Tuesday, December 28, 2010

Repairing GRUB after re-installing Windows XP

GRUB
Though Linux (in this case, Ubuntu) has become our alternative operating system, many people still install Windows together with Linux because Linux is a friendly operating system that allows other operating systems to dual-boot.
It is a common secret that the most re-installed operating system is Windows, especially XP. It is due to any malwares, viruses, worms, etc that often destroy this OS (read: Windows). Although we try to secure the OS using antivirus (i.e. free antivirus) the viruses still stay. So, an easy way to clean is to clean the operating system. To do that we are to have at least two hard-disk partitions, one for system and others for our data so if we reinstall Windows there is no worry about data stored in other partitions.
The problem after re-installing (or maybe re-re-re-re-installing) Windows is that it erases the boot loader to be Windows' while its boot loader can only load Windows operating system. So, our Linux Distro installed before Windows cannot be accessed. But be relax because through simple steps we can get GRUB back and our lovely Linux Distro still exist.
Let's go...
What we need is a LIVE CD (or, if you want, a LIVE USB). I use Ubuntu 8.04 LTS Live CD I got directly from Canonical (thank you Canonical!).
Open a terminal and type (don't type $ or # mark for it is just a mark that differ our privilege to execute some command)
$ sudo su
the command above is used to change our privilege as root
# fdisk -l
It will display some partitions for our hard-disk and may vary. My display is
Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x58e6429e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10241406 7 HPFS/NTFS
/dev/sda2 1276 9696 67641652 f W95 Ext'd (LBA)
/dev/sda5 1276 6374 40957686 7 HPFS/NTFS
/dev/sda6 6375 7649 10241406 83 Linux
/dev/sda7 7650 9434 14337981 83 Linux
/dev/sda8 9435 9696 2104483+ 82 Linux swap / Solaris
Disk /dev/sdb: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xeb31fa71
Device Boot Start End Blocks Id System
/dev/sdb1 2 1276 10241437+ f W95 Ext'd (LBA)
/dev/sdb2 * 1277 30400 233938530 7 HPFS/NTFS
/dev/sdb5 2 1276 10241406 b W95 FAT32
Pay your attention to column "System". In above case, my Linux partition is /dev/sda6, /dev/sda7 and /dev/sda8. I mount a filesystem (/) to /dev/sda6 while /dev/sda7 mounts /home folder. So, in this case and may vary to you I have to reinstall GRUB in /dev/sda6 partition.
Then I type,
# mkdir /media/sda6
The command will create a directory used to mount /dev/sda6 partition so then I type,
# mount /dev/sda6 /media/sda6
And... This is what this tutorial is made to! Type this command
# grub-install --root-directory=/media/sda6 /dev/sda
If everything's OK, you will receive a message "finished and no error reported". Restart your computer and you'll se your GRUB to select your Linux Distro as your favorite operating system.

No comments:

Post a Comment