ZFS replace a mirrored disk

From: Christos Chatzaras <chris_at_cretaforce.gr>
Date: Wed, 11 May 2022 10:22:36 UTC
When a disk fails and want to replace it with a NEW disk are these commands correct?

----
gpart backup nvd1 | gpart restore -F nvd0
gmirror forget swap
gmirror insert swap /dev/nvd0p2
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 nvd0
zpool replace zroot nvd0
----


I try to simulate a disk "failure". I tried the above commands with the SAME disk without success. I believe the "issue" is because the "new" disk is the SAME as before.

I did these steps:

1) Boot with mfsBSD and did "gpart destroy -F nvd0"
2) Reboot the server in the main OS.

If the "new" disk is the SAME as before do I have to change the commands to these?

----
gpart backup nvd1 | gpart restore -F nvd0
gmirror forget swap
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 nvd0
zpool offline zroot nvd0
zpool online zroot nvd0
----


Also I notice that with the SAME disk "gmirror forget swap" starts rebuilding swap immediately and "gmirror insert swap /dev/nvd0p2" is not needed. Is this the correct behaviour when the "new" disk is the SAME?