«

»

Nov 26

Lost dual boot option and need to reinstall grub

The steps in this post are applicable to be done in distributions like Redhat, Centos and Fedora.

Recently I met with an issue like my personal desktop has lost its Dual Boot option at the startup. The machine has been working by having both Windows XP and Centos present in it. The dual boot option has been lost ever since I reinstalled Windows XP. I was not able to choose Centos at the startup from then, and the machine was automatically booting to Windows XP once I power on the CPU. It was pretty sure that I would probably need to reinstall grub in Centos to bring back the Dual Boot option.

Here you go with the steps I tried to reinstall grub in Centos.

Put in the installation CD you used to install Centos in your machine.
(Before that log into BIOS and set CD/DVD Drive in first place of Boot Priority list)

– Press F10(Save your BIOS change and exit inorder to reboot) and on the reboot cycle, machine would load your Centos disk. That means your Centos disk should be present prior to the booting of machine, otherwise it would try to load the from Harddrive.
– Select “Rescue installed system”.
– Select “Local CDDVD” for the Rescue Method.
– On the “Rescue Screen”, select “Continue”.
– On the next menu screen, select “shell Start shell”.
– I got the shell as “bash-4.1#” successfully.
– Then I tried to run “chroot /mnt/sysimage” and hit the following error.

=====================
chroot: failed to run command `/bin/bash’: No such file or directory
=====================

The above error indicates that either you have put in a different architecture CD that doesn’t match the one installed in your machine. Mine is Centos 6.4 i686 and I was using the same disk used to installed it, so that wasn’t issue here.

Finally I found “chroot /mnt/sysimage” was not working and not shifting me into chroot environment, because “/” and “/boot” partitions were not mounting as well. I had to proceed with manual steps in the following way.

My fdisk -l result is

bash-4.1# fdisk -l
omitting empty partition (5)

Disk /dev/sda: 80.0GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x332cf22a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 7 HPFS/NTFS
/dev/sda2 2551 9728 57657285 f W95 Ext’d (LBA)
/dev/sda3 5738 9728 32057676 7 HPFS/NTFS
/dev/sda5 2551 2576 204800 83 Linux
/dev/sda6 2576 5476 23294976 83 Linux
/dev/sda7 5476 5737 2096128 82 Linux swap / Solaris

/dev/sda6 is my “/” partition and “/dev/sda5” is the “/boot” partition.

I mounted “/” and “/boot” partitions manually and chrooted it.

bash-4.1# mkdir /mnt/ROOT
bash-4.1# mount -t ext4 /dev/sda6 /mnt/ROOT
bash-4.1# mount -t ext4 /dev/sda5 /mnt/ROOT/boot

bash-4.1# chroot /mnt/ROOT
you will be switched to chroot environment >> sh-4.1#

sh-4.1#

I tried to run fdisk -l , but got the below error:

sh-4.1# fdisk -l
cannot open /proc/partitions
sh-4.1#

I exit from the chroot and mounted /proc and /dev using bind method.

sh-4.1# exit
bash-4.1# mount -o bind /proc /mnt/ROOT/proc
bash-4.1# mount -o bind /dev /mnt/ROOT/dev

chroot again

bash-4.1# chroot /mnt/ROOT
sh-4.1# fdisk -l
omitting empty partition (5)

Disk /dev/sda: 80.0GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x332cf22a

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2550 20482843+ 7 HPFS/NTFS
/dev/sda2 2551 9728 57657285 f W95 Ext’d (LBA)
/dev/sda3 5738 9728 32057676 7 HPFS/NTFS
/dev/sda5 2551 2576 204800 83 Linux
/dev/sda6 2576 5476 23294976 83 Linux
/dev/sda7 5476 5737 2096128 82 Linux swap / Solaris
sh-4.1#
sh-4.1#

Now install grub

sh-4.1# grub-install /dev/sda
The file /boot/grub/stage1 not read correctly.

Made me crazy again 🙂
and did it manually from grub prompt.

sh-4.1# grub
Probing devices to guess BIOS drives. This may take a long time.

GNU GRUB version 0.97 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> find /boot/grub/stage1
(hd0,5)

grub> root (hd0,5)
Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
Checking if “/boot/grub/stage1” exists… yes
Checking if “/boot/grub/stage2” exists… yes
Checking if “/boot/grub/e2fs_stage1_5” exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 15 sectors are embedded.
succeeded
Running “install /boot/grub/stage1 (hd0) (hd0)1+15 p
(hd0,5)/boot/grub/stage2
/boot/grub/grub.conf”… succeeded
Done.

grub> quit

Make corrections to (hd0,5) in the file /etc/grub.conf or /boot/grub/grub.conf and this is MANDATORY.

sh-4.1# exit
bash-4.1# reboot

Issue has been fixed 🙂

1

2

 

 

 

 

 

 

 

This can also be done using a Live CD with same OS and architecture.

– Boot to CD/DVD Drive
– Select “Rescue Installed System”

You will be shifting to Live CD environment

[root@livecd ~]#

just mount the /boot partition and install grub like as follows:

[root@livecd ~]# mkdir /oldboot
[root@livecd ~]# mount /dev/sda5 /oldboot (/dev/sda5 is my /boot partition here)
[root@livecd ~]#
[root@livecd ~]# grub-install –root-directory=/oldboot /dev/sda
Installation finished. No error reported.
This is the contents of the device map /oldboot/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install’.

# this device map was generated by anaconda

(fd0) /dev/fd0
(hd0) /dev/sda

3

 

 

 

 

You are done 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>