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 disk
Output 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:~$
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/sdc
See 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 130406
The 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_bytes
The 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 = 200000000
Then 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.