4

I'm running openSUSE Tumbleweed, and finding a strange behaviour when mounting btrfs subvolumes. I have two subvolumes on a btrfs filesystem: @media and @migration. I have my /etc/fstab set up like this:

UUID=<UUID> /mnt/media btrfs subvol=/@media,noatime,noexec,nodev,nosuid 0 0 UUID=<UUID> /mnt/migration btrfs subvol=/@migration,noatime,noexec,nodev,nosuid 0 0 

However, when I run mount -a, I get the following:

/dev/sdb1 on /mnt/media type btrfs (rw,nosuid,nodev,noexec,noatime,space_cache=v2,subvolid=278,subvol=/@media) /dev/sdb1 on /mnt/migration type btrfs (rw,relatime,space_cache=v2,subvolid=279,subvol=/@migration) 

As you can see, the mount options nosuid,nodev,noexec,noatime only appear to be applied to the first subvolume mounted. The second one has only relatime.

When I try to remount the second subvolume, it appears properly:

:~> sudo mount -o remount,noatime /dev/sdb1 /mnt/migration :~> mount | tail -n 2 /dev/sdb1 on /mnt/media type btrfs (rw,nosuid,nodev,noexec,noatime,space_cache=v2,subvolid=278,subvol=/@media) /dev/sdb1 on /mnt/migration type btrfs (rw,noatime,space_cache=v2,subvolid=279,subvol=/@migration) 

So my questions are:

  1. Do mount options on subsequent subvolumes matter? (i.e. is this just a visual bug?)
  2. Is there any way I can verify whether the mount options have actually taken effect?
1
  • As indicated by the answers, for options like nosuid, noexec etc to take effect you have to manually remount. Still in 2025! Commented Mar 17 at 0:30

3 Answers 3

3

I have less than 50 reputation, so I can't comment to squircle's self-answer. But the test is flawed. touch -a updates the atime regardless of mountpoint options.

/tmp  32% ❯ sudo mount -t tmpfs -o noatime none noatime /tmp  32% ❯ cd noatime/ /tmp/noatime  32% ❯ touch banana /tmp/noatime  32% ❯ stat banana File: banana Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 0,116 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/vytautas) Gid: ( 100/ users) Access: 2022-04-14 00:03:14.714042647 +0300 Modify: 2022-04-14 00:03:14.714042647 +0300 Change: 2022-04-14 00:03:14.714042647 +0300 Birth: - /tmp/noatime  32% ❯ cat banana /tmp/noatime  32% ❯ stat banana File: banana Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 0,116 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/vytautas) Gid: ( 100/ users) Access: 2022-04-14 00:03:14.714042647 +0300 Modify: 2022-04-14 00:03:14.714042647 +0300 Change: 2022-04-14 00:03:14.714042647 +0300 Birth: - /tmp/noatime  32% ❯ touch -a -t 1212121212 banana /tmp/noatime  32% ❯ stat banana File: banana Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 0,116 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/vytautas) Gid: ( 100/ users) Access: 2012-12-12 12:12:00.000000000 +0200 Modify: 2022-04-14 00:03:14.714042647 +0300 Change: 2022-04-14 00:03:39.030547903 +0300 Birth: - 
2

I managed to answer my questions using the btrfs wiki and some light experimentation.

Do mount options on subsequent subvolumes matter?

No. Per the btrfs wiki:

Note: most mount options apply to the whole filesystem and only options in the first mounted subvolume will take effect. This is due to lack of implementation and may change in the future. This means that (for example) you can’t set per-subvolume nodatacow, nodatasum, or compress using mount options. This should eventually be fixed, but it has proved to be difficult to implement correctly within the Linux VFS framework.

Is there any way I can verify whether the mount options have actually taken effect?

Yes. I did this with the atime/noatime parameters:

  1. Mount subvolume 1 with the atime option
  2. Mount subvolume 2 with the noatime option
  3. Create a test file on subvolume 2
  4. Use touch to set the atime to an arbitrary value (e.g. touch -a -t 12121212 test_file)
  5. Verify that the atime is set to the test value with ls -lu

This experiment will show that the atime was updated on subvolume 2, despite it being mounted with the noatime option. This is because subvolume 1 was mounted first with the atime option.

1

Subvolume mounts do in fact obey noatime. This is called out explicitly (albeit unclearly) in the new-ish btrfs docs. https://btrfs.readthedocs.io/en/latest/btrfs-subvolume.html#mount-options

(They also support noexec, which was the purpose I had for it.)

$ sudo mount -o subvolid=257,noatime /dev/sdd1 test $ touch -a -t 9001010101 test/foo $ stat test/foo Access: 1990-01-01 01:01:00.000000000 -0700 $ cat test/foo # noatime: atime unchanged $ stat test/foo Access: 1990-01-01 01:01:00.000000000 -0700 $ sudo umount test $ sudo mount -o subvolid=257 /dev/sdd1 test $ cat test/foo # default (relatime): atime changed $ stat test/foo Access: 2023-09-20 03:50:37.919732794 -0600 

(other output lines from stat have been clipped for brevity)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.