Friday, 15 January 2021

Replacing a ZFS pool device in FreeBSD 12.2

# Check drive to replace
smartctl -A -i /dev/ada2

# Shortcut to show hours only
smartctl -A -i /dev/ada2 | grep Power_On_Hours

# ada2 very old 61661 hours Device Model:     WDC WD10EAVS-00D7B0 
# ada3 old 34813 hours Device Model:     TOSHIBA DT01ACA100

# Power off and swap drives - HP Microserver Gen8 is not hotplug
poweroff

# Check replaced drives have same dev numbers before we obliterate them
smartctl -i /dev/ada2

# Create partition layout on replaced drives and copy bootcode
gpart destroy -F ada2
gpart create -s gpt ada2
gpart add -s 512k -t freebsd-boot -l gptboot2 ada2
gpart add -a 1m -s 2G -t freebsd-swap -l swap2 ada2
gpart add -a 1m -t freebsd-zfs -l zfs2 ada2

# Identify a removed drive
zpool status | grep UNAVAIL

# Replace drive in pool - mine is called zroot
zpool replace zroot 15833367089499325236 /dev/gpt/zfs2

# Install bootcode
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 /dev/ada2