2

I was trying to make my HDD bootable and did

gpart bootcode -b /boot/pmbr -p /boot/gptboot -i1 ada0s1

and now I got "Invalid partition" message on boot.

/boot was from USB drive, not from HDD (which is ada0s1).

Is it possible to restore partition from this situation?


# gpart show /dev/ada0s1
=>      0   976770081  ada0s1    BSD   (466G)
        0          16            - free -   (8.0K)
       16   959992849       1    freebsd-ufs  (458G)
959992865    17777216       2    freebsd-swap   (8.0G)

trying

# fsck /dev/ada0s1
** /dev/ada0s1
Cannot find file system superblock
# fsck /dev/ada0s1a
** /dev/ada0s1a
Cannot find file system superblock
# fsck /dev/ada0s1a

Trying to guess superblocks didn't help

newfs -N /dev/ada0s1a
192, 1282432...

then

fsck_ufs -b 192 /dev/ada0s1a
Akternate super block location: 192
** /dev/ada0s1a
192 is not a file system superblock

It was working before gpart bootcode

Dims
  • 3,181
  • 9
  • 49
  • 107
  • 1
    By definition you cannot un-brick a device. To brick is to irrevocably remove functionality from a device: to render it as if a brick. – ctrl-alt-delor Aug 05 '19 at 23:11
  • 1
    Looks like you used UEFI-specific command syntax, and perhaps your system boots in legacy MBR style? Apparently `/boot/pmbr` is Protective MBR, a fake MBR partition table that tells systems that only understand MBR partitioning: "this disk is partitioned but in a way you don't understand". When applied to a MBR-partitioned disk, that would overwrite the real MBR partition table, which would explain the error you're getting. [testdisk](https://www.cgsecurity.org/wiki/TestDisk) might be a good first step in recovering the real MBR partition table; only after that you might try `fsck`. – telcoM Aug 06 '19 at 08:48
  • @telcoM I don't see FeeeBSD version – Dims Aug 06 '19 at 18:38
  • By installing the `gptboot` code into your UFS partition, you have damaged your UFS filesystem. You will need to `newfs` it and restore from backup. `gptboot` code is meant to go into a partition of type `freebsd-boot`. – Jim L. Aug 06 '19 at 19:27
  • @JimL. is it possible to recover from this damage with FreeBSD live cd or something? – Dims Aug 06 '19 at 19:43
  • I'm sorry to bear bad news, but no. I mean not *just* a live CD. You may want to use a live CD to restore from your backup, but I think your only options are to restore from backup (if you have one), or to re-install. You **might** be able to do some emergency file recovery by using the right tools to scan through the raw partition, but that's outside my scope of expertise. The filesystem can be fixed only by `newfs` and restore, or `newfs` and reinstall. – Jim L. Aug 06 '19 at 20:14

1 Answers1

0

I successfully recovered most of the data on the partition after the similar mistake with the following steps:

  1. Create a file from damaged partition using dd or testdisk (image.dd)
  2. dd if=image.dd of=ffs.dd bs=1024 count=204800
  3. newfs ffs.dd
  4. mdconfig image.dd
  5. dd if=ffs.dd of=/dev/md0 bs=512 count=140
  6. newfs -N /dev/md0 (write done backup superblocks 192, 1282368 etc)
  7. fsck_ffs -b 192 /dev/md0 (try another superblock if this one fails)
  8. fsck_ffs /dev/md0

Then you can access recovered files. Do it with caution because some of them are damaged.

Greenonline
  • 1,759
  • 7
  • 16
  • 21
dsamersoff
  • 21
  • 1