Tuesday, 23 September 2014

What to do when you have deleted /etc/fstab file from Linux and rebooted the server?

/etc/fstab is one of the most critical file in the Linux system. It contains the filesystem tables and information of the mount points. We need this file information at the time of reboot. Partition information is required to mount / partition and other partition table. When this is deleted or missed, our PC will definitely ran into some problem. But we can rather save our PC, if we miss our file.

This blog will tell how to recover from a missing /etc/fstab file.

When you rebooted the server without the /etc/fstab file, we will get some error on the screen on the booting time. But it is important to debug if it is really a fstab error or something else.
For this we have to know the boot process also. As we know that the fstab information is required by the kernel at the time of the reboot. So you will see BIOS is loading, MBR is loading and then GrUB loaded successfully but after that at the time of kernel starting the services, we will ran to an error screen.

Read the error carefully, as the error itself gives the detailed description of the problem. It will say, filesystem table is missing or /etc/fstab not found etc.

At this stage, you know that the error is related to the filesystem table.

This problem can be resolved by a number of ways. We will discuss them one by one.

1. By creating the required file in single user mode.
2. By booting the system in rescue mode and then creating the file.

1. Using single user mode.

1. Reboot the server.
2. Press e when kernel listing is there on the grub screen, add 1 to the kernel parameters to boot the system in single user mode.
3. When the server boots into single user mode, check the UUID using command, blkid as shown in the snapshot.
# blkid
4. Now try to create the file /etc/fstab using vi. But you will not be able to create the file as the server is mounted in the read only mode. So remount the server in rw mode again.
# mount -o loop rw,remount /dev/sda2 /
5. Now create file /etc/fstab and write all the mount points required to boot the server.

6. Unmount the / again and reboot the server. The server will surely boot and come up.

2. Using Rescue Mode.

1. Reboot the server using a rescue CD or bootable media.
2. When menu appears for installation from CD, select from menu the rescue the previous installation.
3. Follow the instruction and it will finally give a command prompt.
4. Try mounting the / partition on /tmp or /mnt of your server in read write mode using above method.
5. After that follow the same above procedure and create /etc/fstab file on the server. If we don't want to go in all this mess, you can also copy the file /proc/mounts to /etc/fstab.
# cat /proc/mounts > /etc/fstab
6. This option will let you reboot the server next time, but your filesystem may or may not be mounted at this time. So after rebooting the server you can mannually add the partition information and then reboot the server.

No comments:

Post a Comment