Created
October 11, 2016 15:11
-
-
Save fcharlier/a085afa83a525c9d96ecc40e3e3e1f9a to your computer and use it in GitHub Desktop.
FreeBSD ZFS replace faulted disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Backup the the partitions geometry from another disk, rewrite the labels | |
(naz@celeri)~ % sudo gpart backup /dev/ada0 | sed -e 's/disk10/disk4/' -e 's/swap10/swap4/' > geom | |
# Restore the partitions geometry to the replacement disk | |
(naz@celeri)~ % sudo gpart restore -lF /dev/ada1 < geom | |
# Check | |
(naz@celeri)~ % sudo gpart show /dev/ada1 | |
=> 34 976773101 ada1 GPT (466G) | |
34 128 1 freebsd-boot (64K) | |
162 8388608 2 freebsd-swap (4.0G) | |
8388770 968384365 3 freebsd-zfs (462G) | |
(naz@celeri)~ % sudo gpart backup /dev/ada1 | |
GPT 128 | |
1 freebsd-boot 34 128 | |
2 freebsd-swap 162 8388608 swap4 | |
3 freebsd-zfs 8388770 968384365 disk4 | |
# Enable swap if required | |
(naz@celeri)~ % sudo swapon /dev/gpt/swap4 | |
# Get the name of the device to replace | |
(naz@celeri)~ % sudo zpool status -v zroot | |
pool: zroot | |
state: DEGRADED | |
status: One or more devices could not be opened. Sufficient replicas exist for | |
the pool to continue functioning in a degraded state. | |
action: Attach the missing device and online it using 'zpool online'. | |
see: http://illumos.org/msg/ZFS-8000-2Q | |
scan: scrub repaired 0 in 19h0m with 0 errors on Wed Sep 28 05:05:20 2016 | |
config: | |
NAME STATE READ WRITE CKSUM | |
zroot DEGRADED 0 0 0 | |
raidz1-0 DEGRADED 0 0 0 | |
14326764412051271881 UNAVAIL 0 0 0 was /dev/gpt/disk4 | |
gpt/disk6 ONLINE 0 0 0 | |
gpt/disk8 ONLINE 0 0 0 | |
gpt/disk10 ONLINE 0 0 0 | |
errors: No known data errors | |
# Do the replacement | |
(naz@celeri)~ % sudo zpool replace zroot 14326764412051271881 /dev/gpt/disk4 | |
Make sure to wait until resilver is done before rebooting. | |
If you boot from pool 'zroot', you may need to update | |
boot code on newly attached disk '/dev/gpt/disk4'. | |
Assuming you use GPT partitioning and 'da0' is your new boot disk | |
you may use the following command: | |
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0 | |
# Update the boot code | |
(naz@celeri)~ % sudo gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1 | |
bootcode written to ada1 | |
# Resilvering is in progress !!! | |
(naz@celeri)~ % zpool status -v zroot | |
pool: zroot | |
state: DEGRADED | |
status: One or more devices is currently being resilvered. The pool will | |
continue to function, possibly in a degraded state. | |
action: Wait for the resilver to complete. | |
scan: resilver in progress since Tue Oct 11 14:56:04 2016 | |
28.6M scanned out of 315G at 574K/s, 159h45m to go | |
6.95M resilvered, 0.01% done | |
config: | |
NAME STATE READ WRITE CKSUM | |
zroot DEGRADED 0 0 0 | |
raidz1-0 DEGRADED 0 0 0 | |
replacing-0 UNAVAIL 0 0 0 | |
14326764412051271881 UNAVAIL 0 0 0 was /dev/gpt/disk4/old | |
gpt/disk4 ONLINE 0 0 0 (resilvering) | |
gpt/disk6 ONLINE 0 0 0 | |
gpt/disk8 ONLINE 0 0 0 | |
gpt/disk10 ONLINE 0 0 0 | |
errors: No known data errors | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment