# grub, linux, xp, freebsd - multiboot problem



## alys (Jun 7, 2010)

I have 2 hdd
1.40gb - primary master - ubuntu
2.40gb - primary slave - 30gb partition - XP, 10gb partition - room for FreeBsd.

before I try to unstall freebsd 8.0, I had freebsd 7.0 there, and the bootloader - grub. and could load any os without problem.
but after few attempts to find "where are this packets on CD" I occasionally not avoid the setting the bsd loader by 8.0 installation.
grub is not damaged and shows correct menu - ubuntu variants, XP, freebsd.
I m able to load ubuntu(i use it just now), i am able to load freebsd 8, but i m not able to load xp.
it says - ntldr missing, press ctrl alt del.
this problem is common and is discussed in inet...but I cant understand what to do now.
facts:
1.when I installed freebsd i did not change the disk configuration, so freebsd installation target was 2 partition of primary slave.
2. grub is working fine and not damaged
3. bootsector of WinXP partition seems not damaged, because primaryloader from there is running and says - ntldr not found. I checked this sector(zero of XP partition) and there is this text. So grub is able to run code from there... but this code cant find main nt loader....which is also in root dir of XP, and all files needed are there (also I doubt freebsd could damage file in XP partition so easy at instalation)...
so I cant understand what freebsd did with XP partition, that XP primary loader cant find the main one.


----------



## Beastie (Jun 7, 2010)

As for your problem, this may help. Don't follow it blindly though. If you don't know what you're doing, don't understand what's going on, and operate on the wrong disk/slice you'll make things worse.
If you have any doubt, don't hesitate to ask. And if you do, post the output of `% fdisk ad[b]X[/b]`, replacing *X* with the "primary slave".


----------



## zeiz (Jun 7, 2010)

FreeBSD doesn't touch XP (and Ubuntu) partition. Only MBR could be replaced or corrupted.
What version of Ubuntu do you have? Does it use legacy grub or grub2?
If it's unknown boot to Ubuntu and run in terminal:
`$ sudo grub-install -v`
If version is 0.97 then
`$ sudo grub-install hd0`
If version is 1.98 then
`$ sudo grub-install sda`
`$ sudo update-grub`
See if grub2 finds Windows XP


----------



## alys (Jun 7, 2010)

> What version of Ubuntu do you have? Does it uses legacy grub or grub2?


Ubuntu 10.04.
About grub version I forgot...i am at work know, and cant check it...it seems grub2.
But grub itself work fine, at least he starts code from bootsector of XP. and (if am I right), grub's task is finished.
also he starts booting of Ubuntu and my new freeBSD.
so it is not grub.
so there is no question(I believe) that "grub cant find Windows".

Bestie and zeiz! You speak opposite. Zeiz said - freeBSD doesnt touch not his partition. But Bestie advice looks like restore of XP partition geometry. By the way I think, that bsd did something with geometry of XP partition...better to say -- bsd did something with geometry data somewhere on my primary slave, and XP bootloader senses it. question is - where is this geometry data.
Just now Im at work and cant test your advices.
But Bestie speaks smth I think useful.


----------



## Beastie (Jun 7, 2010)

alys said:
			
		

> Bestie and zeiz! You speak opposite. Zeiz said - freeBSD doesnt touch not his partition. But Bestie advice looks like restore of XP partition geometry. [...] question is - where is this geometry data.


What we are saying is not contradictory at all: the slice/partition itself _is not_ modified; the information that describes it _is_.
This information is stored in the partition table, a 64-byte array with 16 bytes per entry. This array starts at the 446th byte of the MBR (sector 0) and can be edited using fdisk(8) as mentioned in the link I posted previously.


----------



## zeiz (Jun 7, 2010)

alys said:
			
		

> question is - where is this geometry data.


On MBR, in partition table. That's Beastie's quite right approach.
However if your car doesn't start once you may order its towing to garage but you also may check first aren't you running out of gas: it's free


----------



## alys (Jun 7, 2010)

```
However if your car doesn't start once you may order its towing to garage but you also may check first aren't you running out of gas: it's free
```
sorry I m too noisy...but if grub calls xp partition bootsector code...then grub understand geometry, isnt it?
question 2 - does code running from bootsector of XP partition read MBR of his disk, to know geometry to find second stage bootloader of XP? because advice to patch geometry in MBR work for this case only.
sorry if i get your time.


----------



## alys (Jun 9, 2010)

bsd people!
finaly I have a time to play with my broken XP loading.
this is the output of Ubuntu
sudo fdisk -l
(partually in russian, because it is localised)
******

