# SATA Hotswap

## jtrooney

Hi I have a quick question, I have asked on the server mailing list but with no results. I have a server with hot swap sata drives, that are non raided, my question is: is it possible to umount a drive remove that drive, pop-in a new one, and remount it? A while back i tried this with software raid and scsi, but ended up finding that udev dropped the device once it was unplugged. Any information would be greatly appreciated. Thanks in advance.

----------

## widan

 *jtrooney wrote:*   

> ... hot swap sata drives ... is it possible to umount a drive remove that drive, pop-in a new one, and remount it?

 

It's not possible yet, as libata (the kernel framework for SATA drivers) doesn't handle drive hotplug for the moment. Trying to do it will usually just confuse the controller and/or the kernel.

 *jtrooney wrote:*   

> A while back i tried this with software raid and scsi, but ended up finding that udev dropped the device once it was unplugged.

 

For SCSI, you need some special commands before removing and after inserting the drive to unregister/register it with the SCSI subsystem.

----------

## Whoopie

Hi,

have a look at http://www.thinkwiki.org/wiki/How_to_hotswap_UltraBay_devices

It's for ThinkPads, but I think you can use this howto for any other SATA system.

Best regards,

Whoopie

----------

## stdPikachu

Woohoo! Thanks for that link!

With those commands:

```
echo 0 0 0 > /sys/class/scsi_host/hostN/scan
```

 (where N is the SATA controller number) I was able to get my 2.6.19 box 9using the new libata) to see a recently-plugged-in hard drive on SATA controller 4:

```
scsi 4:0:0:0: Direct-Access     ATA      WDC WD2500JD-00G 02.0 PQ: 0 ANSI: 5

SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)

sdc: Write Protect is off

sdc: Mode Sense: 00 3a 00 00

SCSI device sdc: drive cache: write back

SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)

sdc: Write Protect is off

sdc: Mode Sense: 00 3a 00 00

SCSI device sdc: drive cache: write back

 sdc: sdc1

sd 4:0:0:0: Attached scsi disk sdc

SCSI device sdc: 488397168 512-byte hdwr sectors (250059 MB)

sdc: Write Protect is off

sdc: Mode Sense: 00 3a 00 00

SCSI device sdc: drive cache: write back

 sdc: sdc1
```

Presumably, automatic/hotplug support for this is coming soon; in the meantime I've just created a script that runs "echo 0 0 0 > /sys/class/scsi_host/host4/scan" every few minutes to get pseudo-hotswap functionality.

Tested on 2.6.19-rc5 with latest udev and libata on an Intel ICH8 southbridge.

Edit: I note that 2.6.19-mm1 has an option in ACPI for HDD docks, so I guess that it'll be reasonably easy for me to create an ACPI event to detect the SATA caddy and auto-scan the relevant controllers.

----------

## planet-admin

Once minor change for me, using fiber channel on a qla2xxx based card:

```

echo - - - > /sys/class/scsi_host/host0/scan

```

echo 0 0 0 did NOT work, (don't know why).

I actually had resized this volume, and needed to hot remove and re-add it, so I :

```

echo 1 > /sys/class/scsi_device/0\:0\:0\:17/device/delete

echo - - - > /sys/class/scsi_host/host0/scan

```

Where on the first line, 0:0:0:17 is my host, channel, lun, etc.

Michael

----------

## hoka

Although already answered, if anybody else finds the need to dig up this post, SATA hotswapping is fairly well supported under libata, though your specific chipset may not support it. The support matrix can be found here: http://linux-ata.org/driver-status.html#matrix

Turning on a disk looks something like this (nvidia chipset, activating 2x 320gb at once on ports 3/4):

```

ata7: exception Emask 0x10 SAct 0x0 SErr 0x150000 action 0x2 frozen

ata7: hard resetting port

ata7: SATA link up 1.5 Gbps (SStatus 113 SControl 300)

ata7.00: ATA-7, max UDMA/133, 625142448 sectors: LBA48 NCQ (depth 0/32)

ata7.00: configured for UDMA/133

ata7: EH complete

  Vendor: ATA       Model: ST3320620AS       Rev: 3.AA

  Type:   Direct-Access                      ANSI SCSI revision: 05

SCSI device sdg: 625142448 512-byte hdwr sectors (320073 MB)

sdg: Write Protect is off

sdg: Mode Sense: 00 3a 00 00

SCSI device sdg: drive cache: write back

SCSI device sdg: 625142448 512-byte hdwr sectors (320073 MB)

sdg: Write Protect is off

sdg: Mode Sense: 00 3a 00 00

SCSI device sdg: drive cache: write back

 sdg: sdg1

sd 6:0:0:0: Attached scsi disk sdg

ata8: exception Emask 0x10 SAct 0x0 SErr 0x50000 action 0x2 frozen

ata8: hard resetting port

ata8: SATA link up 1.5 Gbps (SStatus 113 SControl 300)

ata8.00: ATA-7, max UDMA/133, 625142448 sectors: LBA48 NCQ (depth 0/32)

ata8.00: configured for UDMA/133

ata8: EH complete

  Vendor: ATA       Model: ST3320620AS       Rev: 3.AA

  Type:   Direct-Access                      ANSI SCSI revision: 05

SCSI device sdh: 625142448 512-byte hdwr sectors (320073 MB)

sdh: Write Protect is off

sdh: Mode Sense: 00 3a 00 00

SCSI device sdh: drive cache: write back

SCSI device sdh: 625142448 512-byte hdwr sectors (320073 MB)

sdh: Write Protect is off

sdh: Mode Sense: 00 3a 00 00

SCSI device sdh: drive cache: write back

 sdh: sdh1

sd 7:0:0:0: Attached scsi disk sdh

```

The kernel/udev should automagically handle assigning the new device block and creating the appropriate /dev/ nodes. If you are doing a lot of hot swapping you might want to create a udev ruleset that properly names each port in say /dev/raid/ with a symlink to the device node. This is how it looks on my system:

```

cat /etc/udev/rules.d/10-local.rules

KERNELS=="0:0:0:0", SUBSYSTEMS=="scsi", SYMLINK+="raid/1d%n"

KERNELS=="1:0:0:0", SUBSYSTEMS=="scsi", SYMLINK+="raid/2d%n"

...

ls /dev/raid/ -l

total 0

lrwxrwxrwx 1 root root 6 Dec 24 02:25 1d -> ../sda

lrwxrwxrwx 1 root root 7 Dec 24 02:25 1d1 -> ../sda1

lrwxrwxrwx 1 root root 6 Dec 24 02:25 2d -> ../sdb

lrwxrwxrwx 1 root root 7 Dec 24 02:25 2d1 -> ../sdb1

...

```

For SATA hotswapping I've found you don't really need to do anything special, though I havn't tested turning drives off during writes/reads. I'm using some generic hot swap cages from Newegg (iStarUSA/Athena/buncha other companies rebrand it). udev 103 + gentoo-hardened-2.6.18 with added nvidia hard port reset patch.

----------

## stdPikachu

Just a request for confirmation here; which driver does the Intel ICH8 controller use? I'm presuming ata_piix, which is probably why hotplug doesn't work on my C2D box...? Does anyone know where I should look for upcoming hotplug support? My usual experience is that Intel chipsets are well supported right off the bat, so I'm a bit miffed that hotswap support for the Intel chipsets doesn't seem to be anywhere yet...

Edit: does anyone know if the ICH8 chipset works with the ahci driver? At the moment it looks like hotplug is loading both ata_piix and ahci at boot, so I may have an experiment where I remove ata_piix support from the kernel...

----------

