Tuesday, June 8, 2010

Grub 2 after reinstalling Windows XP/Vista/Win7

Using Ubuntu 9.10 livecd or higher
Here assuming the Ubuntu partition is sda7,and /boot partition is sda6 (if you have a separate /boot partition).
Boot up ubuntu from the livecd,open terminal and run:
sudo -i
mount /dev/sda7 /mnt
mount /dev/sda6 /mnt/boot  #skip this one if not have a separate /boot partition
grub-install --root-directory=/mnt/ /dev/sda

If you miss “grub.cfg” file,use following to recreate:
mount --bind /proc /mnt/proc
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
chroot /mnt update-grub
umount /mnt/sys
umount /mnt/dev
umount /mnt/proc
exit

Using the cd/usb boot up with grub
open the Terminal 
Boot up the grub menu.Type:
grub>find /boot/grub/core.img
grub>root (hdx,y)   (previous command will output the x,y)
grub>kernel /boot/grub/core.img
grub>boot
 
After the boot command,you’ll go into grub2 menu.Select to boot up ubuntu,and run this command to restore grub:
sudo grub-install /dev/sda

No comments:

Post a Comment