External hard drive keeps powering down
Is it possible to prevent an external hard drive from powering down? I left the drive on over the night for a large download, but when I checked it in the morning, the download failed with the message unable to access the drive.
I am able to read/write to the drive perfectly well, small downloads are fine, but downloads which take more time, seem to fail because of some i/o error.
I have performed a badblocks scan on the drive and no errors were found.
Unable to start a SMART self-test:
Disconnected and then reconnected external USB drive. dmesg results follow:
[ 289.881673] usb 1-1.1: USB disconnect, device number 5
[ 305.182474] usb 1-1.1: new high-speed USB device number 6 using ehci-pci
[ 305.275807] usb 1-1.1: New USB device found, idVendor=152d, idProduct=2338
[ 305.275812] usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=5
[ 305.275825] usb 1-1.1: Product: USB to ATA/ATAPI bridge
[ 305.275828] usb 1-1.1: Manufacturer: JMicron
[ 305.275830] usb 1-1.1: SerialNumber: 000001D91CA8
[ 305.276594] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[ 305.276914] scsi host5: usb-storage 1-1.1:1.0
[ 306.275373] scsi 5:0:0:0: Direct-Access WDC WD25 00KS-00MJB0 PQ: 0 ANSI: 5
[ 306.275787] sd 5:0:0:0: Attached scsi generic sg3 type 0
[ 306.276317] sd 5:0:0:0: [sdc] 488397168 512-byte logical blocks: (250 GB/233 GiB)
[ 306.277429] sd 5:0:0:0: [sdc] Write Protect is off
[ 306.277435] sd 5:0:0:0: [sdc] Mode Sense: 28 00 00 00
[ 306.278429] sd 5:0:0:0: [sdc] No Caching mode page found
[ 306.278433] sd 5:0:0:0: [sdc] Assuming drive cache: write through
[ 306.288959] sdc: sdc1 sdc2
[ 306.292063] sd 5:0:0:0: [sdc] Attached SCSI diskOutput of 'blkid' while the drive is in use. I took that screenshot while copying 500MB worth of files to the drive.
Output of lsblk below:
userone@userone:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 59.2G 0 part └─sda5_crypt 252:0 0 59.2G 0 crypt ├─ubuntu--vg-root 252:1 0 43.2G 0 lvm / └─ubuntu--vg-swap_1 252:2 0 15.9G 0 lvm [SWAP]
sdb 8:16 0 232.9G 0 disk
├─sdb1 8:17 0 500M 0 part
├─sdb2 8:18 0 232G 0 part
└─sdb3 8:19 0 470M 0 part
sdc 8:32 0 232.9G 0 disk
├─sdc1 8:33 0 232.4G 0 part /media/userone/New Volume
└─sdc2 8:34 0 470M 0 part
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 86.6M 1 loop /snap/core/4571
loop1 7:1 0 90.3M 1 loop /snap/coolreader3/1
loop2 7:2 0 86.7M 1 loop /snap/simplescreenrecorder/1
loop3 7:3 0 236.5M 1 loop /snap/pycharm-community/64
loop4 7:4 0 86.9M 1 loop /snap/core/4830
loop5 7:5 0 85M 1 loop /snap/simplescreenrecorder-mardy/4
loop6 7:6 0 86.6M 1 loop /snap/core/4650
userone@userone:~$ 5 4 Answers
Get the device name with blkid or check dmesg for the connected device. Then switch the power management off with hdparm.
# get device name
$ sudo blkid
/dev/sda1: UUID="..." UUID_SUB="..." TYPE="somefs" PARTUUID="..."
/dev/sdb1: UUID="..." UUID_SUB="..." TYPE="someotherfs" PARTUUID="..."
$ sudo dmesg
...
[ 305.276914] scsi host5: usb-storage 1-1.1:1.0
[ 306.275373] scsi 5:0:0:0: Direct-Access WDC WD25 00KS-00MJB0 PQ: 0 ANSI: 5
[ 306.275787] sd 5:0:0:0: Attached scsi generic sg3 type 0
[ 306.276317] sd 5:0:0:0: [sdc] 488397168 512-byte logical blocks: (250 GB/233 GiB)
[ 306.277429] sd 5:0:0:0: [sdc] Write Protect is off
...As you can see from the output the commands, your USB disk is registered as /dev/sdc. So disable power management for this device.
# disable power management
$ sudo hdparm -B 255 /dev/sdcSee hdparm ArchWiki for more details.
Update: Add sudo to commands, since super user privileges are required.
Not only with large downloads, but also with copying large files from HDD to external HDD there is a bug almost five years old: Ubuntu slows down and hangs while copying file from/to USB.
The solutions posted by many users is to check your write back cache:
$ cat /proc/vmstat | egrep "dirty|writeback"
nr_dirty 15
nr_writeback 0
nr_writeback_temp 0
nr_dirty_threshold 261131
nr_dirty_background_threshold 130406The accepted answer (with 66 up-votes) here: stackexchange.com - Why is my pc freezing while I'm copying a file to a pendrive?
suggests using:
echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes
echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytesThe accepted answer is using indirect math to set 16 MiB for dirty background bytes and 48 MiB for dirty bytes.
From the first link (bug report) though, comment #83 recommends a more aggressive value of 200 MB for dirty bytes. To make settings permanent edit /etc/sysctl.conf and add this line:
vm.dirty_bytes = 200000000Then run systctl -p or reboot.
There are many other suggestions in the first link and you might have to try other ones if this common solution doesn't work.
BTW dirty doesn't mean anything nefarious. It means data held in RAM waiting to be written to disk. So while your download is running the information is being held in RAM and not written to your external hard drive. Inactivity could be why it is powering down.
Also as I mentioned in comments blkid reveals nothing in Ubuntu 18.04 but lsblk reveals everything including external drives.
Just a anther idea: If the vendor of the USB device doesn’t support disabling the power management, you can keep it alive with a cronjob.
Create a cronjob for the root user, that creates a file every minute, synchronizes the file system and deletes it afterwards.
# Edit the crontab as root user (it will open the crontab with your favorite editor)
$ sudo crontab -e
# add the following line, save and close the editor
* * * * * touch /media/userone/New\ Volume/keepalive; sync; rm -f /media/userone/New\ Volume/keepaliveThis should keep the USB device up an running
To me the combination of the previous two answers worked. I executed "/sbin/hdparm -B 255 /dev/sdc" in cronjob every minute.
# Edit the crontab as root user (it will open the crontab with your favorite editor)
$ sudo crontab -e
# add the following line, save and close the editor
* * * * * /sbin/hdparm -B 255 /dev/sdc >/dev/null 2>&1