```
Ð”Ð¸ÑÐº /dev/sda: 40.0 Ð“Ð‘, 40020664320 Ð±Ð°Ð¹Ñ‚
255 heads, 63 sectors/track, 4865 cylinders
Units = Ñ†Ð¸Ð»Ð¸Ð½Ð´Ñ€Ñ‹ of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d1678

Ð£ÑÑ‚Ñ€-Ð²Ð¾ Ð—Ð°Ð³Ñ€     ÐÐ°Ñ‡Ð°Ð»Ð¾       ÐšÐ¾Ð½ÐµÑ†       Ð‘Ð»Ð¾ÐºÐ¸   Id  Ð¡Ð¸ÑÑ‚ÐµÐ¼Ð°
/dev/sda1   *           1        4661    37431296   83  Linux
/dev/sda2            4661        4866     1648641    5  Ð Ð°ÑÑˆÐ¸Ñ€ÐµÐ½Ð½Ñ‹Ð¹
/dev/sda5            4661        4866     1648640   82  Linux ÑÐ²Ð¾Ð¿ / Solaris

Ð”Ð¸ÑÐº /dev/sdb: 40.0 Ð“Ð‘, 40020664320 Ð±Ð°Ð¹Ñ‚
15 heads, 63 sectors/track, 82714 cylinders
Units = Ñ†Ð¸Ð»Ð¸Ð½Ð´Ñ€Ñ‹ of 945 * 512 = 483840 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Ð£ÑÑ‚Ñ€-Ð²Ð¾ Ð—Ð°Ð³Ñ€     ÐÐ°Ñ‡Ð°Ð»Ð¾       ÐšÐ¾Ð½ÐµÑ†       Ð‘Ð»Ð¾ÐºÐ¸   Id  Ð¡Ð¸ÑÑ‚ÐµÐ¼Ð°
/dev/sdb1   *           1       62033    29310561    7  HPFS/NTFS
/dev/sdb2           62034       82705     9767520   a5  FreeBSD
```
****

my disks are equal - Seagate ST340016A, but with different firmware.
I see that first has 

```
255 heads, 63 sectors/track, 4865 cylinders
```
but second - 

```
15 heads, 63 sectors/track, 82714 cylinders
```
so geometry is different.
as I said above, linux and FreeBSD are bootable, but XP - not.
question...if I change manually geometry of disk2 to 

```
255 heads, 63 sectors/track, 4865 cylinders
```
could it help me?


----------



## alys (Jun 9, 2010)

`$ sudo grub-install -v`
says:

```
grub-install (GNU GRUB 1.98-1ubuntu6)
```


----------



## Beastie (Jun 9, 2010)

Did you read the link I posted yet? Did you try it? Did it work/not work?

At first, change the head only. And do this for the Windows XP partition only. BTW, there's no such a thing as changing the geometry of a _disk_.
Also, the instructions I linked are for FreeBSD's fdisk. I have no idea if GNU/Linux's fdisk behaves similarly.


----------



## alys (Jun 9, 2010)

i ll not change the headnumber of this partition, because totally misunderstand why ubuntu reads this, NTFS partition, and I can see any file there...
hm... just now im reading MS manual about partitions.
by the way - could you advice to me some freebsd tech text, to understand what freebsd could do with mbr in my installation configuration - to second partition of slave. What freebsd did with my lovely MBR of my lovely slave? 
I m slightly a system programmer and i hope i could understand.


----------



## alys (Jun 11, 2010)

I solved it just now.
the reason of the problem - during installation freebsd overwrote the MBR of HDD, where I put it. my second HDD. And it had recalculated the partition parameters of the first partition(NTFS), having in mind CHS parameters from bios.  where my bios says about 16 heads.
but this partition was created by XP installer as partion with 255 heads. It was stored in boot sector of this partition, and....here was some conflict and windows bootcode stops with error.
I studied the code of this bootloader, and this data is stored there.

solution.
what I did.
from linux I run the "testdisk" utility, select my drive(second in list), and go to Change geometry. this sets the "geometry values" for this programm, and is not written anywhere. Then I go to "analyse" and read the mbr(it reads the partitions data). All partitions are in green color(in my case), which reports(I hope) that all is right.
then I press - "write" menu item, and (I hope) this values were written in partition table, assuming that heads total is 255.
reboot and....my XP is here.
solved.


----------



## alys (Jun 11, 2010)

i missed that when you go to Change geometry, you must enter there 255 heads, proper number of tracks(), and 63 sectors per track.


----------

