3

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:

enter image description here


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.

enter image description here


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:~$ 
oshirowanen
  • 3,937
  • 23
  • 76
  • 104
  • 1
    it is my belief some drives & devices have power-save functions that turn the device/drive off to save power after a period of inactivity (allowing more 'stars' to be stuck on the box as a marketing selling point compliant with local laws). these devices are turning themselves off, thus I don't believe can be disabled by Ubuntu. It'll be drive specific, but may be fooled by a script that writes random data to the device every so often (or just `sync` data to drive, if there is data to sync; it can't just re-read same data as it will come from cache & won't stop drive turning itself off). – guiverc Jun 26 '18 at 08:39
  • 1
    Another possibility is that the drive overheated. What are the SMART data (see `smartmontools` package). What is the drive type anyway? (brand/model of enclosure, and model as reported in SMART)(edit your question to answer) – xenoid Jun 26 '18 at 08:48
  • @xenoid, edited question. – oshirowanen Jun 27 '18 at 09:25
  • You don't need s self-test, SMART (if available) will also report logged data (ie, past errors, temperatures reached, etc...). Note that if @SimonSufdler's answer doesn't work it will worth stating in a comment. – xenoid Jun 27 '18 at 11:27
  • 1
    Is the external drive powered via the USB port, or does it have a separate power supply? Can you power it externally if not currently done so? If no external power capability, did you try a Y USB connector (so two ports may supply power)? SMART doesn't work over USB, can use use eSATA on the external drive? – ubfan1 Jun 30 '18 at 15:17

4 Answers4

5

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.

Simon Sudler
  • 3,771
  • 3
  • 20
  • 33
3

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.

WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401
  • I'm not sure this is the issue, my computer does not slow down or freeze at all. The drive itself becomes unacceptable, which it reaches a certain part of the download. – oshirowanen Jul 01 '18 at 19:25
  • I can't guarantee it's the same issue, but both cases are about extremely large files. In your case the large file comes from the Internet and goes to the external USB. In the other case the large file comes from a local disk and goes to the external USB. In both cases RAM is used for buffering the writes and when the buffers grow too large the copying slows down/stalls. You won't know if the answer works unless you try it though... – WinEunuuchs2Unix Jul 01 '18 at 19:42
  • Fair point, giving it a try now. – oshirowanen Jul 01 '18 at 20:05
  • X (fingers crossed) – WinEunuuchs2Unix Jul 01 '18 at 20:50
0

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/keepalive

This should keep the USB device up an running

Simon Sudler
  • 3,771
  • 3
  • 20
  • 33
0

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
pintergabor
  • 101
  • 2