GRUB 2 Restore after Windows (re)installation
Scenario: Multiple OS in one machine – Linux Grub2 Boot Loader doesn’t start after Windows (re) installation. A selfish Windows OS starts automatically by default. It happens when installing Linux and Windows. This can be easily avoided by installing multiple operating systems in the following order; first Windows then Linux.
Example of existing disk partitions:
/sda1 ntfs Windows 7 (here, Windows installer set up the Boot flag to active)
/sda2 ext3 Ubuntu ( bootloader’s home partition and the Boot flag has been unset)
/sda3 ext3 home
/sda4 ext3 ….
/sda5 ntfs data/whatever
Requirements:
– A patient – Computer with multiple OS’s and the bootloader broken by the Windows installer.
– Ubuntu LiveCD (installation CD) or
– A light GParted Live CD/USB/HD/PXE – gparted-live-xxx.iso ~121.4 MB (recommended)
– Mind the OS architecture! Don’t run 32 bit live cd against 64 bit operating system.
Solution: GRUB-2 Boot Loader has been restored by applying the following remedy:
UPDATE
I tried and it did not work against Windows 7 installation! It looks like windows installer don’t care and takes it all, writing its own rubbish into a MBR sector. To fix this OS disaster do the following:
Run script:
$sudo fdisk -l Device Boot Start End Blocks Id System /dev/sda1 1 1244 9990144 83 Linux /dev/sda2 1244 1306 492545 5 Extended /dev/sda3 1244 1306 492544 82 Linux swap / Solaris /dev/sda4 * 8370 13995 45190845 69 HPFS/NTFS #mount existing Linux installation file system (sda1): $sudo mount /dev/sda1 /mnt $sudo mount --bind /dev /mnt/dev $sudo mount --bind /proc /mnt/proc # chroot into the environment: $sudo chroot /mnt #reinstall Grub2 : $ sudo grub-install /dev/sda Installation finished. No error reported.
Reboot computer, grub menu should start now.
In case that Windows 7 menu entry is missing do the follwoing to add windows 7 to the grub2 menu list:
Script:
# create and fill up 11_Windows configuration file $ sudo vi /etc/grub.d/11_Windows # next add the following lines: #! /bin/sh -e echo "Adding Windows" >&2 cat << EOF menuentry "Windows 7" { set root=(hd0,4) chainloader +1 } EOF
Save and exit :wq vi editor, this will create a new file.
Mind the fact if the Windows was installed on fourth partition (like in example above) we need to give root=(hd0,4).
GRUB2 recognizes partitions in the following way:
First partition (/dev/sda1): root=(hd0,1)
2nd partition (/dev/sda2): root=(hd0,2), and so on…
# next grand execute permission to a file: $ sudo chmod a+x /etc/grub.d/11_Windows # issue the following command to refresh Grub2 configuration: $ sudo update-grub
Reboot computer.
Cheers!!
By continuing to use the site, you agree to the use of cookies. more information
The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.