From 9ad6441b3a9aec9f01c411e1045239fa8988dc98 Mon Sep 17 00:00:00 2001 From: lelgenio Date: Wed, 23 Jun 2021 11:59:23 -0300 Subject: [PATCH] root: auto detect root subvolume --- config.yaml | 4 ++-- dotfiles/fish/alias.fish | 2 +- dotfiles/scripts/_create-subvolumes | 18 ++++++++++++------ root/fstab | 17 ++++++++++++++--- root/grub | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/config.yaml b/config.yaml index 49fdf67..c429daf 100644 --- a/config.yaml +++ b/config.yaml @@ -43,8 +43,7 @@ variables: zram: true filesystem: partitions: - "/": /btrfs - "/@root": / + "/": /mnt/btrfs-root "/@home": /home "/@sql": /var/lib/mysql "/@swap": /swap @@ -206,6 +205,7 @@ dynvariables: phisical_uuid: sudo blkid /dev/sda2 -s UUID -o value decrypted_uuid: sudo blkid /dev/mapper/main -s UUID -o value boot_uuid: sudo blkid /dev/sda1 -s UUID -o value + root_subvol: echo "/@$(lsb_release -i | cut -f 2)-root" nproc: nproc memory_size: env LC_ALL=C free -b | awk '/^Mem:/ {print $2}' deezer_arl: pass show Entertainment/Deezer | awk '/^arl:/ {print $2}' diff --git a/dotfiles/fish/alias.fish b/dotfiles/fish/alias.fish index d55c039..6fecb52 100644 --- a/dotfiles/fish/alias.fish +++ b/dotfiles/fish/alias.fish @@ -18,7 +18,7 @@ abbr -g mpn ncmpcpp abbr -g dot "dotdrop install -f" set -l root_cfg (dirname $DOTDROP_CONFIG)/root -alias rootdrop 'dotdrop install -f -c "$root_cfg"' +alias rootdrop 'sudo dotdrop install -f -c "$root_cfg"' cabbr p emerge diff --git a/dotfiles/scripts/_create-subvolumes b/dotfiles/scripts/_create-subvolumes index 8de4253..2198452 100755 --- a/dotfiles/scripts/_create-subvolumes +++ b/dotfiles/scripts/_create-subvolumes @@ -1,12 +1,18 @@ #!/bin/sh -if ! mountpoint /mnt/btrfs-root -then - mkdir /mnt/btrfs-root - mount /mnt/btrfs-root -fi -cd /mnt/btrfs-root +set -e +BTRFS_ROOT="{{@@ filesystem.partitions['/'] @@}}" + +if ! mountpoint "$BTRFS_ROOT" +then + mkdir -p "$BTRFS_ROOT" + mount "$BTRFS_ROOT" +fi +cd "$BTRFS_ROOT" + + +{%@@ set new_partitions = filesystem.partitions.update({root_subvol: '/'}) @@%} {%@@ for name, path in filesystem.partitions.items() @@%} test -e "./{{@@ name @@}}" || btrfs subvolume create "./{{@@ name @@}}" diff --git a/root/fstab b/root/fstab index 75fda70..a750781 100644 --- a/root/fstab +++ b/root/fstab @@ -1,12 +1,23 @@ {{@@ 'non_templated(_dotfile_abs_dst)' | var @@}} ##### Dotdrop-start ##### +{#@@ @@#} + + {%@@ set btrfs_opt_t = "rw,noatime,compress=zstd:3,subvol={}" @@%} + {%@@ set entry_t = "UUID={uuid} {path} {fs} {opts} {dump} {pass}" @@%} + UUID={{@@ boot_uuid @@}} /boot vfat rw,errors=remount-ro 0 2 +{%@@ set new_partitions = filesystem.partitions.update({root_subvol: '/'}) @@%} {%@@ for name, path in filesystem.partitions.items() @@%} - {#@@ @@#} - {%@@ set options = "rw,noatime,compress=zstd:3,subvol={}".format(name) @@%} - UUID={{@@ decrypted_uuid @@}} {{@@ path @@}} btrfs {{@@ options @@}} 0 {{@@ ("root" in name) | int@@}} + {{@@ entry_t.format( + uuid= decrypted_uuid , + path= path , + fs= "btrfs", + opts= btrfs_opt_t.format(name), + dump= "0", + pass= ("root" in name) | int, + ) @@}} {%@@ endfor @@%} /swap/swapfile none swap defaults 0 0 diff --git a/root/grub b/root/grub index 10c92b1..a3667bb 100644 --- a/root/grub +++ b/root/grub @@ -11,7 +11,7 @@ GRUB_DISTRIBUTOR="Artix" GRUB_CMDLINE_LINUX_DEFAULT="" GRUB_CMDLINE_LINUX=" cryptdevice=UUID={{@@ phisical_uuid @@}}:main " -GRUB_CMDLINE_LINUX+=" root=/dev/mapper/main rootflags=rw,noatime,compress=zstd,subvol=/@root " +GRUB_CMDLINE_LINUX+=" root=/dev/mapper/main rootflags=rw,noatime,compress=zstd,subvol=/{{@@ root_subvol @@}} " # Preload both GPT and MBR modules so that they are not missed GRUB_PRELOAD_MODULES="part_gpt part_msdos"