Monday, February 27, 2012

Recover Dual boot after windows reinstallation

As everyone knows, when you reinstall Windows you lose boot of Linux, be it Grub or Lilo. This is because Windows writes a new table in the MBR and Microsoft simply ignores the presence of Linux (so it forces the user to give Linux). But today let's ignore Microsoft and recover Linux after installing Windows.

1) start the machine with a live cd either. If you choose a live cd as Kurumin, Ubuntu, Dreamlinux and others, will open a graphical environment that can be Gnome, KDE, XFCE, Ximian among others.

2) press Ctrl + Alt + F2 to go to the shell - as a live cd, it will be as super-user. Basically we do the following: mount your root partition, change the root to this directory and reinstall lilo or grub.

3) create a directory to mount its root:

# Cd / mnt
# Mkdir root


4) mount your root partition, I'll use the default of most machines dual boot here, where: sda1 (sda1) = Windows
hda2 (sda2) = SWAP
hda3 (sda3) = EXT3, ReiserFS, XFS, AMONG OTHERS (ROOT)


Note: We will rely on a ext3 partition, but can be any type of partition for root.

5) we mount root:

# Mount-t ext3 / dev/hda3 / mnt / root

6) we will change the root directory of the live cd to the directory that we set:

# Chroot / mnt / root

Okay, your prompt changes at this time. If you give a cd / always goes to / mnt / root, but appears as /. At this time you're on your Linux. All configuration files are now the Linux on your machine and no longer the livecd.

7) Now let's reconfigure grub and / or lilo. To reconfigure lilo just type:

# lilo

Ready: The lilo will now open the next time you restart!

8) to grub should do the following:

# Grub-install hd0

Where: = hd0 hda
hd1 = hdb

or:

# Grub-install / dev / hda

This variation on the grub command will depend on the version installed on the system, the most accept the two new commands and so on.

Okay, now grub will open at the restart type:

# exit

to return to the root directory of livecd type:

# Umount / mnt / root

to unmount the partition and restart the machine. Get the livecd and voila! Already have the option to choose to boot Windows or Linux.

If your previous installation had only Linux, it will give the option of opening only Linux. Do not despair, the Grub edit / boot / grub / menu.lst:

$ Sudo kate / boot / grub / menu.lst

Change kate by your favorite editor (vi, ... mcedit). If you're using a distro that does not use sudo, do the command as follows:

$ Su-c 'vi / boot / grub / menu.lst "

But graphics editors will not work, so only the text as vi, vim, mcedit. At the end of the file add the following line:
title         Windows 95/98/NT/2000/XP/Vista
root          (hd0,0)
makeactive
chainloader   +1


Where: Title = a label that will appear
root = hd and partition (hd0 = hda, hda1 = 0)
makeactive = mark as active (only for non-Linux partitions)
chainloader +1 = boot  rule (always keep +1 for Windows)

Save the file and exit. Okay, just restart.

If you are using lilo, edit / etc / lilo.conf and add at end of file the following lines:

other = /dev/hda1
label = "Windows95/98/NT/2000/XP/Vista(hda1)"

Where: other = partition that should be initiated;
label = name that will appear.

Save the file and exit. Now enter the command:

# lilo

This command will write the MBR lilo again. Remember, other than grub, lilo must be written in the MBR whenever you have changes to lilo.conf. Okay, just restart.

1 comment:

Anonymous said...

i can't do grub-install hd0