6

I have an external hard disk drive, formatted with ext4 and connected to my Pi 3B+ running Raspbian with Kernel 4.19.97-v7+. Every now and then, usually after about 12 hours, but sometimes a few days the hard disk drive is no longer mounted and no longer visible.

I have mounted it in the past by running sudo fdisk -l to find the device and then running sudo mount /dev/sda1 /mnt/external. The problem was that every now and then, the hard drive would not be at /dev/sda1 but would have moved to /dev/sdb1, then /dev/sdc1 and so on. To get around this, I got the UUID of the drive by running sudo blkid and then added it to /etc/fstab by adding the following line:

UUID=3eb6e277-0b3e-40d6-988a-d4200977f79f /mnt/external ext4 defaults 0 0

Now, this does mount the drive at startup but every now and then it is no longer mounted. If I go to /mnt/external there are no files. If I run sudo fdisk -l, it is not listed. The only way I could find around this was to reboot.

Something that I have tried is adding the following jobs to my crontab. The intention here was to write on the hour and then delete at half past the hour. I thought that perhaps the hard drive was entering some power saving state. The files are being added and removed, right up until the disk disappears.

30 * * * * rm /mnt/external/keep-hdd-alive
0 */1 * * * touch /mnt/external/keep-hdd-alive

Does anyone know how I can make my hard drive stay mounted and available?

3
  • 1
    Try: "dmesg | tail" and see if there are any hints there. Also look at /var/log/syslog at around the times this is happening and see if anything is there.
    – jwh20
    Apr 27, 2020 at 14:35
  • Check the power supply of the external hard disk.
    – Ingo
    Apr 27, 2020 at 17:20
  • I have just learned that the USB host adapter firmware is also upgradeable on the Pi 4. Can you check which version you have by running sudo vl805? May 3, 2020 at 20:54

6 Answers 6

4

External drives are often problematic on the Pi. The root cause is probably power issues, although I have found that occasionally the drive would be in Read Only mode.

It is, of course, better to fix the underlying problem, but I routinely include a test in my scripts to check that the drive is mounted, at the correct spot (below in /mnt/PiData), in Read/Write mode.

#!/bin/bash
BACKUP_MOUNTED=$(mount | awk '/PiData/ {print $6}' | grep "rw")
if [ $BACKUP_MOUNTED ]; then
    echo $BACKUP_MOUNTED
…
else
    echo "Backup drive not available or not writable"
fi
1
  • I've tried a few things to fix the issue, but I think the best one was changing the power supply. It might just not having been supplying enough power. It's taken a while for me to respond because I wanted to test it for long enough to be sure.
    – Arthur
    May 31, 2020 at 17:09
3

If the drive does not have a separate power supply, check sudo grep "Under-voltage" /var/log/syslog for clues that this is an issue.

You could try fiddling with the drive parameters using hdparm (pretty sure that's the name of the package if it isn't installed).

From man hdparm:

-B

Get/set Advanced Power Management feature, if the drive supports it. A low value means aggressive power management and a high value means better per‐ formance. Possible settings range from values 1 through 127 (which permit spin-down), and values 128 through 254 (which do not permit spin-down). The highest degree of power management is attained with a setting of 1, and the highest I/O performance with a setting of 254. A value of 255 tells hdparm to disable Advanced Power Management altogether on the drive (not all drives support disabling it, but most do).

I use hdparm -B 127 /dev/sda and then hdparm -S ... to set a USB HDD to spin down when idle to save power. It does not unmount in that state, but when data is actually accessed it takes a second or so to power up again.

It could be that using hdparm -B 255 might keep it online, albeit by disabling any APM.

2
  • Thank you! I'll try that, as I do suspect that there might be some sort of power management issue causing this.
    – Arthur
    Apr 28, 2020 at 8:30
  • I should add that the drive does have a separate power supply.
    – Arthur
    Apr 28, 2020 at 8:42
1

The question seems to say it is UNMOUNTED. Power supply problems would only result in the mount being broken and inaccessible. The mount command would show it mounted, but attempts to access it would fail.

I suspect you may have something attempting to unmount unused drives. I suggest keeping the mount active. This means keeping a file or directory in use. One easy way to do this is to cd a shell into the mount and leaving it. Or you could do something like ( cd /mnt/external ; sleep 999999999 & )

Another interesting alternative is to use automount to mount the drive instead of manually mounting it. This will cause it to remount any time it is referenced, and unmount when it isn't in use for a while.

One thing you didn't mention in the question: if the external drive is bus powered or independently powered. (The other answers have assumed bus powered.)

Having said all that... changing drive letters may well be an indication of power or connectivity problems. (It could be the USB cable being loose or flaky, or an intermediate hub having issues.)

As for the issue of needing to reboot... There is a umount(2) option that can unmount a broken partition. The umount(8) option to do it doesn't work.

1

Power saving can't result in the HDD getting unmounted. Unless you changed the IO settings, block device timeout (/sys/block/sda/device/timeout) is set to 30 seconds, which is plenty for any reasonably recent drive to wake up.

While it's not impossible that a bug in the Linux driver or even in the HDD controller results in a disconnect, this is actually very rare. On USB-powered drives it's most likely that your HDD is not getting enough power when by coincidence all system components are stressed at once. This appears not to be your case.

While it's a long shot, try changing your USB host adapter firmware as described here: if you have an old version, you should definitely upgrade, but if you have a new version and you suspect the issue could have started after the upgrade, a downgrade could also be useful.

Trying a different HDD and a different USB to SATA converter could also help. I have an external Toschiba HDD with a built-in converter, and it never got dismounted without an obvious reason like undervoltage.

1
  • The HDD has it's own power supply, but it is possible that this power supply is faulty.
    – Arthur
    May 3, 2020 at 10:08
1

Many external drives need more power than the Pi can give. Unfortunately, quite a few powered hubs cause problems and stop the Pi rebooting cleanly. An alternative I have used is to get a USB cable that has an extra plug for power. I got this one from Amazon.

USB Cable with extra power plug

It probably won’t be useful to plug the extra lead into the Pi as it has limited power to the USB hubs. I use a 5V phone charger type plug and connect the extra lead to that. It seems to work OK even through a reboot.

0

I dont know why, but when I use the raspberry pi4, icm with external powered USB HDD, the whole drive got corrupted, including the filesystem. I had to format (quick format) and do multiple disk check under Ubuntu desktop to repair the HDD. This was using ext4 mount. The same happend when I format the drive as NTFS and mount using ntfs-3g. All the rest is the same with what OP said.

I think the USB is somehow flacky, because I have no issues with the drive on my laptop, where as the exact same problems happen when I connect the drive to a cheap Chinese motherboard I once bought.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.