Reinstall/restore grub bootloader (CentOS, Ubuntu, Fedora)
These is the step to restore it:
- Build a LiveCD boot, or LiveUSB boot
- CentOS here: https://projects.centos.org/trac/livecd/
- Ubunto here: https://help.ubuntu.com/community/LiveCD
- Fedora here: http://fedoraproject.org/wiki/FedoraLiveCD
- Boot from your LiveCD or LiveUSB
- Login to root account
- Mount your current system disk with read/write mode. Some time, liveCD only mount it as readonly.
- Open the terminal (if you booted to GUI mode)
- Once you are at the terminal, you will have to access the ‘grub’ shell to change the grub configuration. So, give this command at the terminal:
- $ grub
- If it says that you don’t have the permission, in which case you will not have logged in as root(as in Ubuntu), give this command at the terminal:
- $ sudo grub
- You will get the grub-shell prompt:
- grub>
- Now, you will have to find out in which partition Grub had been installed before, so that you reinstall in that partition only. Give this command at the terminal:
- grub> find /boot/grub/stage1
(returns value)
- grub> find /boot/grub/stage1
- It returns the number of the partition in which Grub i.e your GNU/Linux had been installed.e.g.:
- grub> find /boot/grub/stage1
- (hd0,2)
Sometimes, when Grub has not been installed properly, the file “/boot/grub/stage1″ may not exist. So, the output will be “Error 15: File not found”. In such a case, come out of the grub-shell by pressing “Ctrl+c”. Then, at the shell prompt, give this command at the terminal:
$ fdisk -l
Again, if you are not logged in as root, give this command at the terminal:
$ sudo fdisk -l
The output will list all the partitions and it’s properties, including the file system type.
e.g.,
Device Boot Start End Blocks Id System /dev/sda1 1 654 5253223+ b W95 FAT32 /dev/sda2 * 655 1962 10506510 7 HPFS/NTFS /dev/sda3 1963 3924 15759765 83 Linux The “System” attribute of your GNU/Linux operating system will be “Linux”. So note down that partition number.
e.g., sda3
Since it’s array numbering, sdaN is mapped to (hd0,N-1).
Just (hd0) will be the Master Boot Record(MBR).
sda1 will be (hd0,0) and so on.
So, sda3 will be (hd0,2)
Now, log into the grub-shell prompt again.
- Before reinstalling Grub, you will have to notify the partition that your Grub i.e. GNU/Linux is resided in. So, give this command at the terminal:
- grub> root (returned value)
- E.g.: root (hd0,2)
- Now, reinstall grub in the MBR i.e. the returned value without number part. (hd0,2) will be become (hd0).
- grub> setup (returned value without number part)
- E.g.: setup (hd0)
- Exit the grub-shell prompt using “Ctrl+c”.
- Exit the shell prompt using “Ctrl+d”.
- Reboot your system.