Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which is the best way to fix broken fstab? I think that i could do that with some live linux distro. First serch for partitions and mount them to temporary created /temproot. Manually mount partitions that you recognized one by one into newly created /temproot. very important is to wacth on righ filesystem of each partition and swap partition. After that using command chroot fix to the original root. Does someone knows better way - any suggestion is welcome?

share|improve this question
It depends on how badly it is broken. If the entry for the root file-system is still valid, then you should be able to reboot into rescue mode. – Zoredache Jan 17 '12 at 21:35
@Zoredache after booting system with live cd i found partitions. Now i need next proper step -as i described earlier or there is a better way? – mdakic Jan 17 '12 at 22:35
I guess, I don't understand what is broken. Most of the time, people just add an invalid line for a new mount. The answer is to remove that line. If you have completely trashed your fstab, then I would restore the copy from your backup. If you have no backup, and a completely trashed fstab, then you have a lot of detective work to do. – Zoredache Jan 17 '12 at 22:41
up vote 1 down vote accepted

Once you have booted the live CD, you will first need to identify the partitions as you suggest.

Using parted will provide a couple of clues:

# parted /dev/sdc P

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  2155MB  2154MB  primary   linux-swap(v1)
 4      2155MB  212GB   209GB   extended
 5      2156MB  3230MB  1074MB  logical   ext3
 6      3231MB  5378MB  2147MB  logical
 7      5379MB  48.3GB  42.9GB  logical   ext4
 2      212GB   319GB   107GB   primary   ext4
 3      319GB   320GB   1080MB  primary   ext3            boot

Here we can see that sdc1 is swap - so that is easy.

Note that the sdc3 has the boot flag enabled, so that is most likely the boot partition (the flag marks it as a bootable partition, but it isn't necessarily the /boot partition). Boot partitions are generally small as they don't need to contain much. In this case, the other likely candidate /dev/sdc5 is the real boot

If we mount that,

$ mount /dev/sdc5 /mnt
$ grep root /mnt/grub/grub.cfg
set root='(hd2,5)'
linux   /vmlinuz-2.6.32-5-xen-amd64 root=UUID=5d41ba76-8261-41cd-b147-1f034833f0a1 ro  quiet

If your grub.cfg (or menu.lst) is using device names, then you'll know which is root - however in this case, we are using UUID, so we need to identify the device:

ls -l /dev/disk/by-uuid/5d41ba76-8261-41cd-b147-1f034833f0a1
lrwxrwxrwx 1 root root 10 Jan 18 08:45 /dev/disk/by-uuid/5d41ba76-8261-41cd-b147-1f034833f0a1 -> ../../sdc7

So now we know that the root partition is /dev/sdc7

Mounting the others in turn as suggested will help you identify the remaining partitions. There is no need to chroot into the environment, you can just edit fstab directly:

mount /dev/sdc7 /mnt
vi /mnt/etc/fstab

And recreate the entries.

Note that the /etc/mtab file gets created as partitions are mounted. This might still be intact if you havn't been able to boot since the fstab broke, so you might be able to look in /etc/mtab and recover the mount information from there. You can usually copy lines as they are in mtab directly into fstab.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .