From ded31276c90e8103ad5f20d378af8a1dda33f43a Mon Sep 17 00:00:00 2001 From: Denis Benato Date: Thu, 21 Mar 2024 21:58:09 +0100 Subject: [PATCH 1/3] Add support for /etc as a submodule --- __frzr-deploy | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/__frzr-deploy b/__frzr-deploy index edf1c33..bc65f6b 100644 --- a/__frzr-deploy +++ b/__frzr-deploy @@ -325,6 +325,32 @@ main() { tar xfO ${IMG_FILE} | btrfs receive --quiet ${DEPLOY_PATH} fi + if [ -d "${SUBVOL}/etc" ]; then + echo "System image ${NAME} will use the /etc overlay" + else + echo "System image ${NAME} will use an /etc subvolume" + + btrfs subvolume create "${SUBVOL}/etc" + + btrfs subvolume create "${SUBVOL}/snapshots" + + btrfs subvolume create "${SUBVOL}/snapshots/etc" + + # copy every stock /etc (that has been moved to /usr/etc) file to the actual /etc + cp -a ${SUBVOL}/usr/etc/** ${SUBVOL}/etc/ + + # copy the machine-id file: this was created by systemd the very first boot and identify the machine: + # changing this will also make ssh warn about machine not matching. + if [ -f "/etc/machine-id" ]; then + cp -a /etc/machine-id ${SUBVOL}/etc/ + else + echo "WARNING: no /etc/machine-id -- new machine-id will be regenerated at next boot" + fi + + # Make a snapshot of /etc so that this state can be restored + btrfs subvolume snapshot ${SUBVOL}/etc ${SUBVOL}/snapshots/etc/0 + fi + mkdir -p ${MOUNT_PATH}/boot/${NAME} cp ${SUBVOL}/boot/vmlinuz-linux ${MOUNT_PATH}/boot/${NAME} cp ${SUBVOL}/boot/initramfs-linux.img ${MOUNT_PATH}/boot/${NAME} From 0cc9ad718d2f0bbbec51969ed4a8d8315d650d3b Mon Sep 17 00:00:00 2001 From: Denis Benato Date: Fri, 22 Mar 2024 20:37:33 +0100 Subject: [PATCH 2/3] cp * instead of ** since cp -a is already recursive --- __frzr-deploy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__frzr-deploy b/__frzr-deploy index bc65f6b..b93e364 100644 --- a/__frzr-deploy +++ b/__frzr-deploy @@ -337,7 +337,7 @@ main() { btrfs subvolume create "${SUBVOL}/snapshots/etc" # copy every stock /etc (that has been moved to /usr/etc) file to the actual /etc - cp -a ${SUBVOL}/usr/etc/** ${SUBVOL}/etc/ + cp -a ${SUBVOL}/usr/etc/* ${SUBVOL}/etc/ # copy the machine-id file: this was created by systemd the very first boot and identify the machine: # changing this will also make ssh warn about machine not matching. From bd3be915e00397922e6349f7bbcc0daf00646d24 Mon Sep 17 00:00:00 2001 From: Denis Benato Date: Fri, 22 Mar 2024 23:57:08 +0100 Subject: [PATCH 3/3] creating a subvolume needs the parent to be r/w --- __frzr-deploy | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/__frzr-deploy b/__frzr-deploy index b93e364..4189068 100644 --- a/__frzr-deploy +++ b/__frzr-deploy @@ -330,10 +330,18 @@ main() { else echo "System image ${NAME} will use an /etc subvolume" + # unlock the subvolume to be able to create a nested subvolume + btrfs property set -f -ts "${SUBVOL}/" ro false + + # create the nested subvolume for /etc btrfs subvolume create "${SUBVOL}/etc" + # create the nested subvolume for /snapshots btrfs subvolume create "${SUBVOL}/snapshots" + # re-lock the subvolume. ${SUBVOL}/etc will remain R/W + btrfs property set -f -ts "${SUBVOL}/" ro true + btrfs subvolume create "${SUBVOL}/snapshots/etc" # copy every stock /etc (that has been moved to /usr/etc) file to the actual /etc