A couple of days back I had faced a problem on one of the Linux Server. I rebooted the server for some task & the server didn’t came up for a long time. When I checked from the console, I found the grub command line screen. I knew that the grub has been corrupted.
I had two options to boot up the server and fix the grub.
1. Boot from the rescue CD and install the grub loader.2. Use the grub commands to boot the server and then install grub.
I was not having any Linux bootable CD when I faced this problem, hence I had only one option i.e. to boot the server from grub command line and install grub loaded. Fortunately the root file system was clean hence I was able to start the server from grub command prompt but it may not be the case always. Sometimes, there could be inconsistencies with the root file system and the system can be started only after fixing the inconstancies by executing fsck which requires the server to be started in rescue mode. Hence I thought of explaining both the methods here.
Method 1.
- Boot the server in Rescue Mode (For details, please refer my previous article – Linux Rescue Mode )
- Select the option to search and mount the previous system @ /mnt/sysimage
- Execute /sbin/grub-install to install grub boot loader.
[root@VCSNode2 ~]#/sbin/grub-install /dev/sda
Installation finished. No error reported.This is the contents of the device map /boot/grub/device.map.Check if this is correct or not. If any of the lines is incorrect,fix it and re-run the script `grub-install’.
# this device map was generated by anaconda(hd0) /dev/sda
[root@VCSNode2 ~]#
Method 2
1. Execute the following command on the grub command prompt.
grub> find /boot/grub/stage1
(hd0,0)
grub>
2. If you get the partition information where the file is located, that means you have created a separate /boot and separate / partition. Now execute the following command to get the root file system information.
grub> find /etc/hosts(hd0,1)grub>
3. If you get “File not found” error in step 1 above (as shown below), that means you have not created a separate /boot file system.
grub> find /boot/grub/stage1 // “File Not Found Error Output afterError 15: File not found //executing find /boot/grub/stage1 command at grub promptgrub>
4. Now execute the following command. In this case, your operating system (boot as well as root partition) is on hard disk 0, partition 1 i.e. hda1/sda1.
grub> find /grub/stage1(hd0,0)grub>
5. Now execute the following commands to boot your operating system.
grub> root (hd0,0) //device information you received after executingFilesystem type is ext2fs, partition type 0×83 //find “/boot/grub/stage1? or “find /grub/stage1: command.
grub> kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/hda1 //device information you received after executing “find /etc/hosts” command.[Linux-bzImage, setup=0x1e00, size=0x1ad054] // Please note, if you get device information as (hd0,0) then the device name in this case would be /dev/hda1grub> boot
6. This would start the operating system. Once operating system is loaded execute the following command to install grub boot loader.
[root@VCSNode2 ~]# /sbin/grub-install /dev/sda
Installation finished. No error reported.This is the contents of the device map /boot/grub/device.map.Check if this is correct or not. If any of the lines is incorrect,fix it and re-run the script `grub-install’.
# this device map was generated by anaconda(hd0) /dev/sda
[root@VCSNode2 ~]#