# [ZFS] Hotswapping sata drives



## wasd (Feb 24, 2011)

I have 2 SATA drives.

ad8s1 - UFS2, / (15 gb)
ad8s2 - first part of ZFS pool (~280 gb)

ad11s1 - second part of zfs pool (400 gb)

I want to swap ad11s1 with another hard drive (1 tb) without rebooting and data loss. Operation should be transparent (without closing descriptors, if possible. Maybe, transfer data from ad11s1, detach it from pool, detach from physical port? My motherboard Asus P5B Deluxe. Is that possible?

P. S. sorry my English.


----------



## wasd (Feb 24, 2011)

P. P. S.: yes, another hard drive will be in ZFS too and will be attached to pool


----------



## jem (Feb 24, 2011)

Hot-swapping SATA disks is only possible with AHCI compliant controllers, otherwise you must power-down and cold-swap.  Most of the modern onboard Intel SATA controllers are AHCI compatible, although it needs to be supported in the BIOS of the machine.  Some SIS controllers also support it.

To see if your controller supports it, reboot FreeBSD and at the 'beastie' menu, press 6 to escape to a loader prompt and type the following:


```
Type '?' for a list of commands, 'help' for more detailed help.
OK load ahci
/boot/kernel/ahci.ko size 0xfd88 at 0x126b000
OK load siis
/boot/kernel/siis.ko size 0xNNNN at 0xNNNNNNN
OK boot
```

If your disks show up as adaX devices during boot (instead of adX), then your controller is compliant.

You'll need to reboot again without AHCI and edit your fstab to use the new device names, then you can add the following to /boot/loader.conf to make the AHCI module load on every boot:


```
ahci_load="YES"
```


----------



## wasd (Feb 24, 2011)

jem said:
			
		

> If your disks show up as adaX devices during boot (instead of adX), then your controller is compliant.
> 
> ```
> ahci_load="YES"
> ```



Hm. When I use Linux, I can hotadd/hotremove harddisks, it's ok. But now I loaded ahci at boot, and:


```
iwhag% ls /dev/ad*
/dev/ad7	/dev/ad7s1	/dev/ad7s2	/dev/ad8s1
```

now ad7s1 is my rootfs, strange. What happens?


----------



## wasd (Feb 24, 2011)

```
iwhag% sudo lspci | grep -i sata
00:1f.2 IDE interface: Intel Corporation 82801H (ICH8 Family) 4 port SATA IDE Controller (rev 02)
00:1f.5 IDE interface: Intel Corporation 82801H (ICH8 Family) 2 port SATA IDE Controller (rev 02)
```


My controller is SATA JMicron JMB363


----------



## jem (Feb 24, 2011)

The Asus P5B Deluxe has two SATA controllers on board:


Intel ICH8R with six SATA ports (these are the four red and two black ports near the corner of the board, labelled SATA1-6)
JMicron PATA+SATA controller with 1 internal SATA port, 1 eSATA port and 1 PATA port (the internal SATA port is near the first PCIe x16 slot, labelled SATA_RAID)

Your Intel controller is in legacy IDE mode, which is why it shows up as a 4 port SATA IDE controller PLUS a 2 port SATA IDE controller.

In the BIOS setup, you can configure the Intel controller to operate in AHCI mode instead.  You'll need to refer to your motherboard manual for how to do that.

Once you've done that, you can boot FreeBSD with AHCI driver loaded and see what your disks now show up as.

AHCI mode is a much better mode to operate SATA controllers in, if it is available.  It enables things like Native Command Queueing, which might help speed up your disks, as well as making hotswapping possible.


This is going off on a tangent though, all you wanted to do was transfer data from one disk to another.  I would install the new 1GB disk and create a new zpool on it, then I would use 'zfs send | zfs receive' to transfer the ZFS filesystems onto the new disk.


----------



## Terry_Kennedy (Feb 25, 2011)

jem said:
			
		

> Hot-swapping SATA disks is only possible with AHCI compliant controllers, otherwise you must power-down and cold-swap.


Just to clarify - this is for drives on controllers that appear as ad or ada devices. If you are using a hardware RAID controller, whether or not drives are hot-swappable will depend on both the specific controller hardware and whether the matching FreeBSD driver supports hot-swap. As an example, drives on the 3Ware 9650 controller (twa driver) are hot-swappable.


----------



## jem (Feb 25, 2011)

Good point.

Both the controllers on the OP's motherboard are soft-raid capable.  No idea whether they handle hot-swapping or not.


----------



## phoenix (Feb 25, 2011)

From the sounds of it, you have a non-redundant ZFS pool.  Because it is non-redundant (ie, not a mirror, or a raidz), you cannot hot-swap your drives.


----------



## beadon (Apr 1, 2011)

I broke my ZFS array when I tried to do a hot-swap ages ago (pulled a wrong drive, broken drive remained, confused the 2 and hooked them up wrong, etc.. ).  Also, I may not have had the AHCI compliant option..

It's fun to do, but if you can spare the downtime I think it's worth avoiding the risk.


----------

