Installation appears to have corrupted my boot sector

Asked by Peter Rye

I tried installing Ubuntu 7.04 as a dual boot onmy existing XP laptop last night, using a disk that came with 'linux magazine'

The install aparrantly all ran through without any problems, but when the machine restarted on completion, I got the message 'Invalid Bot Sector'

Any suggestions as to how I get the PC working again?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Cesare Tirabassi
Solved:
Last query:
Last reply:
Revision history for this message
Cesare Tirabassi (norsetto) said :
#1

You need to use either the Live CD (to attempt repairing the MBR) or the Win Recovery CD to restore the MBR.
The former is not really difficult, but if you have never done it before the latter is desiderable; the only drawback is that you will loose your linux installation.
If you tell me which way you want to go I can provide detailed instructions.

Revision history for this message
Peter Rye (pr31) said :
#2

Whilst I am new to Linux, I am pretty familiar with computers, so am happy to try the repair so long as it is not too complicated.

If it dosen't work I can presumably always fall back to restoring the windows boot and then attempting the linux install again

Revision history for this message
Cesare Tirabassi (norsetto) said :
#3

Its not very difficult, but you risk to damage even more if not careful. In case of any deviation or things not clear or not working as explained, stop and come back here, ok?
I'll give you 3 choices, have a look at them and try the one which seems more confortable for you.

----------------------------------------------------------------------------------------------------------------------------

First of all, boot from your Live CD, and open a terminal.
Now check with this command what your partitions are:

sudo fdisk -l

From the listing, you must deduce in which partition you have linux installed.

To give you an idea, you should see something like this:

   Device Boot Start End Blocks Id System
/dev/hda1 * 1 2434 19551073+ 7 HPFS/NTFS
/dev/hda2 4867 9486 37110150 83 Linux
/dev/hda3 9487 9732 1975995 82 Linux swap / Solaris

You can see that the first partition is a bootable partition (the star *) and is a win partition (ntfs).
The third is the linux swap, and the second is the linux filesystem.
Now you have to mount the partition which contains the linux filesystem (I will use /dev/hda2 but you have to adapt it to your situation).

sudo mount -t ext3 -o rw /dev/hda2 /mnt

Now your linux partition is mounted at /mnt.

Next you have to use a chroot command to change the root directory:

sudo chroot /mnt

Now to restore the MBR give this command (I assume your drive is hda):

sudo grub-install /dev/hda

You may also want to have a look at your /boot/grub/menu.lst file to check that the entries make sense.

----------------------------------------------------------------------------------------------------------------------------

Alternatively, you can use the grub console.
From the LiveCD give the command sudo grub. Once at the prompt (grub>) give this command:

find /boot/grub/stage1

Now use what is retured by the previous command in this command:

root (hd?,?)

In my example above this would be (hd0,1), hd0 for first HD (hda) and 1 for 2nd partition (they start from 0).

Last, install grub:

setup (hd?)

Here again as in my previous example it will be hd0.

Exit with:

quit

Reboot and .......

----------------------------------------------------------------------------------------------------------------------------

You can also follow the advice of this page:

http://doc.gwos.org/index.php/Restore_Grub

Finally, this link will give you some background and is a useful reference:

http://www.gnu.org/software/grub/manual/html_node/Installing-GRUB-natively.html#Installing-GRUB-natively

Revision history for this message
Peter Rye (pr31) said :
#4

Thanks for the info. When I ran the fdisk command it came up with something a bit different to your example. I think this points to where the problem is, but thought it best to check with you before trying to change anything. My partition table looks like this :-

Disk /dev/hda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/dev/hda1 1 2313 18579141 7 HPFS/NTFS
/dev/hda2 2314 4863 20482875 f W95 Ext'd (LBA)
/dev/hda5 2314 3321 8096728+ 7 HPFS/NTFS
/dev/hda6 4227 4863 5116671 b W95 FAT32
/dev/hda7 * 3322 4181 6907918+ 83 Linux
/dev/hda8 4182 4226 361431 82 Linux swap / Solaris

comparing this with your example, I am guessing that the boot partition should be hda1 not hda7. I can only therefore assume that the install process changed which partition was flagged as bootable, and it needs to be changed back to hda1 for it to work. If this assumption is correct, how do I change the bootable partition?

Revision history for this message
Best Cesare Tirabassi (norsetto) said :
#5

You can use parted. Booting from the LiveCD open a terminal and give this command:

sudo parted

Since you only have one HD it should tell you:

GNU Parted 1.7.1
Using /dev/hda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

You can use these commands (help will list all):

print (it will show you the partitions)
set 1 boot on (it will make partition 1 bootable)
print (again to check it)
quit

reboot and check if problem is solved....

Revision history for this message
Peter Rye (pr31) said :
#6

Cesare

Thanks for your help - all appears to working correctly now.

Peter