Wednesday, 26 October 2011

Ubuntu Dual Boot

Feeling lost while seeing a black grub screen, you're not alone. Grab the latest Ubuntu iso, The first thing you're going to do is that you will need a Ubuntu LIVE CD which ever version you have. The best thing to do is to install  Windows first, because if you install it afterwards, the windows boot manager wipes out grub and thinks that it is the only OS on the computer. But still if you have installed Ubuntu first and want Windows aftewards, you have to follow this procedure.

Enter the LIVE CD, and press Alt+F2, type in  gnome-terminal, then give the following commands:
        $sudo fdisk -l
        This will print your partition table. Here is mine - for a better  understanding:
              /dev/sda1 29 8369 66999082+ 83 Linux
              /dev/sda2 * 8370 13995 45190845 7 HPFS/NTFS
              /dev/sda3 13996 14593 4803435 5 Extended
              /dev/sda5 13996 14593 4803403+ 82 Linux swap / Solaris

          Now, we will mount Linux (sda1 here). I have NO external boot partition as you can see. (if you have an external one, DO NOT forget mounting it)
                $sudo mount /dev/sda1 /mnt
                $sudo mount --bind /dev /mnt/dev
                $sudo mount --bind /proc /mnt/proc
            The following command is optional, as it copies the file "resolv.conf "
                  $sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
                Now chroot into the newly made environment:
                      $sudo chroot /mnt
                    After chrooting, you do not need to add sudo before your commands; as you'll be running everything as root by default. 

                    You may want to edit /etc/default/grub file to fit your system (timeout options etc)
                          $nano -w /etc/default/grub
                        Play with the options if you want, (but do not forget to give grub-update command after saving)

                        Now recover Grub2 via:
                              $grub-install /dev/sda
                            If you run into errors with the above code like me, use this command:
                                  $grub-install --recheck /dev/sda
                                You may exit chroot, umount the system and reboot your system:
                                      $sudo umount /mnt/dev
                                      $sudo umount /mnt/proc
                                      $sudo umount /mnt
                                      $sudo reboot
                                  That's all, you're done! Enjoy :