Contribute  :  Calendar  :  Advanced Search  :  Site Statistics  :  Directory  :  About  :  Cartoons  :  Web Resources  :  Polls ...for all that other stuff    
 Welcome to
 Monday, April 23 2018 @ 11:42 CEST

Using scan_ffs to recover disklabels

FreeBSDEverybody 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. Steps required:
  1. 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.
  2. enable name resolution. I edited the /etc/resolv.conf file, adding the info for my name server
  3. verify that network and name resolution works: ping a known site.
  4. fetch the package. fetch -p followed by the url for the scan_ffs package, and you are all set.
  5. 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
    • cd test
    • tar xvf ../scan_ffs-1.2.tbz sbin/scan_ffs
  6. run scan_ffs to recover info about the lost partitions. ./sbin/scan_ffs -l /dev/ad4s1
  7. 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.
  8. 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.
  9. finally, I used boot0cfg to inspect and replace the boot code on the disk
Finished! Don't forget to fsck all partitions before using them.

What's Related

Story Options

Using scan_ffs to recover disklabels | 1 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Using scan_ffs to recover disklabels
Authored by: tingo on Saturday, January 31 2009 @ 19:26 CET
I recently tried this with a FreeBSD 7.1-RELEASE / amd64 livefs cd. It still works, with a few minor adjustments:
  1. I had to do mkdir /var/db before starting dhclient, as it complained about that dir not being there.
  2. I had to do a disklabel -w ad4s1 before I could do disklabel -e ad4s1, because disklabel complained that ad4s1 didn't have a valid label.
I tried using pkg_add -r instead of fetch, but it complained: Can't open data connection.
 Copyright © 2018
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.03 seconds