From a22cafb5da101e774be3849c58737e7972228a7f Mon Sep 17 00:00:00 2001 From: Yukari Chiba Date: Wed, 17 Jul 2024 18:10:07 +0800 Subject: [PATCH] add multi-layer sfs generation --- utils/collect.sh | 14 ++++++++++---- utils/function_def.sh | 27 +++++++++++++++++++++++++++ utils/hooks.sh | 13 ++++++------- utils/install.sh | 13 ++++++++++++- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/utils/collect.sh b/utils/collect.sh index 423b4f0..3bf8bee 100755 --- a/utils/collect.sh +++ b/utils/collect.sh @@ -6,8 +6,14 @@ mkdir -p results if [[ $PROFILE == liveimage* ]]; then mkdir -p ./tmpdir/isofs/live/sfs/ - $RUNAS mksquashfs ./tmpdir/rootfs ./tmpdir/isofs/live/sfs/root.sfs - echo "root" | $RUNAS tee ./tmpdir/isofs/live/live.list + for sfsdir in $(ls ./tmpdir/layers/); do + $RUNAS mksquashfs ./tmpdir/layers/$sfsdir ./tmpdir/isofs/live/sfs/$sfsdir.sfs + done + cat < results/eweos-$TARGET_ARCH-$PROFILE.iso.sha256 fi if [[ $PROFILE == tarball* ]]; then - umount_chroot ./tmpdir/rootfs $RUNAS tar cJf results/eweos-$TARGET_ARCH-$PROFILE.tar.xz -C ./tmpdir/rootfs . pushd results sha256sum eweos-$TARGET_ARCH-$PROFILE.tar.xz > eweos-$TARGET_ARCH-$PROFILE.tar.xz.sha256 diff --git a/utils/function_def.sh b/utils/function_def.sh index c42fbc0..83a8663 100755 --- a/utils/function_def.sh +++ b/utils/function_def.sh @@ -18,3 +18,30 @@ function umount_chroot(){ $RUNAS umount $1/sys/firmware/efi/efivars || true $RUNAS umount $1/sys || true } + +function mount_overlay(){ +# mount overlay only for liveimage, use rootfs as usual for other images +if [[ $PROFILE == liveimage* ]]; then + mkdir -p ./tmpdir/overlay_workdir + upperlayer=$1 + mkdir -p ./tmpdir/layers/$upperlayer ./tmpdir/rootfs + shift 1 + if [ $# -eq 0 ]; then + $RUNAS mount --bind ./tmpdir/layers/$upperlayer ./tmpdir/rootfs + else + LOWERLAYERS="" + for layer in "$@" + do + mkdir -p ./tmpdir/layers/$layer + LOWERLAYERS+="$PWD/tmpdir/layers/${layer}:" + done + $RUNAS mount -t overlay overlay -o lowerdir=${LOWERLAYERS%:},upperdir=$PWD/tmpdir/layers/$upperlayer,workdir=$PWD/tmpdir/overlay_workdir ./tmpdir/rootfs + fi +fi +} + +function umount_overlay(){ + $RUNAS sync + umount_chroot ./tmpdir/rootfs + $RUNAS umount ./tmpdir/rootfs || true +} diff --git a/utils/hooks.sh b/utils/hooks.sh index ab78fef..571e9f5 100755 --- a/utils/hooks.sh +++ b/utils/hooks.sh @@ -1,11 +1,10 @@ #!/bin/env sh -if [[ $PROFILE == liveimage* ]]; then - _logtxt "#### creating boot partition" - mkdir -p tmpdir/isofs - $RUNAS mkdir -p ./tmpdir/rootfs/boot - $RUNAS mount --bind ./tmpdir/isofs ./tmpdir/rootfs/boot -fi +mount_overlay live packages base + +mkdir -p tmpdir/isofs +$RUNAS mkdir -p ./tmpdir/rootfs/boot +$RUNAS mount --bind ./tmpdir/isofs ./tmpdir/rootfs/boot if [ -d profiles/$PROFILE/files ]; then _logtxt "#### copying files" @@ -40,4 +39,4 @@ if [ -d ./tmpdir/rootfs/.files ]; then $RUNAS rm -r ./tmpdir/rootfs/.files fi -umount_chroot ./tmpdir/rootfs +umount_overlay diff --git a/utils/install.sh b/utils/install.sh index a51a5c1..b5f1bb1 100755 --- a/utils/install.sh +++ b/utils/install.sh @@ -2,7 +2,17 @@ mkdir -p tmpdir/rootfs -_logtxt "#### bootstrapping system" +_logtxt "#### bootstrapping base system" + +mount_overlay base + +$RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./tmpdir/rootfs base linux linux-firmware + +umount_overlay + +_logtxt "#### bootstrapping packages" + +mount_overlay packages base $RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./tmpdir/rootfs `cat profiles/$PROFILE/packages.txt | xargs` @@ -10,3 +20,4 @@ if [ -f profiles/$PROFILE/packages.$TARGET_ARCH.txt ]; then $RUNAS pacstrap -G -M -c -C ./pacman.ewe.conf ./tmpdir/rootfs `cat profiles/$PROFILE/packages.$TARGET_ARCH.txt | xargs` fi +umount_overlay