From 63d81b5e35a21d4ad0eb75f1c67dd3bb40972beb Mon Sep 17 00:00:00 2001 From: Adrian Wannenmacher Date: Fri, 25 Sep 2020 12:39:53 +0200 Subject: [PATCH] Add basic version of creation script --- scripts/snap-pac-uki_create.fish | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 scripts/snap-pac-uki_create.fish diff --git a/scripts/snap-pac-uki_create.fish b/scripts/snap-pac-uki_create.fish new file mode 100755 index 0000000..96fb3de --- /dev/null +++ b/scripts/snap-pac-uki_create.fish @@ -0,0 +1,41 @@ +#!/bin/fish + +# get id and type of last snapshot +set -l config "root" +set -l snapshots (snapper -c $config --jsonout ls | jq -c ".$config") +set -l last (echo $snapshots | jq -c "last") +set -l id (echo $last | jq ".number") +set -l type (echo $last | jq ".type") + +if not contains $type '"pre"' '"post"' + echo "Last snapshot has type \"$type\", therefore no UKI is created." + exit +end + + +# check if UKI already exists +set -l ukis (ls /boot/EFI/Linux/ | grep "snap-pac-uki-[1-9][0-9]*\.efi" | grep -o '[1-9][0-9]*') + +if contains $id $ukis + echo "UKI already exists" + exit +end + + +# prepare uki creation +mkdir -p "/tmp/snap-pac-uki/$id" +rm -rf "/tmp/snap-pac-uki/$id/*" +cd "/tmp/snap-pac-uki/$id" + +sed "s/BUILD_ID=.*/BUILD_ID=\"Snapshot $id\"/" ./os-release +grep options /boot/loader/entries/00-arch.conf | string sub -s 9 | sed ':a;N;$!ba;s/\n/ /g' >./kernel-parameters + + +# create uki +objcopy \ + --add-section .osrel="./os-release" --change-section-vma .osrel=0x20000 \ + --add-section .cmdline="./kernel-parameters" --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" "/boot/EFI/Linux/snap-pac-uki-$id.efi"