Reinstall/restore grub bootloader (CentOS, Ubuntu, Fedora)

Ngày 29 tháng 8 năm 2012 Trương Chương Dương
If you lose the bootloader after resize partition (I lose after resize with Partedmagic), or install windows and cannot boot to Linux. In this case, grub might have to be reinstalled.

These is the step to restore it:
  1. Build a LiveCD boot, or LiveUSB boot
    1. CentOS here:
    2. Ubunto here:
    3. Fedora here:
  2. Boot from your LiveCD or LiveUSB
  3. Login to root account
  4. Mount your current system disk with read/write mode. Some time, liveCD only mount it as readonly.
  5. Open the terminal (if you booted to GUI mode)
  6. 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
  7. 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
  8. You will get the grub-shell prompt:
    • grub>
  9. 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)

  10. 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.


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.

  1. 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)
  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)
  3. Exit the grub-shell prompt using “Ctrl+c”.
  4. Exit the shell prompt using “Ctrl+d”.
  5. Reboot your system.
Đang tải dữ liệu...
web site traffic statistics