Two Hard Disk Server Zfs replace script

yena

Renowned Member
Nov 18, 2011
385
6
83
Hello,
i have find very "dangerous" the HD replace procedure in a Simple two hd server installed with Zraid1.
I have this command lines, but it's dangerousse if HD change name after a reboot or in case of human error..

sgdisk -R /dev/sdnew /dev/sdGood
sgdisk -G /dev/sdnew
zpool replace pool sdGood sdNew2
grub-install /dev/sdNew
update-grub
update-initramfs -u

Have someone write a little script to do this work ?

Thanks!
 
look at /dev/disk/by-id/

# ls /dev/disk/by-id/ -la
total 0
drwxr-xr-x 2 root root 800 Nov 12 15:33 .
drwxr-xr-x 8 root root 160 Nov 12 15:33 ..
lrwxrwxrwx 1 root root 9 Nov 12 15:33 ata-HGST_HDN724040ALE640_PK1334PCJY7Y8S -> ../../sdf
lrwxrwxrwx 1 root root 10 Nov 12 15:33 ata-HGST_HDN724040ALE640_PK1334PCJY7Y8S-part1 -> ../../sdf1
lrwxrwxrwx 1 root root 10 Nov 12 15:33 ata-HGST_HDN724040ALE640_PK1334PCJY7Y8S-part9 -> ../../sdf9
lrwxrwxrwx 1 root root 9 Nov 12 15:33 ata-HGST_HDN724040ALE640_PK1334PCJY7ZGS -> ../../sde
lrwxrwxrwx 1 root root 10 Nov 12 15:33 ata-HGST_HDN724040ALE640_PK1334PCJY7ZGS-part1 -> ../../sde1
lrwxrwxrwx 1 root root 10 Nov 12 15:33 ata-HGST_HDN724040ALE640_PK1334PCJY7ZGS-part9 -> ../../sde9
....
 
look at /dev/disk/by-id/

Thanks, with disk by id is more secure and i can do:
zpool detach rpool sdBroken2
and
zpool add -f rpool /dev/disk/by-id/ata-SanDisk_SDSSDRC032G_134107400014-part2

but the new disk can't boot:
error: no such device: 36264e277a59...
Entering rescue mode...
grub rescue>

I have tryed both:

grub-install --recheck /dev/sdNew
update-grub
update-initramfs -u

and
dd if=/dev/sdb of=/dev/sdNew bs=512 count=10240

dd if=/dev/sdb1 of=/dev/sdNew1 bs=512
dd if=/dev/sdb9 of=/dev/sdNew9 bs=512

( same grub error on both hd .. )
after some testing i found the problem:
zpool detach rpool sdBroken2
and
zpool add -f rpool /dev/disk/by-id/ata-SanDisk_SDSSDRC032G_134107400014-part2

with zpool add i have a stripe Zraid0 non Zraid1 !!

Thanks!
 
Last edited: