Accidentally deleted /etc/fstab file

You have to recreate a new fstab file inside /etc directory and add an entry for your root partition, so that your Ubuntu os will boot.

Method 1:

Recreating /etc/fstab file via Recovery mode

  1. Boot into Recovery mode and then drop to root shell.

  2. Run sudo blkid command to know the UUID of your /(root) partition.It will show something like this,

    /dev/sda1: UUID="52e062e0-716c-4828-9bf1-05b93fdaef93" TYPE="ext4"
    /dev/sda1: UUID="2F4DAFCF02D7EBEB" TYPE="ntfs" 
    /dev/sda3: UUID="039E0CF305398945" TYPE="ntfs" 
    /dev/sda5: UUID="C68C57908C5779BF" TYPE="ntfs" 
    
  3. From the sudo blkid output, identify your root ext4 partition and note down its corresponding UUID.

  4. Now mount your / partition in Read Write Mode by running the below command.Please note that the simple mount / command for mounting your root partition won't work because of the deletion of /etc/fstab. So, if your / was /dev/sda1, run this command:

    mount -t ext4 -o rw,remount /dev/sda1 /
    
  5. The above command will mount your / partition in read write mode.Run the below command to create a new fstab file inside /etc with the appropriate line to mount your /. In the example above, my / has UUID=52e062e0-716c-4828-9bf1-05b93fdaef93, so I would run:

    echo "UUID=52e062e0-716c-4828-9bf1-05b93fdaef93 / ext4 errors=remount-ro 0 1" > /etc/fstab
    
  6. Exit from the root shell and boot your Ubuntu OS, it will surely bootup.

Method 2

Recreating /etc/fstab file via Ubuntu live disk

  1. Boot ubuntu live disk.

  2. Run sudo blkid command and note the installed Ubuntu partition's device id and the UUID.

  3. Mount your root partition,

     sudo mkdir /media/ubuntu
     sudo mount /dev/sdaX /media/ubuntu
    
  4. Now go into the /media/ubuntu via nautilus and create a fstab file inside /etc.

  5. On that fstab file, add an entry for your root partition like below.

     UUID=52e062e0-716c-4828-9bf1-05b93fdaef93 / ext4 errors=remount-ro 0 1
    
  6. Save that file.And boot into your installed Ubuntu.

Note: My root partition's UUID was given above.Please give your's.After booting into your installed Ubuntu OS, don't forget to add fstab entry for your swap partition.