Why won't my USB hard drive stay mounted without constant disk access?
April 18, 2006 2:55 PM   Subscribe

My USB2 hard drive will only stay mounted if I keep accessing it. If I don't, within 5 hours or fewer, I can't access files on the drive or even do a directory listing. I can then unmount the HD, power cycle it, and it will mount again as if nothing had happened. If I keep accessing the disk, say by continuously playing an MP3 mix on it, the disk acts completely normal: uptime now (with MP3s playing) is something like 20 hours without the shadow of a problem.

The PC connected to the HD is a Linux box (Great Quality computer from Fry's; only previous hardware problem was crib death of the internal, non-USB hard disk). Software is Knoppix 4.0 plus infrequent upgrades.

I used to have an Iomega 250GB USB hard disk (ext3 file system) on one of the USB 2.0 ports on the PC. That disk recently crashed. I bought a new 250GB drive from Western Digital, ran disk recovery software on the old drive, and copied the files over to the new disk (FAT32 this time). Norton shows no problems with the partition table or file system on the new hard disk.

FWIW, I can mount my iRiver on USB and copy files back and forth with no problem, but I never keep it mounted long enough to have noticed whether the same thing happens. Also, the new hard drive seems normal when connected for short periods to other computers, but as of this writing, we don't really have another PC we can test the new hard drive on for a long period (that may change soon).

Please work that AskMeFi magic for me, people. Has anyone heard of this weirdness before?
posted by rwhe to Computers & Internet (12 answers total)
I've heard of it, although I haven't bothered to fix it. It has happened to me in Linux and Windows. I have an external laptop drive in an enclosure that I use as a temp drive, and I can't leave it hooked up for more than a day or so. I've also had intermittent problems with a large IDE drive in an enclosure that would randomly no longer exist.

Oddly, I've never lost connection to my external DVD burner.

All of these (2 laptop drive enclosures, 1 external IDE drive, 1 DVD burner) are USB 2, connected to a Thinkpad T42p.
posted by bh at 3:02 PM on April 18, 2006

I've heard the problem goes away if you switch the drive from FAT32 to NTFS...of course that's not going to help your situation much.
posted by furtive at 3:24 PM on April 18, 2006

Best answer: Sounds like the drive is going to sleep and for whatever reason isn't waking up automatically.

There may well be a fix for it out there, but there's probably a simple workaround -- just add a cron job to access the drive periodically.

run 'crontab -e', and add a line like:
0 */2 * * *   touch /mountpoint/.dummyfile
This would cause the dummyfile's timestamp to be updated every two hours, hence keeping the drive alive.
posted by SpookyFish at 3:54 PM on April 18, 2006

The SpinDownUSBHarddisks FAQ will also help you figure out how NOT to spik down USB Hard Disks.

Specifically, look into the hdparm utility. This allows you to set the time until a disk goes to sleep. I believe that the setting is stored on a chip on the hard drive itself so it won't matter which computer you plug it into.

It sounds like it could also be a power management problem, but I'm unfamiliar with power management settings in Linux.
posted by lockle at 4:09 PM on April 18, 2006

Response by poster: The hdparm possibility is extremely attractive, but I may have to resort to the cron workaround. Theoretically, "hdparm -S 0 /dev/foo" will prevent the drive from spinning down, but check this out:

# hdparm -S 0 /dev/uba

setting standby to 0 (off)
HDIO_DRIVE_CMD(setidle1) failed: Inappropriate ioctl for device

Lousy "commodity" hardware... Any other ideas?
posted by rwhe at 4:48 PM on April 18, 2006

Aha, I think /dev/uba may point to the problem. This means that CONFIG_BLK_DEV_UB is enabled in the configuration file for your kernel, either as a module or built in.

Typically external USB drives show up as scsi, i.e. /dev/sda, and work through the 'usb-storage' driver. The UB driver can cause problems with usb-storage and scsi commands, potentially preventing your drive from automatically waking up.

I don't use Knoppix so I can't tell you the specifics. If it is compiled as a module, you will see it with 'lsmod'. If so, you can try unmounting your drive, then modprobe -r ub ; modprobe usb-storage. If it works, it should now show up as /dev/sda instead.

Otherwise, you may need to change the config and recompile your kernel.

Here is a related thread.
posted by SpookyFish at 6:07 PM on April 18, 2006

Response by poster: SpookyFish, thanks. usb_storage is a module on my system, but "modprobe -r ub ; modprobe usb-storage" didn't help. I couldn't get Linux to see the drive as /dev/sd*, so I unplugged and replugged it. It came back as /dev/uba1. Sigh. I really don't want to recompile the modules, etc. so I'm holding my breath to see how the cron job works.
posted by rwhe at 6:25 PM on April 18, 2006

Response by poster: lockle, I RTFMed (Read the FAQ, Man). The first two paragraphs of the USB spindown FAQ read:

For various technical reasons it is not generally possible to adjust the standby timer of an IDE disk connected through a USB adapter (including turnkey external USB drives). See the sdparm page and the section below on sdparm for the technical reasons.

So one method available is to temporarily connect the drive via its IDE connector directly to a big Linux box and run hdparm to set the timer (the -S option is what you're looking for...).

I really don't want to crack open the case of my brand new hard drive, find an IDE connector, open my PC, etc., so I'm letting the hard drive lie fallow for a few hours while SpookyFish's KISS cron job touches it once an hour.
posted by rwhe at 6:32 PM on April 18, 2006

Response by poster: OK, an hourly cron job touching a file on the hard drive isn't enough to prevent losing the connection, nor are cron jobs that run on the quarter-hour. The timestamp on my dummy file shows it was last touched about 13 minutes after I last used the disk, so either the disk spun down before another 15 minutes had elapsed, or just touching a zero-byte file isn't doing the trick.

I am going to try some other workarounds. I really don't want to start messing with hooking up the HD as an IDE drive, but I will if no other reasonable solution presents itself.
posted by rwhe at 1:53 AM on April 19, 2006

Response by poster: I don't know if anyone is still reading this or finding it interesting (probably not at 3:15 in the morning), but I discovered that many or most Western Digital external hard drives spin down after 10 minutes of inactivity, and this "feature" cannot be disabled (Answer ID 1376).

So I guess I have two questions: (1) How much activity does my drive need to stay connected? (2) What do other Linux users do when their HDs spin down? The FAQ lockle cited makes spindown sound positively desirable.

I have a partial answer for question #1: a lot. Touching a zero-byte file doesn't seem to do it, nor does a cron job that sends a directory listing of the mount point to /dev/null once a minute. It's kind of a digital Winchester Mystery House here as I continuously run XMMS while trying to find a lesser degree of activity that will still keep the disk mounted. My wife: "The sound of The Mix must never stop."
posted by rwhe at 3:28 AM on April 19, 2006

Best answer: OK, here's what seems to be working. At my brilliant wife's suggestion, I made a small text file called .stayalive (98 bytes) in the root directory of the HD. I then made a cron job that runs once a minute and touches, then copies this file to a new file called .stayinalive. That's it! Specifically, here's the line from /etc/crontab:

* * * * * root touch /mnt/media/.stayalive; cp /mnt/media/.stayalive /mnt/media/.stayinalive

The HD is functional, and until I just looked at some photos on it to verify this, there had been no disk activity other than the cron job for almost half an hour, so it seems the 10-minute barrier has been broken.

If the disk doesn't work in the morning, I'll come whine then, but until and unless that happens, thanks all!
posted by rwhe at 4:16 AM on April 19, 2006 [1 favorite]

Response by poster: Seven hours later, and the HD is still mounted. Huzzah! Thanks again.
posted by rwhe at 11:25 AM on April 19, 2006

« Older Take it off! It burns us, it does!   |   Good machine shop with lasers in LA? Newer »
This thread is closed to new comments.