Ubuntu – the purpose of listing the rootfs in /etc/fstab

buildrootfstabroot-filesystemUbuntu

In BuildRoot 2015.08.1 /etc/fstab contains the following line.

/dev/root / ext2 rw,noauto 0 1

On my encrypted Ubuntu laptop /etc/fstab contains the following line.

/dev/mapper/ubuntu--vg-root / ext4 errors=remount-ro 0 1

Question: What is the purpose of listing the rootfs in /etc/fstab?

Not the answer:

  • The kernel mounts the rootfs read-only from the root= parameter or in initramfs. So /etc/fstab does not help mounting the rootfs read-only.

  • The init process remounts the rootfs read-write. This is done in /etc/inittab in BuildRoot, and /etc/rcS.d/S06checkroot.sh in Ubuntu. So /etc/fstab does not help remounting the rootfs read-write.

Background: I am building an embedded system with a fancy initramfs. It looks for different rootfs candidates on the network and locally until it finds a suitable one. It takes care of checking the filesystem and remounting it read-write before calling switch_root.

Bonus question: What would be the impact of not listing the rootfs in /etc/fstab?

It would be awesome if there was none. I don't want to maintain a different /etc/fstab for each rootfs. But then why would BuildRoot and Ubuntu keep it?

Spoiler: I tried and it seems to work, but I am wary of hidden consequences.

Best Answer

The options in fstab are supposed to be used to remount it, applying the options specified ( which may NOT include rw access ). A boot script that is hard coded to remount the root fs with rw without consulting fstab is broken. Thus, the only result of leaving it out of fstab is that it won't be remounted, and will remain ro with no other options applied.

Related Question