You are not logged in.

#1 2021-12-20 05:00:17

PBS
Member
Registered: 2015-06-28
Posts: 53

[SOLVED] Btrfs subvolume remount semantics

It's possible to have a btrfs filesystem mounted read-write while a subvolume is mounted read-only:

filesystem: rw
subvolume: ro

I can remount the subvolume read-write:

filesystem: rw
subvolume: rw

But when I subsequently try to remount the subvolume read-only again, the whole filesystem also gets remounted read-only:

filesystem: ro
subvolume: ro

Yet unmounting the subvolume and mounting it read-only gives what I asked for:

filesystem: rw
subvolume: ro

Why doesn't remounting give the same result as umounting and mounting again? Is it a bug? A design (mis)decision? The man 5 btrfs manpage does not shed any light on the matter.

Last edited by PBS (2021-12-20 07:09:41)

Offline

#2 2021-12-20 05:14:01

PBS
Member
Registered: 2015-06-28
Posts: 53

Re: [SOLVED] Btrfs subvolume remount semantics

Other notes:

  • See this question for how to try it yourself.

  • This patch seems closely related, but is outdated.

  • The error messages become silly if the filesystem is your root filesystem. Then remounting the subvolume read-only fails with "mount point is busy". But it's not, because you can unmount it.

  • One might think remounting the subvolume with all the original mount options (only adding remount,ro) would fix things. It doesn't.

Different versions of the same question:

Last edited by PBS (2021-12-20 06:51:13)

Offline

#3 2021-12-20 06:59:05

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 9,003
Website

Re: [SOLVED] Btrfs subvolume remount semantics

Try

mount -o remount,ro,subvol=$subvol,bind /$mountpoint

Jin, Jîyan, Azadî

Offline

#4 2021-12-20 07:14:37

PBS
Member
Registered: 2015-06-28
Posts: 53

Re: [SOLVED] Btrfs subvolume remount semantics

Head_on_a_Stick wrote:

Try

mount -o remount,ro,subvol=$subvol,bind /$mountpoint

Yes, sticking bind in the mount options makes it work. I suppose that's because btrfs subvolumes are really implemented over bind mounts.

That solves my original problem. The troubling issue that btrfs ignores sysrq+U remains, though that is an entirely separate topic.

Offline

#5 2021-12-20 07:46:32

PBS
Member
Registered: 2015-06-28
Posts: 53

Re: [SOLVED] Btrfs subvolume remount semantics

PBS wrote:

I suppose that's because btrfs subvolumes are really implemented over bind mounts.

Correcting myself, it has nothing to do with subvolumes being implemented over bind mounts, and works for any mount. In fact, man 2 mount clearly states that "remount,bind" is the preferred way to change the mount options of an existing mount. (Despite that, it doesn't work for systemd-automounts, and you have to use plain old "remount" for them, but that's another mystery.)

I also notice that the example given in the man page,

mount --bind olddir newdir mount -o remount,bind,ro olddir newdir

seems to be missing a line break.

Last edited by PBS (2021-12-20 15:36:29)

Offline

Board footer

Powered by FluxBB