This page contains some information on hot swapping hard drives on Linux.

Removing a Drive[edit]

To remove a SATA on a live Linux system:

  1. Ensure the disk is unmounted.
  2. Ensure the disk isn't used by swap or LVM groups.
  3. Power down the disk by running echo 1 > /sys/block/sdX/device/delete.

Once the drive spins down, you can disconnect the power and SATA connector.

Rescanning SATA Bus[edit]

When connecting another drive to the system, depending on the chipset, you may need to force a rescan of the bus before the drive shows up on the system.

Do so by:

# echo "- - -" > /sys/class/scsi_host/host1/scan

The 3 values represents the channel, SCSI target ID, and LUN respectively with dashes being wildcards.

Depending on your system, you may need to scan the proper scsi host for the disk to show.

# ls -al /sys/class/scsi_host
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host0 -> ../../devices/pci0000:00/0000:00:06.0/ata1/host0/scsi_host/host0/
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host1 -> ../../devices/pci0000:00/0000:00:06.0/ata2/host1/scsi_host/host1/
lrwxrwxrwx  1 root root 0 Feb 18 22:21 host2 -> ../../devices/pci0000:00/0000:00:04.0/0000:01:06.0/ata3/host2/scsi_host/host2/