Repository: archlinux/archinstall

Issue #1571: Bugs: Btrfs compression does not work when subvolumes are selected in the UI, btrfs subvolumes ignore "mount_options" specified in disk layout json file 
Created: 2022-11-19T01:48:26Z
Hi Torxed,
Btrfs compression does not work when subvolumes are selected in the user interface.  Another bug which is related to this is that btrfs subvolumes ignore "mount_options" specified in the disk layout json file.
In order to replicate, just start archinstall and do the following:  Select "Wipe all selected drives and use a best-effort default partition layout". Choose yes for btrfs compression and btrfs subvolumes.  Install a minimal system.  After the installation is over, enter the command "cat /proc/mounts".  You will see that the mount options of the subvolumes do not include any compression options.  When you check "/mnt/archinstall/etc/fstab" file you will see that no compression options are defined in it.
There are some other things you can check that might help you to debug this issue and reveal more bugs.  Do the same steps that I mentioned above in the user interface but instead of installing the system, ask the UI to save the disk layouts to "user_disk_layout.json" file.  When you look at the json file, you will see that the file system has "mount_options": ["compress=zstd"] specified but the subvolumes have "compress": false specified.  Playing with this json file will reveal more bugs.  Edit the file and specify "compress": true for all subvolumes.  run "archinstall --disk_layout user_disk_layout.json" and install a minimal system again.  After the installation is over, enter the command "cat /proc/mounts".  You will see that the mount options of the subvolumes include "compress=zlib:3".  When you check fstab you will see that it includes both "compress=zstd" and "compress=zlib:3" for all subvolumes.  Wrong type of compression (zlib:3) was used when installing the system and wrong type of compression was specified in the fstab file (both zstd and zlib are specified at the same time).
Please bear with me and lets do one more check to reveal another bug.  Edit the "user_disk_layout.json" file one more time and set "mount_options": ["compress-force=zstd:15"].  We will again have "compress": true for all subvolumes.  Run archinstall with this new json file that has the custom compression we specified and install a minimum system.  After the installation is over check  "cat /proc/mounts" and fstab one more time.  You will see that the situation is the same.  /proc/mounts will show "compress=zlib:3" and fstab will show both "compress=zstd" and "compress=zlib:3".  Custom mount_option (compression option) specified in the json file was completely ignored.
I am not a programmer but I searched the source code to see if I can help you to debug these issues.
It seems like in line 19 of subvolume.py file, you have the word "compress" hard coded as a mount option for subvolumes.  Btrfs uses zlib:3 compression by default when "compress" is specified without any options.  If you change that line to "compress=zstd" that will solve part of the problem.  Please also check if the user specified custom compression in the  mount_options field of the json file, otherwise a hard coded "compress=zstd" in that line will override the custom compression specified in the disk layout json file.
Line 39 of btrfs_helpers.py file might be responsible for options  "compress=zstd" and "compress=zlib:3" showing up in the fstab file at the same time.  In that line you check if "compress=zstd" is in the mount options and add it if it is not already there.  Since zlib compression was mistakenly used when installing the system (due to line 19 of subvolume.py file), compress=zstd gets added.  Line 39 might cause issues if the user specifies custom compression options such as "compress-force=zstd:15" or "compress=lzo" since they do not match the "compress=zstd:*" pattern.
I could not figure out why mount_options flag from the json file gets completely ignored for subvolumes.  It might be because that flag is completely missing from the subvolume.py file.
I also could not figure out why "compress": false is specified for all subvolumes even if the user selects compression in the user interface.  Something in the code overrides the user selection from true to false.  Currently it is not possible to install a compressed system with subvolumes by using the UI of archinstall.  We need to create a disk layout json file first and modify subvolume "compress" flags to true.  Even then, we have to settle with other bugs that I explained above.  :))
On a separate note, none of these issues happen if the user does not use subvolumes.  Compression works fine and defaults to "compress=zstd:3" in the fstab file and /proc/mounts when subvolumes are not specified in the user interface.  Specifying custom compression in the disk layout json file such as "mount_options": ["compress-force=zstd:15"] also work without any problems when subvolumes are not used.  Line 39 of btrfs_helpers.py file does not add an incorrect "compress=zstd" into the fstab file in addition to the "compress-force=zstd:15" that is already in there.  Normally I do not use subvolumes.  That's why I did not notice these bugs in the past.

Duplicate issue #1592: Double compression on BTRFS subvolumes?
Created: 2022-12-13T08:30:13Z
Adding compression to each BTRFS subvolume managed to somehow add both compress=zstd and compress=zlib:3 options to my /etc/fstab causing it to default to using zlib instead of zstd.
UUID=5166753d-a8b3-46e8-b0a0-f9808948e86f / btrfs rw,compress=zstd,relatime,compress=zlib:3,ssd,space_cache=v2,subvolid=256,subvol=/@ 0 0

I also had to manually add compress options on at least one subvolume on a separate drive, despite selecting to add compression to every subvolume.

Closing comment (2024-03-11T00:53:06Z): Yes, this is a duplicate of #1571