Linux : SATA hot plug / unplug
stephane
I have 3 hard disks in SATA-to-eSATA external enclosure which I occasionally need to plug to perform backups and to unplug when done. I found it annoying to have to restart the whole computer at every turn, especially when SATA is supposed to bring hotplug abilities. If you mainboard / SATA chipset and disks support hot plugging and unplugging, you can do this by following those instructions.
Hot plug : Scanning for newly added disks
When you plug the disks, you need to tell the OS to scan for new SATA devices, you do this with the following command :
roadrunner / # echo "- - -" > /sys/class/scsi_host/host0/scan
Here “host0” is the SATA channel you want to scan, so you obviously need to replace that by the appropriate channel number. Linux will then hopefully discover the newly attached disk.
Hot unplug : safely removing a disk
First thing, you need to unmount all the mounted filesystems which are residing on the disk you wish to disconnect.
Once this is done, you need to instruct Linux to flush all data still in memory to the disk and then to disconnect it. You do this by issuing the following command :
roadrunner / # echo 1 > /sys/block/sda/device/delete
At this point you’ll usually hear the “click” of the drive spinning down, and you can power off and disconnect it.