Ext4 Filesystem – Mark an Ext4 Filesystem as Read-Only

ext4readonly

I want to create an ext4 filesystem, and add some files to it, then "freeze" it so it is henceforth read-only.

I know it's possible to use the ro mount option. But is there some way to indicate in the filesystem itself that it is read-only?

I see that tune2fs has an option -o to set default mount options, but -o ro is not a valid option.

I also see that tune2fs has an option -E mount_opts. I tried -E mount_opts=ro on a loopback filesystem (Ubuntu 14.10):

dd if=/dev/zero of=ext4test bs=1M count=32
mkfs.ext4 -L test ext4test
tune2fs -E mount_opts=ro ext4test
mkdir ext4testmnt
sudo mount ext4test ext4testmnt

However, the file system is still mounted as read-write.

Best Answer

This is supported in recent kernels (4.0 and later) and, since late February 2015, in e2fsprogs (available since version 1.42.13).

With the appropriate kernel and tools, you can flag an ext4 filesystem read-only using tune2fs:

tune2fs -O read-only ext4test

and clear the flag as always with

tune2fs -O ^read-only ext4test
Related Question