Solved gpart restore hangs on corrupt partition table

gpart restore hangs from taken gpart backup.
[ Luckely it's zfs so there are copies and zpool imports without problem, but there are a few cksum errors ]

/sbin/gpart backup da2 > /root/partitions/part_da2.txt
/sbin/fdisk -vsp /dev/da2 > /root/partitions/fdisk_da2.txt

I have these backups but can't seem to restore from it ?
 
boot from stick or cd and try if it works then
it might be a deadlock, busy case
you also may have a copy in /var/backups
 
Good idea. But I already started a zpool scrub. Result in 5 days.
[ Of the record, HP-BIOS drives you knuts. The same input produces random output, as completely opposed to determinism ]
 
Even when i exported the zpool, and no partition mounted, gpart would not restore it.
This is the output of :
Code:
/sbin/fdisk -vsp /dev/ada2 > /root/partitions/fdisk_ada2.txt
Code:
GPT 128
1   freebsd-zfs          6 1220934389 ZUSBLABEL
Like covacat said maybe i should have booted from a USB stick.
[ PS: It shows a strength of ZFS to survive a corrupt GPT/MBR table by using copies of the most essential data ]
 
Unless I'm not seeing it, where is your restore operation? The fdisk command shown is simply dumping what it finds, which in #5 you have /dev/ada2 but the other posts you have /dev/da2

This command creates a file in a special format (not really a text file) that is a dump of the partition table on da2.
/sbin/gpart backup da2 > /root/partitions/part_da2.txt

To use that backup copy:
/sbin/gpart restore /dev/da2 < /root/partitions/part_da2.txt

The backup and restore commands have worked in the past for me as long as nothing has opened the device (mounted a partition, etc).
What I have done in the past is when I mirrored a boot device. Lets call them ada0 and ada1. ada0 is fully partitioned, fully operational, root on zfs. I physically added in ada1, brand new, same device, not partitioned, not anything. It's a baby.
I did:
gpart backup ada0 > /root/ada0.part
gpart restore ada1 < /root/ada0.part

That gave me 2 devices with the same partitioning (including the same labels if any). I then used gpart commands on ada1 to relabel so there was no overlap then I did all the gpart bootcode ada1 and zfs attach ada1/zfs-partition to the ada0 vdev to create the mirror.
 
With these commands it shows me geom file exists (error).
The thing is restoring partition tables is not as easy as /sbin/gpart or /sbin/fdisk give you the impression.
I've got two drives where the zpool import good, but the gpt partition are corrupt,
GEOM: da2: the primary GPT table is corrupt or invalid.
GEOM: da2: using the secondary instead -- recovery strongly advised.

I didn't lost data, but i could have lost data. And bios plays important role in it.
It also has to do with USB where there is detection order , and not bus connection order ...
 
gpart recover da2

when you first partition with gpt scheme, the partition table is at the front of the device but a backup copy is stored at the end of the device.
man gpart, scroll down to the RECOVERING section and you will see exactly your two messages.
 
After a reboot and export i was able to correctly restore the partiontables using fdisk & gpart.
It's imperative that the drive is not in any way active or busy.
The command used was:
Code:
fdisk -i -f ./fdisk_da2.txt /dev/da2 
gpart restore -lF da2 < ./part_da2.txt
 
  • Like
Reactions: mer
Top