How to hot-swap SATA drives in Linux

Q I have several 500GB SATA hard drives with all my movies on them. Instead of putting them on a server and running them across the wire, I have chosen to have a removable tray in my media computer. The only problem is that I must shut down the computer to change hard drives. I want to be able to hot-swap disks, but I'm not aware of a way to do that under Linux, as the drive tables are loaded when the kernel is brought up.

A What you are looking for is hotplugging on SATA, which is dependent on the hardware in two areas. The drive caddy system you use must be hot-swappable; most are, but check before you buy. The lock is often necessary, although some caddies use a sliding catch rather than a key, because it not only locks the drive in place but also controls the power to the drive. Unlocking the drive powers down the drive so it is not still spinning when you physically yank it out. Secondly, your SATA controller must handle hot-swapping. It must be able to recognise when a drive has been disconnected or connected and communicate this information. Provided that happens, the OS should handle hot-swapped SATA drives much the same as it does USB or FireWire drives. Identifying suitable controllers is not so easy. I've had complete success with Intel ICH8 controllers running in AHCI mode, which seems to be the most important factor. If your SATA controllers are AHCI compatible (there is often a BIOS option to enable or disable this if they are), you should be OK, but search Google for your particular controller(s) first. Watch the system log with

tail -f /var/log/messages

while pulling and replacing the drives. You should see various messages relating to the disappearance and reappearance of the drive. If this ends in success you are ready to use them, although there is one more factor you may need to consider. If you want the drives to be automounted and your automount system uses pmount to do the mounting (pmount allows mounting by a normal user without an entry in /etc/fstab) you may need to edit /etc/pmount.allow. If the drives are seen as non-removable, which SATA hard disks usually are, pmount will refuse to mount them unless you add the device name to /etc/pmount.allow, for example.

echo '/dev/sdb1' >>/etc/pmount.allow
echo '/dev/sdc[123]' >>/etc/pmount.allow
echo '/dev/sdd*' >>/etc/pmount.allow

The first allows one particular partition to be mounted by pmount, the second example permits three specific partitions on a drive, while the third lets through every partition on a drive. Note the use of single quotes to stop the shell interpreting the wildcards.

Follow us on or Twitter

Username:   Password: