install: more comprehensive subdivision of btrfs subvols (MR 2233)

Why
Btrfs has some goodness (snapshots, switching between different rw snapshot)
which plays particularly well with certain "subvolume layouts".

What
This MR seeks to implement such a layout, namely a flat btrfs layout,
where the top level subvolume (i.e. the btrfs filesystem/partition itself)
remains unmounted in all situations,
except when making changes to direct child subvolumes of the filesystem.

- rename all subvols to follow the common @* btrfs subvol naming scheme.
- add subvol @root, because roots home directory shouldn't be rolled back.
- make subvol @var not Copy-on-Write (nodatacow) to avoid write
- multiplication on logs, VMs, databases, containers and flatpaks.
- add subvol @snapshots because that lets us change the root subvol to a
read-write snapshot of @ without affecting snapshots.
- add subvol @srv because it contains data for Web and FTP servers,
which shouldn't roll back together with root subvol.
- add subvol @tmp because we don't want to snapshot temporary files.
This subvol remains unmounted on the device,
unless conditions as laid out in pmaports!4737 are met.
- add check and error for btrfs when using rsync installation.
This commit is contained in:
Jacob Ludvigsen 2024-01-18 13:14:17 +01:00 committed by Oliver Smith
parent e139a34472
commit 2bd1eb26d8
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
3 changed files with 79 additions and 12 deletions

View file

@ -153,10 +153,8 @@ def create_home_from_skel(args):
Create /home/{user} from /etc/skel
"""
rootfs = args.work + "/chroot_native/mnt/install"
if args.filesystem == "btrfs":
pmb.helpers.run.root(args,
["btrfs", "subvol", "create", rootfs + "/home"])
else:
# In btrfs, home subvol & home dir is created in format.py
if args.filesystem != "btrfs":
pmb.helpers.run.root(args, ["mkdir", rootfs + "/home"])
homedir = rootfs + "/home/" + args.user
if os.path.exists(f"{rootfs}/etc/skel"):
@ -779,9 +777,12 @@ def create_fstab(args, layout, suffix):
# btrfs gets separate subvolumes for root, var and home
fstab = f"""
# <file system> <mount point> <type> <options> <dump> <pass>
{root_mount_point} / {root_filesystem} subvol=root,compress=zstd:2,ssd 0 0
{root_mount_point} /home {root_filesystem} subvol=home,compress=zstd:2,ssd 0 0
{root_mount_point} /var {root_filesystem} subvol=var,compress=zstd:2,ssd 0 0
{root_mount_point} / btrfs subvol=@,compress=zstd:2,ssd 0 0
{root_mount_point} /home btrfs subvol=@home,compress=zstd:2,ssd 0 0
{root_mount_point} /root btrfs subvol=@root,compress=zstd:2,ssd 0 0
{root_mount_point} /srv btrfs subvol=@srv,compress=zstd:2,ssd 0 0
{root_mount_point} /var btrfs subvol=@var,ssd 0 0
{root_mount_point} /.snapshots btrfs subvol=@snapshots,compress=zstd:2,ssd 0 0
{boot_mount_point} /boot {boot_filesystem} defaults 0 0
""".lstrip()