Recovering Linux after Re-installing Windows

Recovering Linux after Re-installing WindowsDual-booting is a technique used in order install two working Operating Systems in your computer. Multi-booting on the other hand refers to installing two or more OS. This is pretty useful when you have certain work requirements that can't be done in one OS and it can be only done on the other. Say for example, you are using primarily Linux Operating System but in your line of work, you are required to create a sample client application in CSharp. So you need to have a computer that runs on Windows OS to code your CSharp application. Or, let's just say you want to experience or experiment on using other Operating Systems. So you want to have access to computers running on FreeBSD, OpenBSD, Cent OS, Fedora, Ubuntu, Windows. Etc. Learning how to Dual-boot or Multi-boot saves you from installing different Operating Systems on different computers. What you only need is one computer with large storage capacity that can accommodate those different OS types and flavors.

Dual-booting Ubuntu Linux and Windows

The number one rule in dual-booting Linux and Windows is to install the Windows OS first. Why? Because Windows does not support multi-booting with different OS types. With Windows installed first in a certain partion of your Hard Drive, you can then install Linux on the empty partition without having problems. Linux comes with a very useful program called Boot Manager or Boot Loader. In the case of Ubuntu Linux, the Boot Loader program is called GRUB or GNU GRUB (GNU GRand Unified Bootloader).

When you turn on your computer, the Boot Loader will let you select which Operating System you would like to run, either Linux or Windows.

Reinstalling Windows in a Dual-boot Machine

In my case, I have a second hand Lenovo Y410 laptop that was dual-boot with Microsoft Windows Vista and Ubuntu Linux 11.04. I have no problem with the Ubuntu Linux already but with Microsoft Windows Vista, I just want to make sure its virus free. And so I delete the old Vista and installed a new one. (I tried Windows 7 but I got no luck in finding drivers for Lenovo Y410 so I went back to Vista).

After I successfully installed Windows Vista, the Boot Loader of Ubuntu Linux was erased and overwriten. If I turn on the machine, I am not given anymore the choice to boot with Ubuntu. The following are steps I did in order to re-install the GRUB boot loader of Ubuntu:

Steps in Recovering Linux after Re-installing Windows

  1. Boot with an Ubuntu LiveCD of the same version and architecture with the one that is currently installed.
  2. From the Ubuntu LiveCD GUI, run a Terminal console.
  3. From the Terminal console, check and determine what partition in your Hard Disk is your Linux and which one is contains the Windows
    # sudo fdisk -l
  4. Mount the Linux root partition:
    # sudo mount /dev/sdXX /mnt

    XX can be a0, a1, a2... or b0, b1, b2... or d0, d1, d2... etc.
    If you have a separate boot partition in your Linux, mount also this partition:
    # sudo mount /dev/sdYY /mnt/boot

  5. Mount some important virtual filesystems.
    # for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  6. From the LiveCD terminal, Chroot into your mounted Linux machine.
    # sudo chroot /mnt
  7. Recreate the GRUB configuration file.
    # update-grub
  8. Reinstall GRUB.
    # grub-install /dev/sdX

    Important Note: Do not specify the partition number.

  9. Exit from Chroot: CTRL-D on keyboard
  10. Unmount the virtual filesystems.
    # for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done

    Note: If you have mounted a separate boot partition in Step 4, unmount it also:
    # sudo umount /mnt/boot

  11. Unmount your Linux root partition.
    # sudo umount /mnt
  12. Reboot your computer.
    # sudo reboot

Now after following these steps, you must have fully recovered already your Ubuntu Linux. Try booting with your Ubuntu Linux first then check also if you can still boot with your Windows OS.

Thanks for the useful article

Thanks for the useful article you provided. However, I thought that maybe someone can help me – last night my laptop got infected by “redirect virus”. The only solution I found is Google redirect virus removal, but it’s not free. I’m really confused, because my windows 7 gets so many viruses daily and I don’t have a reliable antivirus. Maybe I should change my OS to Linux instead? Is it a good choice?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.