btrfs icon indicating copy to clipboard operation
btrfs copied to clipboard

Mount read-only by default

Open Witiko opened this issue 8 years ago • 3 comments

Hi,

when I install the driver and reboot, all btrfs partitions are mounted read/write by default. As far as I am aware, the only way to prevent this is to either

  1. know the subkey of HKLM\SYSTEM\CurrentControlSet\Services\btrfs corresponding to my partition and set HKLM\SYSTEM\CurrentControlSet\Services\btrfs\<SUBKEY>\Readonly to 1 prior to activating the driver, or
  2. alter the source code of the driver.

Arguably, making read/write access opt-in rather than opt-out makes for a more sensible default:

  1. Windows creates the /$RECYCLE.BIN and /System Volume Information directories at all the mounted partitions. You generally don't want these in the root directory of your linux btrfs partitions.
  2. After a test boot with the driver installed, I found that my root btrfs filesystem was corrupted (all safely backed up) to the point where it would not mount on linux 4.9.30 given the following /etc/fstab line
/dev/sdXY / btrfs discard,relatime,compress 0 0

without running btrfs check --repair /dev/sdXY first. Attached is the output of btrfs check:

$ btrfs --version
btrfs-progs v4.12
$ btrfs check sdXY.img
Checking filesystem on sdXY.img
UUID: 0c71059e-c962-4709-8db9-664684cca639
checking extents
checksum verify failed on 25861799936 found E4E3BDB6 wanted 00000000
checksum verify failed on 25861799936 found E4E3BDB6 wanted 00000000
bytenr mismatch, want=25861799936, have=0
ERROR: errors found in extent allocation tree or chunk allocation
root item for root 511, current bytenr 25861799936, current gen 323909, current level 2, new bytenr 25925255168, new gen 323915, new level 2
Found 1 roots with an outdated root item.
Please run a filesystem check with the option --repair to fix them.

I can provide parts of the image should you wish to investigate further.

For the above reasons, I suggest the driver should create HKLM\SYSTEM\CurrentControlSet\Services\btrfs\<SUBKEY>\Readonly with the value of 1 for all the new btrfs partitions it detects and that read/write access should become opt-in rather than opt-out.

Witiko avatar Aug 21 '17 08:08 Witiko

Thanks. You make some good points, but I'm not going to do that because it violates the principle of least astonishment - plus it's not what Windows' own drivers do. Though having said that, since https://github.com/maharmstone/btrfs/commit/ec9e233902083df0ff53ce04f9aa63ed1fd43885, which will be in the next version, you can get volumes to default to readonly if you want.

I've not seen that error before... it looks like you have a very large number of subvolumes, is that right?

maharmstone avatar Aug 23 '17 18:08 maharmstone

Thanks, that is certainly an improvement over the current state. And no, I would not say that; this volume contains only 13 subvolumes, 11 of which are read-only snapshots.

Witiko avatar Aug 23 '17 20:08 Witiko

This filesystem has multiple reports about filesystem corruption with Linux, and you're worried about... least astonishment? I would think the "principle of least astonishment" requires that simply checking out a new driver does not corrupt my existing BTRFS filesystems.

Having said that, how to use https://github.com/maharmstone/btrfs/commit/ec9e233902083df0ff53ce04f9aa63ed1fd43885 ? Not having any mentions of read-only mounting in the README is quite "astonishing".

mralusw avatar Mar 27 '21 23:03 mralusw

Closing old issues

maharmstone avatar Nov 30 '23 01:11 maharmstone