UFS How to recover a UFS partition

A bootable UFS partition has suddenly changed into free space after booting from alternative device which must have changed the boot sector somehow. I It was available via FreeBSD's boot manager but no longer is. Booting from a different device and running gpart show shows Free Space where my UFS partition should be. Is recovery possible? How can look at the raw data to see if my data is still there?
 
Thanks for the suggestion. Can't say I'd ever come across this option, so had a look... Does this only apply to GPT disks? Mine is MBR. The two partitions which are displayed ar NTFS. My Freebsd partition was originally created by shrinking the main Windows partition.
 
If I create a ufs partition on a different device equal in size to the free space left on my original disk can I expect to recover my data using dd() ?

I'd give it a try just to see what happens, but how do I work the value of the parameter 'skip' ? Should it be the value shown by gpart() as the logical starting block?
 
If you know for sure the original geometry you could dd(1) the problematic disk to a new one. Then you can run gpart(8) or whatever you have used and let it write the partitioning on top of the copied data. In best case everything matches and you can access your data. If not you still have the unmodified original disk.
 
Is the partition healthy? Can you mount it if you boot from a rescue disk?

I would make a copy of the entire disk first if it contains data you really want to recover.
 
If you know for sure the original geometry you could dd(1) the problematic disk to a new one. Then you can run gpart(8) or whatever you have used and let it write the partitioning on top of the copied data. In best case everything matches and you can access your data. If not you still have the unmodified original disk.
I had a bootable UFS partition on a disk with two Windows partitions and for some reason it became marked as Free space. All I want to do is find out what is there. My hope is that the 'Free space' is still my bootable UFS partition, but not sure how to tell.
 
This is very likely. But if you need your data it is safe to copy everything first.
Yes, I was hoping to do that using dd() to copy data from the 'Free space' area to a different device but haven't got my head around the command line I need...
 
Have you tried using fixparts(8) to restore the mbr? As it seems from your description the ufs file system should be intact, perhaps this will bring back your file system.
 
Have you tried using fixparts(8) to restore the mbr? As it seems from your description the ufs file system should be intact, perhaps this will bring back your file system.
Thanks for the tip. I see there is a man page for this utility, although I've never heard of the utility.. I thought it might be a builtin command, but no. Neither is it available as a pkg... It looks as though it needs to be downloaded from

Is this a FreeBSD program?
 
Is the partition healthy? Can you mount it if you boot from a rescue disk?

I would make a copy of the entire disk first if it contains data you really want to recover.
What was my UFS partition now appears as Free space....

Here is the output from gpart show ada0:-
Code:
=>       63  500118129  ada0  MBR  (238G)
         63       1985        - free -  (993K)
       2048     204800     1  ntfs  (100M)
     206848  358703104     2  ntfs  [active]  (171G)
  358909952  141208240        - free -  (67G)

I'm trying to figure out a dd() command line to copy that free space to a partition on another disk.

Any suggestions would be appreciated.
 
Just modify the partition indicator to freebsd-ufs and you should be fine.
Edit:
You need to add the partition starting from 358909952 with a size of 141208240. That should create your 67G UFS partition. DO NOT newfs obviously.

Unverified command:
gpart add -t ufs -b 358909952 -s 141208240 ada0

Then run fsck on it, to check.
 
gpart add -t ufs -b 358909952 -s 141208240 ada0
gpart: Invalid argument

Changed '-t ufs' to '-t freebsd-ufs' and got the same result.
 
fixparts comes with port sysutils/gdisk.
fixparts shows:-
Code:
Disk size is 500118192 sectors (238.5 GiB)
MBR disk identifier: 0x6F727265
MBR partitions:

                                                   Can Be   Can Be
Number  Boot  Start Sector   End Sector   Status   Logical  Primary   Code
   1                  2048       206847   primary     Y        Y      0x07
   2      *         206848    358909951   primary              Y      0x07
gpart show ada0 shows:-
Code:
=>       63  500118129  ada0  MBR  (238G)
         63       1985        - free -  (993K)
       2048     204800     1  ntfs  (100M)
     206848  358703104     2  ntfs  [active]  (171G)
  358909952  141208240        - free -  (67G)
 
Your disk partitioning is overall, ok. There is no problem with the MBR as that clearly is showing in the status output of message 14.
My apologies, I couldn't immediately recall the type. Change type to freebsd:

gpart add -t freebsd -b 358909952 -s 141208240 ada0
 
Your disk partitioning is overall, ok. There is no problem with the MBR as that clearly is showing in the status output of message 14.
My apologies, I couldn't immediately recall the type. Change type to freebsd:

gpart add -t freebsd -b 358909952 -s 141208240 ada0
OK, done that and now gpart show ada0 shows:-

Code:
=>       63  500118129  ada0  MBR  (238G)
         63       1985        - free -  (993K)
       2048     204800     1  ntfs  (100M)
     206848  358703104     2  ntfs  [active]  (171G)
  358909952  141208240     3  freebsd  (67G)

but can't figure out how run fsck() on partition 3...

As an alternative I was hoping to copy (part of) the area to a different device using dd() using:-

dd if=/dev/ada0s3 of=/mnt/install/tmp/dump skip=358909952 count=10000 bs=2M

but get:-

dd: /dev/ada0s3: Input/output error
 
Not sure what you mean... My command should have been:-

dd if=/dev/ada0 of=/mnt/install/tmp/dump skip=358909952 count=10000 bs=2M

but I still get the same error. ie input/output error . I can't figure out how to skip to the start of what was marked as the Free space...
 
balanga: Note you specified the bs to 2M, so skip will do the 2M*skip size. Check this little test:
Code:
$ echo 12345678 > /tmp/a
$ dd if=/tmp/a of=/tmp/b bs=1 skip=2 count=2
$ cat /tmp/b
$ dd if=/tmp/a of=/tmp/b bs=2 skip=2 count=2
$ cat /tmp/b
You need to use the same approach.

I'm coming late to the party. If it was I who was doing the recovery of the disk I'd dd the whole disk somewhere if data is important enough for me and then start changing stuff.
Type freebsd means you subdivided the partition (slice) into subpartitions (partitions). Are you sure you had this ?

Also any chance you had hybrid MBR ? What was the device (OS) you booted when it happened?
 
Yes, what I meant was please provide output of: ls /dev/ada*
ls /dev/ada*:-

/dev/ada0 /dev/ada0s1 /dev/ada0s2 /dev/ada0s3


but... /dev/ada0s3 was probably created at the wrong start point... In retrospect I probably should not have used the '-b' or '-s' options. If there is no '-s' parameter doesn't gpart use up all available remaining space?
 
Why was it created at the wrong start point? Did you not enter -b 358909952?
So, can you fsck -n /dev/ada0s3?

If you did not use the -b, it should have just created it from that point anyway as it found it to be free. Specifying begin point and size is only to ENSURE this is the case. Peace of mind, so to speak.
Equally, just specifying -s would get the same result. It's more a habit I got into years ago when I occasionally trashed a partition: specify beginning and size to be sure.
 
Back
Top