Monday, December 24 2007 @ 17:51 CET
Contributed by: tingo
Everybody knows that backups and record keeping are important, But often we forget. And then something bad happens, and you are in trouble. In my case, I had a working installation of FreeBSD on slice 1 of ad4, and had just installed NetBSD on slice 2. However, something was wrong with the partitions on slice 1 after the NetBSD installation. Not NetBSD's fault of course, probably something I did. Well, time to look at the problem.
After burning a CD with the FreeBSD livefs image, I booted the Install CD and selected the correct rescue option from the menu (Fixit). Using fdisk I verified that all slices were ok. However, when I did disklabel ad4s1, it only displayed one partition - the 'c' (whole disk) partition. Uh oh, here were a problem. I did some searching on th net, and found scan_ffs (sysutils/scan_ffs) in ports. And there was a package available on ftp mirrors.But I needed a way to get the package onto the machine, which was now running from a memory disk booted from the livefs image.
enable networking: ifconfig re0 up, dhclient re0.
if dhclient complains about not being able to write a file, do mkdir /var/db, then retry dhclient.
enable name resolution. I edited the /etc/resolv.conf file, adding the info for my name server
verify that network and name resolution works: ping a known site.
fetch the package. fetch -p followed by the url for the scan_ffs package, and you are all set.
unpack the package. The package (scan_ffs-1.2.tbz) can be unpacked with tar.
First I created a directory to avoid problem with symlinks: mkdir test
tar xvf ../scan_ffs-1.2.tbz sbin/scan_ffs
run scan_ffs to recover info about the lost partitions. ./sbin/scan_ffs -l /dev/ad4s1
calculate the values for the swap partition. Since the swap partition doesn't have a filesystem on it,scan_ffs can't detect it. However, the swap partition is normally created just after the root partition, and before the next partition. Thus, if you find the partition with the lowest offset after the root partition, you can easily calculate the numbers.
recreate the disklabel. disklabel -e /dev/ad4s1 allows you to edit the label.
if disklabel says there is no valid label on the slice, simply create one first: disklabel -w /dev/ad4s1
vi, do a which vi, and set the EDITOR variable correctly.
finally, I used boot0cfg to inspect and replace the boot code on the disk
Don't forget to fsck all partitions before using them.