Software & AppsOperating SystemLinux

How To Recover from Accidentally Deleting /etc/fstab File and Not Being Able to Boot in Ubuntu

Ubuntu 6

If you’ve accidentally deleted the /etc/fstab file in your Ubuntu system, you might find yourself unable to boot your operating system. This can be a daunting situation, particularly if you’re not familiar with the inner workings of Ubuntu. However, don’t panic. In this article, we’ll guide you through the process of recovery in a step-by-step manner.

Quick Answer

To recover from accidentally deleting the /etc/fstab file and not being able to boot in Ubuntu, you can either recreate the file via Recovery mode or using an Ubuntu live disk. In both methods, you will need to identify the root partition, mount it, and recreate the fstab file with the appropriate UUID. After successfully booting into your Ubuntu OS, remember to add an fstab entry for your swap partition.

Understanding /etc/fstab

Before we dive into the recovery process, it’s important to understand what the /etc/fstab file is. The fstab file, located in the /etc directory, is a crucial system configuration file in Ubuntu. It contains information about the filesystems on the system, including the mount points, filesystem types, mount options, and more. When this file is deleted, the system cannot mount the necessary filesystems during boot, leading to boot failure.

Method 1: Recreating /etc/fstab via Recovery mode

Step 1: Boot into Recovery mode

First, restart your computer and hold down the Shift key during startup to enter the GRUB boot menu. Select the Advanced options for Ubuntu option, then select the Recovery mode option for your kernel version.

Step 2: Drop to the root shell

In the Recovery Menu, select the root option to drop to a root shell prompt.

Step 3: Identify the root partition

Run the command sudo blkid to display the UUIDs of all partitions. The UUID (Universally Unique Identifier) is a string that uniquely identifies each partition. Identify the UUID of your root partition, typically labeled as /dev/sda1 or similar.

sudo blkid

Step 4: Mount the root partition

Mount your root partition in read-write mode using the command below. Replace sdaX with the appropriate device ID of your root partition.

mount -t ext4 -o rw,remount /dev/sdaX /

Step 5: Recreate the fstab file

Create a new fstab file inside /etc with the following command. Replace <your-root-partition-UUID> with the UUID you obtained from sudo blkid.

echo "UUID=<your-root-partition-UUID> / ext4 errors=remount-ro 0 1" > /etc/fstab

Step 6: Reboot your system

Exit the root shell and reboot your Ubuntu OS.

Method 2: Recreating /etc/fstab via Ubuntu live disk

If you’re unable to boot into Recovery mode, you can use an Ubuntu live disk to recreate the fstab file.

Step 1: Boot from Ubuntu live disk

Insert your Ubuntu live disk (or USB) and boot from it. Select the Try Ubuntu option to start a live session.

Step 2: Identify the root partition

Open a terminal and run sudo blkid to find the UUID of your installed Ubuntu partition.

sudo blkid

Step 3: Mount the root partition

Create a mount point and mount your root partition to it. Replace sdaX with the appropriate device ID of your root partition.

sudo mkdir /media/ubuntu
sudo mount /dev/sdaX /media/ubuntu

Step 4: Recreate the fstab file

Navigate to /media/ubuntu/etc using the file manager and create a new fstab file. Add an entry for your root partition using the format below. Replace <your-root-partition-UUID> with the UUID you obtained from sudo blkid.

UUID=<your-root-partition-UUID> / ext4 errors=remount-ro 0 1

Step 5: Reboot into your installed Ubuntu OS

Save the fstab file and reboot into your installed Ubuntu OS.

Final Thoughts

After successful booting into your Ubuntu OS, don’t forget to add an fstab entry for your swap partition. If you’re unsure about any step in this process, it’s always a good idea to consult with a professional or seek help from the Ubuntu community.

Remember, it’s crucial to regularly back up your important data, including system files like /etc/fstab, to prevent loss of data due to accidental deletion or system failure.

What should I do if I accidentally delete the `/etc/fstab` file in Ubuntu?

If you accidentally delete the /etc/fstab file in Ubuntu, you can recover by either using the Recovery mode or an Ubuntu live disk. The recovery process involves recreating the fstab file and rebooting your system.

How do I boot into Recovery mode in Ubuntu?

To boot into Recovery mode in Ubuntu, restart your computer and hold down the Shift key during startup to enter the GRUB boot menu. From there, select the Advanced options for Ubuntu option, then choose the Recovery mode option for your kernel version.

How do I find the UUID of my root partition?

You can find the UUID of your root partition by running the command sudo blkid in either the Recovery mode root shell or the Ubuntu live disk terminal. The UUID will be displayed as a string that uniquely identifies each partition.

Can I use any text editor to recreate the `fstab` file?

Yes, you can use any text editor to recreate the fstab file. In the Recovery mode root shell, you can use the nano editor by running the command nano /etc/fstab. In the Ubuntu live disk, you can use the default text editor, which is typically gedit.

Do I need to add an `fstab` entry for my swap partition?

Yes, after successfully booting into your Ubuntu OS, it is recommended to add an fstab entry for your swap partition. This ensures that your swap partition is properly mounted during boot. You can find the UUID of your swap partition by running the command sudo blkid and add the entry in the same format as the root partition entry.

Leave a Comment

Your email address will not be published. Required fields are marked *