Remounting a Read-Only Partition With a Faulty Fstab in Ubuntu/Debian

2 minute read Published:

The filesystem table, or more commonly known as fstab or /etc/fstab, is a system configuration file, which is parsed by mount during boot, and misconfiguration or typos can render the system somewhat unusable.

By default on Debian and Ubuntu systems, the root partition has the errors=remount-ro option set, which indicates that if the mount encounters any error, it should only remount the partition as read-only, to prevent damage. In that case, for example, many applications will stop working, unexpected behaviour will be present, among other issues.

For the sake of this post, I deliberately added a faulty option (literally) to the fstab’s root entry, and rebooted afterwards.

Trying to simply remount the partition with the -n flag won’t work. As per mount’s manpage,

-n, –no-mtab

Mount without writing in /etc/mtab. This is necessary for example when /etc is on a read-only filesystem.

The workaround? Find something that’s mounted read/write on the system. A simple mount | grep rw would give us a whole lot of entries, but which of them are actually writable? For example, if you try to touch a file on /sys/ or /proc/, you’ll get a Permission denied error, while others will return a Function not implemented. The magic happens in /dev/ (and /var/run/).

All we need to do now is copy the fstab file there, correct it, then remount r/w using the --fstab argument to overwrite its path, and we’re done.

Don’t forget to modify the /etc/fstab file as well, or you’ll find yourself repeat these steps on the next reboot.