Other Recovering BSD disk volume label

I recently overwrote a BSD volume label by mistake and I cannot access the partitions contained in a slice any more- So I am looking for a tool for recovering the partitions.

Background. The disk has one slice with four partitions (ada0s1a, ada0s1b, ada0s1d, ada0s1e) in it.
FreeBSD was installed on partition a, b was free, d is a swap partition and e is a UFS mounted under /home.
I installed the latest FreeBSD version on partition b and it worked OK. I still had the problem that the boot loader booted only the old installation from a. In order to boot the installation from b I had to interrupt stage2 of the bootloader and enter the partition manually. To solve this problem, I have installed stage 0 on the slice (in my, probably wrong, understanding, this should have given me a choice to boot from either of the two partition in the slice using F1, F2):

boot0cfg -B /dev/ada0s1

This did not solve the boot problem. Additionally, now the partitions in slice s1 do not show up anymore. gpart show does not display them either.

So, I guess I have corrupted the partition table inside the slice. Is there any tool that can repair this? I guess that, by scanning the slice, it is possible to find where each partition (three UFS filesystems and a swap partition) start and end. Does such a tool exist?
 
Look at sysutils/scan_ffs
Code:
scan_ffs(8) recovers accidential lost or deleted disklabels.

This is the life-saver of typos.  If you have ever been working too long,
and just happened to type 'disklabel -rw da0 floppy', instead of 'diskla-
bel -rw fd0 floppy', you know what I am talking about.

This little program will take a raw disk device (which you might have to
create) that covers the whole disk, and finds all probable UFS/FFS parti-
tions on the disk.  It has various options to make it go faster, and to
print out information to help in the reconstruction of the disklabel.

Ported from OpenBSD to FreeBSD 4/5 with support for UFS1 and UFS2.

If you know the sizes of BSD-partitions you can recreate and rewrite bsdlabel with new one.
If you restore a correct bsdlabel - then usually all filesystems will be alive.
For example, I have a sheet of paper with partitioning scheme of recently installed FreeBSD. It is possible to create new 'bsdlabel' with the same sizes as on the install-time.

Some people write about success with search of bsdlabel dump within expected location of swap partition.
But I can't repeat the success on my installation.
Article in Russian. https://www.opennet.ru/base/sys/partition_restore.txt.html
strings part-of-disk-image-what-contain-swap-partition-image | grep "disk: " -A25 -B25 > /tmp/result

offtopic:
Some of *BSD distro use 'b' partitions as swap automatically, because it usually used for swap.
It is possible to lost a data on 'b' partition after trying to boot some new BSD-like distro.
 
Thanks a lot for the information. I see that it was a bad idea to install FreeBSD on partition b. Probably that is the reason why the boot loader was not offering to boot from that partition. However, since I have booted manually from partition b (which was then mounted as root) I assume that it was not used as a swap partition.

I have started to scan the whole disk with scan_ffs, it will take a few hours. I hope the filesystems are still there: I have overwritten 512 bytes of the MBR partition: so that should not have damaged any UFS filesystem.

I will report how it worked out when the scan is finished.

Otherwise I may try the strings solution. I can read some Russian but not so fluently. If I cannot solve the problem otherwise, I will try to read the article you linked to.

Thanks for now.
 
I see some interesting points in your posts:

boot0cfg -B /dev/ada0s1
boot0cfg () usually operates with MBR (sector 0 on HDD).
You have installed MBR-like boot-code to the 1st MBR-partition instead of the disk ada0.
I think that correct command might be like boot0cfg -B /dev/ada0

For your case, FreeBSD's MBR-partition ada0s1 contains info about FreeBSD-partitions a-b-c-d-e-.. and some bootcode.

I have overwritten 512 bytes of the MBR partition:
Seems like you have overwtitten 1st sector of 1st partition.
It is a bsdlabel data, which contains info about FreeBSD-partitions like ada0s1a, ada0s1b, ada0s1d.

Be sure, your data still on the disk, but you have to recover bsdlabel information, but not the MBR-data.
 
Last night I scanned the whole disk with

# scan_ffs -l -v /dev/da0

The disk is attached to another computer using a USB adapter, that's why it appears as da0. I did not see anything in the output that looks like partition information by bsdlabel. But today I can see the partitions again:

# bsdlabel /dev/da0s1
# /dev/da0s1:
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 83886080 0 4.2BSD 0 0 0
b: 83886080 83886080 4.2BSD 0 0 0
c: 1953525103 0 unused 0 0 # "raw" part, don't edit
d: 33554432 167772160 swap
e: 1752198510 201326592 4.2BSD 0 0 0

This looks OK to me.
I am checking the filesystems on partitions a, b and e: everyting seems OK-

Does scan_ffs repair the disklabel automatically?

Anyway: I recoverd all my data. Thanks a lot, you saved my day!
 
Last edited:
Back
Top