1

I suck at life and accidentally overwrote my fstab before making a backup by trying to

chmod 777 /etc/fstab

so I could edit and resave it via a text editor.

So my question is, since most of these settings are used at boot to set up various things like swap and such, is there a way to determine what was in my previous fstab as long as I haven't restarted my server?

I've thrown a backup of a default in there, but I need this as apparently there were some customized things in the lost fstab file.

Cheers.

Rooster
  • 485
  • 2
  • 7
  • 21

2 Answers2

6

Look at your /etc/mtab, /proc/swaps files and look at the output of mount. This should give you enough information to re-construct your fstab.

Zoredache
  • 128,755
  • 40
  • 271
  • 413
1

To add to the above answer (which is valid):

If your system happens to be using LVM snapshots, then you can mount the snapshot volume and recover the file from there.

If you merely deleted the file, rather than overwriting it, you can recover the text contents of the file as follows:

  1. shut down to single user
  2. grep on a known mount point (such as the boot partition sda1) on the partition that /etc/fstab resides: grep -a -B30 -A30 -i sda1 /dev/sda2

This greps for text string "sda1" on all data on the /dev/sda2 partition, and grabs 30 lines of text before and after, as well, which should be sufficient to cover a normal sized /etc/fstab.

Michael Martinez
  • 2,543
  • 3
  • 20
  • 31