Perhaps the details shown below will help people to understand my temptation to simply gpart recover mirror/gm0
in a startup script. (And optionally gpart recover mirror/gm1
, when a second mirror's present, in the same script.)
My test scenario: ada0 and ada1 are mirrored into gm0. Its sole purpose is to provide a FreeBSD 13v1 test-bed to investigate two, previously unknown to this thread, HDDs on ada2 and ada3. gm0 is cloned to gm1 then the host is rebooted with gm1 used as root. But first, as expected, gmirror logs gm0 corruption when the test-bed host boots:
# dmesg | grep GEOM
GEOM_MIRROR: Device mirror/gm0 launched (2/2).
GEOM: mirror/gm0: the secondary GPT table is corrupt or invalid.
GEOM: mirror/gm0: using the primary only -- recovery suggested.
# gpart show ada2
=> 63 976773105 ada2 MBR (466G)
63 80262 1 !222 (39M)
80325 1595 - free - (798K)
81920 1540096 2 ntfs [active] (752M)
1622016 974038875 3 ntfs (464G)
975660891 165 - free - (83K)
975661056 1101824 4 !39 (538M)
976762880 10288 - free - (5.0M)
# gpart show ada3
=> 34 976773101 ada3 GPT (466G)
34 2014 - free - (1.0M)
2048 1331200 1 efi (650M)
1333248 262144 2 ms-reserved (128M)
1595392 973123584 3 ms-basic-data (464G)
974718976 2027520 4 ms-recovery (990M)
976746496 26639 - free - (13M)
# gpart destroy -F ada2
ada2 destroyed
# gpart destroy -F ada3
ada3 destroyed
# gmirror label -v gm1 /dev/ada2 /dev/ada3
# gpart create -s gpt /dev/mirror/gm1
mirror/gm1 created
# gpart add -t efi -a4k -s 200M /dev/mirror/gm1
mirror/gm1p1 added
# gpart add -t freebsd-ufs -s 454G /dev/mirror/gm1
mirror/gm1p2 added
# gpart add -t freebsd-swap -s 8G /dev/mirror/gm1
mirror/gm1p3 added
# newfs_msdos -F 32 -c 1 /dev/mirror/gm1p1
/dev/mirror/gm1p1: 403266 sectors in 403266 FAT32 clusters (512 bytes/cluster)
BytesPerSec=512 SecPerClust=1 ResSectors=32 FATs=2 Media=0xf0 SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=409600 FATsecs=3151 RootCluster=2 FSInfo=1 Backup=2
# mount -t msdosfs /dev/mirror/gm1p1 /mnt
# mkdir -p /mnt/EFI/BOOT
# cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
# umount /mnt
# newfs -U /dev/mirror/gm1p2 > /dev/null
# mount /dev/mirror/gm1p2 /mnt
# dump -C16 -b64 -0a -f - / | (cd /mnt && restore -rf -)
DUMP: WARNING: should use -L when dumping live read-write filesystems!
DUMP: Date of this level 0 dump: Fri Oct 7 20:32:54 2022
DUMP: Date of last level 0 dump: the epoch
DUMP: Dumping /dev/mirror/gm0p2 (/) to standard output
DUMP: mapping (Pass I) [regular files]
DUMP: Cache 16 MB, blocksize = 65536
DUMP: mapping (Pass II) [directories]
DUMP: estimated 2766714 tape blocks.
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
warning: ./.snap: File exists
DUMP: DUMP: 2760830 tape blocks
DUMP: finished in 259 seconds, throughput 10659 KBytes/sec
DUMP: DUMP IS DONE
# echo "/dev/mirror/gm1p1 /boot/efi msdosfs rw 2 2" > /mnt/etc/fstab
# echo "/dev/mirror/gm1p2 / ufs rw 1 1" >> /mnt/etc/fstab
# echo "/dev/mirror/gm1p3 none swap sw 0 0" >> /mnt/etc/fstab
# gpart show ada2
gpart: No such geom: ada2.
# gpart show mirror/gm1
=> 40 976773088 mirror/gm1 GPT (466G)
40 409600 1 efi (200M)
409640 952107008 2 freebsd-ufs (454G)
952516648 16777216 3 freebsd-swap (8.0G)
969293864 7479264 - free - (3.6G)
# diskinfo ada2
ada2 512 500107862016 976773168 4096 0 969021 16 63
# diskinfo ada3
ada3 512 500107862016 976773168 4096 0 969021 16 63
# diskinfo mirror/gm1
mirror/gm1 512 500107861504 976773167 4096 0
# gpart recover mirror/gm0
mirror/gm0 recovered
# reboot
login: root
Password:
Last login: Fri Oct 7 20:00:38 on ttyu0
FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC
# dmesg | grep GEOM
GEOM_MIRROR: Device mirror/gm0 launched (2/2).
GEOM_MIRROR: Device mirror/gm1 launched (2/2).
GEOM: mirror/gm0: the secondary GPT table is corrupt or invalid.
GEOM: mirror/gm0: using the primary only -- recovery suggested.
GEOM: mirror/gm1: the secondary GPT table is corrupt or invalid.
GEOM: mirror/gm1: using the primary only -- recovery suggested.
# gpart recover mirror/gm0
mirror/gm0 recovered
# gpart recover mirror/gm1
mirror/gm1 recovered
# efibootmgr
Boot to FW : false
BootCurrent: 0008
Timeout : 0 seconds
BootOrder : 0001, 0002, 0008, 0009, 000A, 000B, 0005, 0006, 0007
Boot0001* DTO UEFI USB Floppy/CD
Boot0002 DTO UEFI USB Hard Drive
+Boot0008* TOSHIBA MQ01ACF050
Boot0009* TOSHIBA MQ01ACF050
Boot000A* WDC WD5000BPKT-75PK4T0
Boot000B* WDC WD5000LPLX-75ZNTT0
Boot0005* DTO Legacy USB Floppy/CD
Boot0006* Hard Drive
Boot0007* IBA GE Slot 00C8 v1381
# efibootmgr -n -b 000A
Boot to FW : false
BootNext : 000a
BootCurrent: 0008
Timeout : 0 seconds
BootOrder : 0001, 0002, 0008, 0009, 000A, 000B, 0005, 0006, 0007
Boot0001* DTO UEFI USB Floppy/CD
Boot0002 DTO UEFI USB Hard Drive
+Boot0008* TOSHIBA MQ01ACF050
Boot0009* TOSHIBA MQ01ACF050
Boot000A* WDC WD5000BPKT-75PK4T0
Boot000B* WDC WD5000LPLX-75ZNTT0
Boot0005* DTO Legacy USB Floppy/CD
Boot0006* Hard Drive
Boot0007* IBA GE Slot 00C8 v1381
# reboot
login: root
Password:
Last login: Fri Oct 7 20:00:38 on ttyu0
FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC
# mount
/dev/mirror/gm1p2 on / (ufs, local, soft-updates)
devfs on /dev (devfs)
/dev/mirror/gm1p1 on /boot/efi (msdosfs, local)
# dmesg | grep GEOM
GEOM_MIRROR: Device mirror/gm0 launched (2/2).
GEOM_MIRROR: Device mirror/gm1 launched (2/2).
GEOM: mirror/gm0: the secondary GPT table is corrupt or invalid.
GEOM: mirror/gm0: using the primary only -- recovery suggested.
GEOM: mirror/gm1: the secondary GPT table is corrupt or invalid.
GEOM: mirror/gm1: using the primary only -- recovery suggested.
# gpart recover mirror/gm0
mirror/gm0 recovered
# gpart recover mirror/gm1
mirror/gm1 recovered