Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 01 Sep 2022 22:38:44 +1000
From:      Ian Smith <smithi@nimnet.asn.au>
To:        Kaya Saman <kayasaman@optiplex-networks.com>,freebsd-questions <freebsd-questions@freebsd.org>
Subject:   Re: Corrupted partitions after upgrade from 12.3 to 13.0-RELEASE
Message-ID:  <B47D8DF2-1121-4809-801B-F0764B5B0297@nimnet.asn.au>
In-Reply-To: <f0a7b860-391c-a4c9-b0f1-538c7db20a02@optiplex-networks.com>
References:  <f0a7b860-391c-a4c9-b0f1-538c7db20a02@optiplex-networks.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 1 September 2022 11:54:14 am AEST, Kaya Saman <kayasaman@optiplex-networ=
ks=2Ecom> wrote:
 > Hi,
 >=20
 > I was trying to update one of my servers earlier from 12=2E3-RELEASE to
 >=20
 > 13=2E0 RELEASE and after issuing:
 >=20
 > freebsd-update install
 >=20
 > shutdown -r now
 >=20
 > after following Chapter 24 from the Handbook:=20
 > https://docs=2Efreebsd=2Eorg/en/books/handbook/
 >=20
 > the Bootloader came up with an error about not being able to access
 > the=20
 > file system on the disk=2E Having read around a little, information=20
 > pointed to updating the bootcode on the disk=2E

When reporting errors, show precisely what was shown=2E

 > Following the docs here:=20
 > https://www=2Efreebsd=2Eorg/cgi/man=2Ecgi?query=3Dgptboot&sektion=3D8&f=
ormat=3Dhtml
 >=20
 > I ran: gpart bootcode -b /boot/pmbr=C2=A0=C2=A0=C2=A0 -p /boot/gptboot =
-i 1 ada0
 >=20
 >=20
 > Now I get a message saying "Invalid Partitions"=2E
 >=20
 >=20
 > Currently I have a 13=2E0-RELEASE usb stick in the system which I'm=20
 > booting from and am able to read the information from /dev/ada0 which
 > is=20
 > fine=2E

Specifically make and keep a copy of the first 128 512-byte sectors:

# dd if=3D/dev/ada0 of=3Dsomefile bs=3D512 count=3D128

You probably need to mount another USB stick r/w for 'somefile' for transp=
ort, recording sessions =2E=2E=2E

 > If I run: mount /dev/ada0s1 /mnt
 >=20
 > The a=2E slice mounts and the data is there!

Please show at this stage:

# gpart show -p ada0
and
# gpart show -p ada0s1

 > However, I think the partition table has become corrupted or altered=20
 > somehow after attempting to update the bootcode as the layout used to
 > be:
 >=20
 > /dev/ada0s1a
 >=20
 > /dev/ada0s1b

If the above is accurate - that your partitions were called ada0s1a and ad=
a0s1b - then your disk was NOT previously partitioned with the GPT scheme, =
but with the MBR scheme=2E

If so, running gptboot(8) will have destroyed the master boot record (MBR)=
 and replaced it with its 'protective' MBR instead, and perhaps clobbered t=
he boot record from the first UFS partition=2E

It's very old-school, but run and record accurately, to see what the pmbr =
slice table contains:

# fdisk ada0

 > b=2E slice was for swap=2E

The swap space is dispensable, if you can recover the 'a' partition=2E


 > The FS is UFS of course=2E=2E=2E=2E now I only get a single partition a=
nd no=20
 > slices at: /dev/ada0s1

You have the terminology backwards: 'slices' are the up to 4 partitions un=
der the MBR scheme, and BSD 'partitions' subdivide a slice with a (/), b (s=
wap), d,e,f =2E=2E=2E optionally others like /var, /usr, /home

The handbook in effect just says "we're going with GPT for all these examp=
les" so is no help with this unless you started with GPT, in which case the=
re would be such as ada0p1 etc, not ada0s1a etc=2E

