mount: warning: /mnt seems to be mounted read-write

When trying to create readonly bind-mounts, this happens:

$ mkdir a b
$ mount -o bind,ro a b
mount: warning: b seems to be mounted read-write.
$ touch b/1
$ mount -o remount,ro b
$ touch b/2
touch: cannot touch `b/2': Read-only file system
This is even documented in the manpage:
   Note that the filesystem mount options will remain the same as those on the 
   original mount point, and cannot be changed by passing the -o option along 
   with --bind/--rbind. The mount options can be changed by a separate remount 
   command, for example:

        mount --bind olddir newdir
        mount -o remount,ro newdir
Interestingly enough, mount(2) states:
    Up until Linux 2.6.26, mountflags was also ignored (the bind mount has the
    same mount options as the underlying mount point).  Since Linux 2.6.26, 
    the MS_RDONLY flag is honored when making a bind mount.
FWIW, let's see how other systems handle that:
  • NetBSD handles this via its mount_null filesystem and gets the dupicated subtree readonly right away:
    $ mkdir /mnt/a /mnt/b
    $ mount -t null -o ro /mnt/a /mnt/b
    $ touch /mnt/b/1
    touch: /mnt/b/1: Read-only file system
    $ touch /mnt/a/2
    $ ls -l /mnt/b/*
    -rw-r--r--  1 root  wheel  0 Jul 13 15:57 /mnt/b/2
    
  • Same for FreeBSD, only here it's called mount_nullfs.

  • OpenBSD removed mount_nullfs years ago.

  • Solaris has lofs(7FS):
    $ mkdir /mnt/a /mnt/b
    $ mount -F lofs -o ro /mnt/a /mnt/b
    $ touch /mnt/b/1
    touch: cannot create /mnt/b/1: Read-only file system
    $ touch /mnt/a/2
    $ ls -l /mnt/b/*
    -rw-r--r--   1 root  root   0 Jul 13 16:53 /mnt/b/2