fix: 🐛 create ukis with appropriate configuration

This commit is contained in:
Adrian Wannenmacher 2021-02-10 21:57:18 +01:00
parent 79a7067f58
commit 3c018e29ed
Signed by: tfld
GPG Key ID: 19D986ECB1E492D5
1 changed files with 26 additions and 17 deletions

View File

@ -23,12 +23,13 @@ function load_config -d "loads the config from a config file" -a cfg
set -g EFI_DIR "/efi/EFI/Linux/"
set -g SNAPPER_CONFIG "root"
set -g SNAPSHOT_SUBVOL "@snapshots"
set -g ROOT_SUBVOL "@"
# load file
set -l cfg (jq -c <$cfg)
# parse config
set -l cfgs "build_path" "efi_dir" "kernel_cmd" "fallback_cmd" "snapper_config" "snapshot_subvol"
set -l cfgs "build_path" "efi_dir" "kernel_cmd" "fallback_cmd" "snapper_config" "snapshot_subvol" "root_subvol"
for c in $cfgs
echo $cfg | jq -e ".$c" >/dev/null
@ -55,17 +56,21 @@ function get_last_snapshot -d "reads the last snapper snapshot id"
set -g SNAPSHOT_ID (snapper -c $SNAPPER_CONFIG --jsonout ls | jq ".$SNAPPER_CONFIG | last | .number")
end
function create_uki -d "creates a new uki" -a fallback
function create_uki -d "creates a new uki"
# prepare directory
set -l bp "$BUILD_PATH/$SNAPSHOT_ID"
mkdir -p $bp
rm -rf "$bp/*"
# os-release
sed "s/BUILD_ID=.*/BUILD_ID=\"Snapshot $SNAPSHOT_ID\"/" </usr/lib/os-release >"$bp/os-release"
cp /usr/lib/os-release "$bp/os-release"
sed "s/BUILD_ID=.*/BUILD_ID=\"fallback\"/" </usr/lib/os-release >"$bp/os-release-fallback"
sed "s/BUILD_ID=.*/BUILD_ID=\"snapshot $SNAPSHOT_ID\"/" </usr/lib/os-release >"$bp/os-release-snapshot"
# kernel cmd
echo $KERNEL_CMD | sed "s/SNAPSHOT/$SNAPSHOT_SUBVOL\\/$SNAPSHOT_ID\\/snapshot/" >"$bp/kernel-cmd"
echo $KERNEL_CMD | sed "s/SNAPSHOT/$ROOT_SUBVOL/" >"$bp/kernel-cmd"
echo $FALLBACK_CMD | sed "s/SNAPSHOT/$ROOT_SUBVOL/" >"$bp/kernel-cmd-fallback"
echo $KERNEL_CMD | sed "s/SNAPSHOT/$SNAPSHOT_SUBVOL\\/$SNAPSHOT_ID\\/snapshot/" >"$bp/kernel-cmd-snapshot"
# create uki
objcopy \
@ -73,17 +78,22 @@ function create_uki -d "creates a new uki" -a fallback
--add-section .cmdline="$bp/kernel-cmd" --change-section-vma .cmdline=0x30000 \
--add-section .splash="/usr/share/systemd/bootctl/splash-arch.bmp" --change-section-vma .splash=0x40000 \
--add-section .linux="/boot/vmlinuz-linux" --change-section-vma .linux=0x2000000 \
--add-section .initrd="/boot/initramfs-linux$fallback.img" --change-section-vma .initrd=0x3000000 \
"/usr/lib/systemd/boot/efi/linuxx64.efi.stub" "$bp/arch-linux-$SNAPSHOT_ID$fallback.efi"
end
function copy_current -d "copies new ukis to efi"
# copy to "current"
cp "$BUILD_PATH/$SNAPSHOT_ID/arch-linux-$SNAPSHOT_ID.efi" "$EFI_DIR/arch-linux-current.efi"
cp "$BUILD_PATH/$SNAPSHOT_ID/arch-linux-$SNAPSHOT_ID-fallback.efi" "$EFI_DIR/arch-linux-fallback.efi"
# copy to "snapshots"
cp "$BUILD_PATH/$SNAPSHOT_ID/arch-linux-$SNAPSHOT_ID.efi" $EFI_DIR
--add-section .initrd="/boot/initramfs-linux.img" --change-section-vma .initrd=0x3000000 \
"/usr/lib/systemd/boot/efi/linuxx64.efi.stub" "$bp/arch-linux.efi"
objcopy \
--add-section .osrel="$bp/os-release-fallback" --change-section-vma .osrel=0x20000 \
--add-section .cmdline="$bp/kernel-cmd-fallback" --change-section-vma .cmdline=0x30000 \
--add-section .splash="/usr/share/systemd/bootctl/splash-arch.bmp" --change-section-vma .splash=0x40000 \
--add-section .linux="/boot/vmlinuz-linux" --change-section-vma .linux=0x2000000 \
--add-section .initrd="/boot/initramfs-linux-fallback.img" --change-section-vma .initrd=0x3000000 \
"/usr/lib/systemd/boot/efi/linuxx64.efi.stub" "$bp/arch-linux-fallback.efi"
objcopy \
--add-section .osrel="$bp/os-release-snapshot" --change-section-vma .osrel=0x20000 \
--add-section .cmdline="$bp/kernel-cmd-snapshot" --change-section-vma .cmdline=0x30000 \
--add-section .splash="/usr/share/systemd/bootctl/splash-arch.bmp" --change-section-vma .splash=0x40000 \
--add-section .linux="/boot/vmlinuz-linux" --change-section-vma .linux=0x2000000 \
--add-section .initrd="/boot/initramfs-linux.img" --change-section-vma .initrd=0x3000000 \
"/usr/lib/systemd/boot/efi/linuxx64.efi.stub" "$bp/arch-linux-$SNAPSHOT_ID.efi"
end
function main -d "the main function"
@ -92,9 +102,8 @@ function main -d "the main function"
get_last_snapshot
create_uki
create_uki "-fallback"
copy_current
cp "$BUILD_PATH/$SNAPSHOT_ID/*.efi" "$EFI_DIR"
exit 0
end