# Correcting partition / slice table



## Seeker (Jan 10, 2010)

So, exactly this motivated me, to fix it with fdisk.

This error doesn't appear on my server, from which I am posting now, but from my laptop.
--> *both* are 8-STABLE

I used fdisk and chosen it's correction recommendations.
It fixed ad4s*1*'s start and size, which is WinXP *C drive*
It fixed ad4s*2*'s start and size, which is WinXP *D drive*
Then it fixed ad4s*3*'s start and size, which is *FreeBSD 8-STABLE*

Exactly, this last one was very suspicious to me, as it offered size which was double from inicial value thus extending it from 30 Gb to 60 Gb, which assumes breaking HDD capacity of 150 Gb to 180 Gb.
I allowed this as it was last - third slice on a disk so there is nothing to overwrite forwardly 

Now, as soon, as FreeBSD's MBR manager appears, I can't boot in FreeBSD (F3), I get a beep and WinXP (F1) just shows initial loader and crashes.

I intend to download *8.0-RELEASE-i386-livefs.iso* and burn it to CD.
Then boot from it on my laptop and fix partition table from it.
BUT, which tool should I use? fdisk again?
Is there tool, smart enough, to see what type of data is on disc and to offer sector start and size corrections, based on it?

Better recommendation? _I am gonna snap!1_


----------



## Beastie (Jan 10, 2010)

Seeker said:
			
		

> Now, as soon, as FreeBSD's MBR manager appears, I can't boot in FreeBSD (F3), I get a beep and WinXP (F1) just shows initial loader and crashes.


Maybe this thread could help.



			
				Seeker said:
			
		

> Is there tool, smart enough, to see what type of data is on disc and to offer sector start and size corrections, based on it?


TestDisk.


----------



## aragon (Jan 11, 2010)

It would be helpful to know what you did.  It sounds like you destroyed the boot records at the start of each slice.  If you can boot your FreeBSD system somehow you should be able to restore the bsdlabel boot code with:


```
gpart bootcode -b /boot/boot ad4s3
```

Replace ad4s3 with the correct slice device name.

As for the Windows system, I've no idea how to replace the boot code there.


----------



## Seeker (Jan 11, 2010)

I used *ONLY* fdisk and followed it's recommendations, to adjust start and size of each slice.
Then rebooted and came into this situation.

Is fdisk messing with boot records at the start of each slice??

Each slice has been 'moved' few MB's back<->forward.

All data is still there and untouched.

I used live cd and used sysinstall which again offered different readjustments, but with no results.

I guess I need tool, which seeks HDD and figures out, on it's own, how should partition table look and then write it.


----------



## aragon (Jan 11, 2010)

Seeker said:
			
		

> I used *ONLY* fdisk and followed it's recommendations, to adjust start and size of each slice.
> Then rebooted and came into this situation.
> 
> Is fdisk messing with boot records at the start of each slice??
> ...


Erm, I hope you kept a backup of your MBR then, or you're going to have a fun time getting it back to how it was.  Like you said, you've moved the slice boundaries around.  You can't just move them around without realigning the data on them, and you can't realign the data if you don't know where it was.  Not to mention you didn't even need to move them around to begin with.

So good luck.  All I can think of is to perform a binary search of your disk for the contents of /boot/boot1.  In theory your bsdlabel will start there (or somewhere there).


----------



## Seeker (Jan 11, 2010)

aragon said:
			
		

> Erm, I hope you kept a backup of your MBR then, or you're going to have a fun time getting it back to how it was.  Like you said, you've moved the slice boundaries around.  You can't just move them around without realigning the data on them, and you can't realign the data if you don't know where it was.  Not to mention you didn't even need to move them around to begin with.


I've trusted to boot error msgs and to fdisk itself, so, is it a bug in a tool?


			
				aragon said:
			
		

> So good luck.  All I can think of is to perform a binary search of your disk for the contents of /boot/boot1.  In theory your bsdlabel will start there (or somewhere there).


I see. I'll attempt it from livecd.

And to all other potential helpers, to make problem more simple.
Just imagine there was many slices on HDD and then I erased partition table and created 1 that covers whole HDD, without backup or anything.

ONLY partition table has been touched, *not data* itself on HDD.

Now I wana restore old slices layout. :\



			
				Beastie said:
			
		

> TestDisk.


This tool looks promising...
But I can't install it from ports, as I can't boot into HDD, so I need to boot from livcd and use TestDisk.


----------



## Seeker (Jan 11, 2010)

Creeeew!
You are totally not helping me, almost at all!
I mean, this is considered emergency! And note some crappy everyday issue. 

Anyway I succeed! 

I went for _frenzy live cd_ and after many procedures and test and trials and errors I've managed to scan HDD for partitions and bsdlabels, etc...
And successfully regenerated partition table with TestDisk.

Right now, I booted into FreeBSD and am rebuilding world + kernel from source.

I only haven't tried to boot into WinXP, but I will, after rebuild from src procedure finishes.


----------



## aragon (Jan 11, 2010)

Seeker said:
			
		

> You are totally not helping me, almost at all!


Incredible.  Your solution came directly from someone suggesting the tool that saved you and yet no one is helping you at all.


----------



## Seeker (Jan 11, 2010)

aragon said:
			
		

> Incredible.  Your solution came directly from someone suggesting the tool that saved you and yet no one is helping you at all.


I expected a set of commands which would restore my partitions.
Thank you.

PS: Booting into XP works!


----------

