I finally got so fed up of my Samba shares not being accessible after a while that I did some digging around. One of my 3 external USB drives attached to my file server keeps going to sleep, which sounds like a good thing. What happens, however, is when I attempt to access the shares from my Windows machine, I get a “Not Accessible” error and I can no longer use any of my Samba shares.
My file server is running Ubuntu 9.04 and all the drives are mounted under /media, then each important directory from each drive is symlinked to a sub directory of /media/shared, and /media/shared is the Samba share. This is convenient because it allows my file server, which has 5 various sized disks and attachments, to appear as one huge drive on the network. I’m not sure if this is why the one sleepy drive is bringing down the whole share or not.
To resolve the issue, I keep having to SSH into my file server, run a command such as fdisk -l to access the drive(s) and then restart Samba. There is a noticeable delay when fdisk -l hits that one sleepy drive while it spins up. My super simple hack to prevent this drive from spinning down, even though I’d rather let it sleep and wake on its own, is this:
$ sudo crontab -e
Then I added the following line to the cron tab file:
5 * * * * fdisk -l >/dev/null 2>&1
This will issue the fdisk -l command every 5 minutes, dumping the fdisk output to neverland. The idea is to access the drive every once in a while to prevent it from going to sleep. I expect to do some tweaking on the 5 minutes part, in an attempt to run the job less frequently, but still enough to keep the drive awake.
It’s an ugly hack and I’m sure there’s something I could do with hdparm if I spent some more time on it, but whatever. It’s only me accessing the file server and the performance is not very critical.
If you do know of slicker way of doing this, drop a comment and let me know.
