# recover data



## Ofloo (Jul 8, 2011)

well few days ago I noticed kernel core on one of my systems, .. FreeBSD went into a loop trying to dump the swap however it never managed, so i figured disabing the dump would work, so i got an bootable usb stick and disabled the flag from rc.conf, only to find out it still wanted to dump the swap, so i figured if i zero'd the swap file it would solve the problem because there wouldn't be any data left to dump. This was my mistake i performed dd if=/dev/zero of=/dev/ad4s1b bs=1M on the swap partition, .. only to conclude later that all my data was gone, .. 

I was wondering if it is possible in any way to recover this data, because when i fdisk i can still see slices but they have no shape/size, ..

Would dumping the disk, allow me to use a file to work from, so i can already reinstall the system and collect the data later on, if it would be possible at all to recover this data?

Regards, ..


----------



## tingo (Jul 9, 2011)

If it is just your disklabel that is gone, you can try sysutils/scan_ffs. There are more rescue tools in ports, but they all have a steep learning curve.


----------



## Ofloo (Jul 9, 2011)

ok i extracted scan_ffs to /tmp directory of the fixit

```
scan_ffs -l -s /dev/ad4s1 > /tmp/disklabel
```
I get the list of drives and where they where last mounted.
got one input/output error probably the swap cause that one is missing.

```
bsdlabel -R -n -m amd64 ad4 /tmp/disklabel
```

get error unknown diskabel field. anyone suggestions.

Or does anyone got a good howto on this stuff ? Or how i can dump the disk partitions from fixit to an usb disk so i can recover them later on.

EDIT:
ok i edited the disklabel file to a d e f instead of the X now it created the device list however once i want to mount, it gives invalid argument error

on example mount /dev/ad4a /tmp/mnt same if i use -f or define type -t ufs, it seems though i should of used ad4s1 instead of ad4 though the names changed not sure if that's a problem.


----------



## Ofloo (Jul 10, 2011)

ok in order to get rid of the error i removed the disklabel 
	
	



```
dd if=/dev/zero of=/dev/ad4 bs=512 count=16
```
 from ad4 then created the slice using fdisk just agreed to what fdisk already knew and wrote it to the disk, .. what is left now is restoring boot strap

after mounting the main file system to /mnt/tmp

```
disklabel -B -b ./boot/boot -m amd64 ad4s1a
```
however that last one doesn't realy work, anyone suggestions on fixing the bootstrap/record whatever


----------



## Ofloo (Jul 11, 2011)

maybe crazy idea and i just noticed so i wonder if this would work if the mbr is 512bytes and boot0 is default mbr would dd if=/boot/boot0 of=/dev/ad4 bs=512 count=1 restore the boot record ?


----------



## Ofloo (Jul 11, 2011)

ok i finaly figured out how to do it


```
fdisk -BI -b boot ad4
bsdlabel -w -b boot -m amd64 ad4s1a
```
then do redo the disklabel cause -w will wipe the current disklabel

ps: the trick is to copy every thing to the tmp then unmount the disks cause they won't allow write access to them if they are mounted.


----------



## Ofloo (Jul 11, 2011)

well, .. i got to reinstall anyways cause i don't get further then bringing up the ether link but it was nice to figur out how to do this and at least i got my data back.


----------



## wblock@ (Jul 11, 2011)

Ofloo said:
			
		

> well, .. i got to reinstall anyways cause i don't get further then bringing up the ether link but it was nice to figur out how to do this and at least i got my data back.



Good!  Now make a backup so you don't have to go through this again.


----------



## Ofloo (Jul 12, 2011)

you know the funny part is i bought the disks to do backups like year ago, but i never got to it, something else always came up.


----------



## wblock@ (Jul 12, 2011)

That's the way it usually goes.  The only time you'll need a backup is when you don't have one.


----------



## Ofloo (Jul 12, 2011)

True most of my systems have backups however, in 10 years never needed it once. In fact this would of been the first case I was worried about a backup. This time I realised how little I backed up on this system. On the other hand I managed to get the data back, so you got to wonder if a backup is really necessary these days. It would of made things a lot easier though, though I learned a lot of new stuff, which I otherwise wouldn't of bothered reading, .. I'm thinking of setting up zfs with dual disk so I don't really have to worry about proper backups cause from what I understand is that zfs does backups .. on to fly bit like raid-1.


----------



## rusty (Jul 12, 2011)

You never need a seatbelt until you have a crash either. 

To my mind its not a case of whether you need backups (as you got the data back), it's the ease of getting it back in the first place.


----------



## Ofloo (Jul 13, 2011)

exactly, I'm not claiming otherwise, however i was thinking of a different system on how to backup currently i did few backups with dump and man it takes forever.


----------



## wblock@ (Jul 13, 2011)

chflags(1) and nodump can help to trim a lot, like /usr/ports and all the big distfiles.


----------



## Ofloo (Jul 14, 2011)

nice one didn't know that


----------



## wblock@ (Jul 14, 2011)

Examples here: Backup Options For FreeBSD


----------



## Ofloo (Jul 15, 2011)

Thank you for that link.


----------