See gpart(8) section PARTITIONING SCHEMES for much more detail=2E

 > In an attempt at recovery I mounted an NFS share on the LiveCD and
 > ran a=20
 > dd backup of the boot drive=2E
 >=20
 > First attempt was: dd if=3D/dev/ada0s1
 > of=3D/path_to_share/freebsd_bak=2Eimg
 >=20
 > Secondly I tried: dd if=3D/dev/ada0 of=3D/path_to_share/freebsd_bak_1=
=2Eimg

Good=2E  The second whole-disk one is what you want=2E  Using dd and hd (h=
exdump) you might find the X? GiB swap partition near the very end=2E

In case I'm on the the right track with this, here's a 12=2E3-RELEASE syst=
em built with bsdinstall on a SSD that came already MBR-scheme with Win10pr=
o taking first 2 slices, then FreeBSD on a 48G s4 - after I had W10 shrink =
itself and add a FAT32 slice=2E

<code>
Root@t430s:~ # gpart show -p ada0
=3D>       63  250069617    ada0  MBR  (119G)
         63       1985          - free -  (993K)
       2048    1185792  ada0s1  ntfs  (579M)
    1187840   80353280  ada0s2  ntfs  (38G)
   81541120   67108864  ada0s3  fat32lba  (32G)
  148649984  100663296  ada0s4  freebsd  [active]  (48G)
  249313280     756400          - free -  (369M)

Root@t430s:~ # gpart show -p ada0s4
=3D>        0  100663296   ada0s4  BSD  (48G)
          0    8388608  ada0s4a  freebsd-ufs  (4=2E0G)
    8388608    8388608  ada0s4b  freebsd-swap  (4=2E0G)
   16777216    8388608  ada0s4d  freebsd-ufs  (4=2E0G)
   25165824   16777216  ada0s4e  freebsd-ufs  (8=2E0G)
   41943040   58720256  ada0s4f  freebsd-ufs  (28G)
</code>

With MBR scheme it's common to see the disk shown as starting at sector 63=
, so sectors 0=2E=2E62 are reserved, and include the MBR itself plus first =
stage boot sectors=2E  Linux puts GRUB there as I recall=2E

Here, s1 (win10 NTFS) starts at 2048 (1MiB) and hd shows |=2ER=2ENTFS    =
=2E=2E=2E=2E=2E| as the start of the NTFS loader=2E

In my case I look at 8k (16 sectors) from 148649984 and see among the bina=
ry, such as =2E=2E =2ERead=2EBoot=2E error' and 'BTX' and later strings lik=
e /boot/kernel/kernel and FreeBSD/x86 boot, ie it may not be too hard to fi=
nd the start of your ada0s1a partition=2E Try:

# dd if=3D/dev/ada0 skip=3D2048 count=3D16 | hd | less

 > In either case when attempting to mount the image I get a message=20
 > saying: "Block device required"

vnode-backed mdconfig(8) perhaps? Make sure to use '-o readonly' on your i=
mage=2E

How big is the disk and image?

 > Is it possible to recover the slices or at least read the data from
 > the=20
 > backup image?

Should be, once you figure out exactly where the partition starts, unless =
the gptboot clobbered it=2E

 > I don't mind reinstalling as long as I can access the backup=2E

Need more data first=2E

 > gpart show/list ada0 doesn't give any indication about the a=2E or b=2E=
=20
 > slices, so either they are completely gone or I'm not using the
 > correct=20
 > tools=2E

Don't tell, show=2E

# gpart show -p ada0

 > Would anyone be able to suggest anything to either get the system to=20
 > boot again or at least read the information from the backup image?

If it was GPT originally, ignore me=2E  Otherwise, let's see what's there=
=2E

Cheers, Ian



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B47D8DF2-1121-4809-801B-F0764B5B0297>