This commit is contained in:
Valeria Fadeeva 2023-04-15 18:13:49 +05:00
parent a26ef6cb27
commit 5da960a8bd
10 changed files with 307 additions and 0 deletions

26
.SRCINFO Normal file
View File

@ -0,0 +1,26 @@
pkgbase = melawy-dracut-ukify
pkgdesc = Integration layer for dracut and systemd's ukify tool for Arch Linux. Placing kernels to /ESP_PATH/EFI/Linux
pkgver = 0
pkgrel = 1
url = https://github.com/Valeria-Fadeeva/melawy-dracut-ukify
arch = any
license = AGPL3
depends = dracut
depends = systemd-ukify
depends = python
depends = util-linux
depends = python-pefile
optdepends = sbsigntools: secureboot support
provides = dracut-hook
conflicts = dracut-hook-uefi
conflicts = dracut-uefi-hook
source = 10-dracut-ukify-pre-install.hook
source = 60-dracut-ukify-remove.hook
source = 90-dracut-ukify-install.hook
source = dracut-ukify
sha256sums = e9592f4f738e8ac70044db1e3f0c4839bc07f37662d5dbc221230cf1617a6b4d
sha256sums = 341cd01546d840e7401f7bec868a78e2f6ca12563e93d993a07bc51efe674ed0
sha256sums = 08225b2c3f5e2a734561b5fa9a3e84060dfffd85b2898adb0fff0ce3b068b4d0
sha256sums = 45de7b379bca66b96327b0a7957fefce5acc53968828cc412f5e5d0f13c4151f
pkgname = melawy-dracut-ukify

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
*.pkg.tar
*.pkg.tar.*
*.zst
*.zst.*
pkg/
src/
.idea/

View File

@ -0,0 +1,16 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase
Target = usr/lib/dracut/*
Target = usr/lib/systemd/systemd
Target = usr/lib/systemd/boot/efi/*.efi.stub
Target = usr/share/libalpm/hooks/90-dracut-ukify-install.hook
Target = usr/bin/dracut-ukify
Target = usr/src/*/dkms.conf
[Action]
Description = Ensure ESP is mounted...
When = PreTransaction
Exec = /usr/bin/dracut-ukify -x

View File

@ -0,0 +1,11 @@
[Trigger]
Type = Path
Operation = Remove
Target = usr/lib/modules/*/pkgbase
Target = usr/src/*/dkms.conf
[Action]
Description = Removing linux images...
When = PreTransaction
Exec = /usr/bin/dracut-ukify -y
NeedsTargets

View File

@ -0,0 +1,17 @@
[Trigger]
Type = Path
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase
Target = usr/lib/dracut/*
Target = usr/lib/systemd/systemd
Target = usr/lib/systemd/boot/efi/*.efi.stub
Target = usr/share/libalpm/hooks/90-dracut-ukify-install.hook
Target = usr/bin/dracut-ukify
Target = usr/src/*/dkms.conf
[Action]
Description = Updating linux images...
When = PostTransaction
Exec = /usr/bin/dracut-ukify -z
NeedsTargets

31
PKGBUILD Normal file
View File

@ -0,0 +1,31 @@
# Maintainer: Valeria Fadeeva <valeria@fadeeva.me>
pkgname=melawy-dracut-ukify
pkgver=0
pkgrel=1
pkgdesc="Integration layer for dracut and systemd's ukify tool for Arch Linux. Placing kernels to /ESP_PATH/EFI/Linux"
url="https://github.com/Valeria-Fadeeva/melawy-dracut-ukify"
arch=(any)
license=('AGPL3')
depends=(dracut systemd-ukify python util-linux python-pefile)
optdepends=(
'sbsigntools: secureboot support'
)
source=('10-dracut-ukify-pre-install.hook'
'60-dracut-ukify-remove.hook'
'90-dracut-ukify-install.hook'
'dracut-ukify')
sha256sums=('e9592f4f738e8ac70044db1e3f0c4839bc07f37662d5dbc221230cf1617a6b4d'
'341cd01546d840e7401f7bec868a78e2f6ca12563e93d993a07bc51efe674ed0'
'08225b2c3f5e2a734561b5fa9a3e84060dfffd85b2898adb0fff0ce3b068b4d0'
'45de7b379bca66b96327b0a7957fefce5acc53968828cc412f5e5d0f13c4151f')
backup=()
provides=(dracut-hook)
conflicts=(dracut-hook-uefi dracut-uefi-hook)
package() {
install -Dm644 "${srcdir}/10-dracut-ukify-pre-install.hook" "${pkgdir}/usr/share/libalpm/hooks/10-dracut-ukify-pre-install.hook"
install -Dm644 "${srcdir}/60-dracut-ukify-remove.hook" "${pkgdir}/usr/share/libalpm/hooks/60-dracut-ukify-remove.hook"
install -Dm644 "${srcdir}/90-dracut-ukify-install.hook" "${pkgdir}/usr/share/libalpm/hooks/90-dracut-ukify-install.hook"
install -Dm755 "${srcdir}/dracut-ukify" "${pkgdir}/usr/bin/dracut-ukify"
}

View File

@ -1,2 +1,12 @@
# melawy-dracut-ukify
Integration layer for dracut and systemd's ukify tool for Arch Linux. Placing kernels to /ESP_PATH/EFI/Linux
```
ls -1 /efi/EFI/Linux
```
```
...
linux-xanmod-anbox.efi
linux-xanmod-anbox-fallback.efi
...
```

171
dracut-ukify Executable file
View File

@ -0,0 +1,171 @@
#!/bin/bash -e
function usage {
echo "$(basename "$0") [OPTIONS]"
echo " -h shows usage"
echo " -g <version> generate UKI image for specified kernel version"
echo " -a generate UKI images for all available kernels"
}
function check_root {
[ $EUID -eq 0 ] && return
echo "dracut-ukify requires root privileges to work" >&2
exit 1
}
if [[ ${#} -eq 0 ]]; then
usage
fi
declare -a ukify_global_args=()
ESP_PATH=$(bootctl --print-esp-path)
BOOT_PATH="${ESP_PATH}/EFI/Linux"
declare -A kernels
update_all=0
while getopts ":hag:xyz" arg; do
case ${arg} in
g)
found=0
for line in $(pacman -Qql "$OPTARG"); do
if [[ $line =~ ^/usr/lib/modules/([^/]+)/pkgbase$ ]]; then
read -r kernel_name < "/${line}"
kernels["${kernel_name}"]="${BASH_REMATCH[1]}"
found=1
break
fi
done
if (( ! found )); then
echo "Error occurred during '$OPTARG' package traversal" >&2
exit 1
fi
;;
a)
update_all=1
;;
x)
check_root
# Trigger some IO on ESP path to be sure it's mounted by autofs if it's the case
# Otherwise upgrading systemd may cause ESP partition not mounted at the time dracut attempt to write new image
stat "$ESP_PATH" >/dev/null
;;
y)
check_root
while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r kernel_name < "/${line}"
path="$(grep -lE "^${kernel_name}\$" /usr/lib/modules/*/pkgbase)"
kernel_version=$(basename "${path%/pkgbase}")
efi_image="$BOOT_PATH/$kernel_name.efi"
efi_image_fallback="$BOOT_PATH/$kernel_name-fallback.efi"
declare -a images=()
images+=($efi_image)
images+=($efi_image_fallback)
for image in "${images[@]}";
do
if [ -f ]; then
echo "==> Removing $image..."
rm -f $image
fi
done
fi
done
exit 0
;;
z)
check_root
while read -r line; do
if [[ $line =~ ^usr/lib/modules/([^/]+)/pkgbase$ ]]; then
read -r kernel_name < "/${line}"
kernels["${kernel_name}"]="${BASH_REMATCH[1]}"
else
update_all=1
break
fi
done
;;
h)
usage
;;
*)
usage
;;
esac
done
if (( update_all )); then
for kernel_path in /usr/lib/modules/*; do
[ -f "$kernel_path/pkgbase" ] || continue
kernel_version=$(basename $kernel_path)
kernel_dir="/usr/lib/modules/$kernel_version"
pkgbase="$kernel_dir/pkgbase"
kernel_name=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "$pkgbase")
if [ -n "$kernel_name" ]; then
kernels["$kernel_name"]="$kernel_version"
fi
done
fi
function gen_image() {
check_root
kernel_name="$1"
kernel_version="$2"
kernel_dir="/usr/lib/modules/$kernel_version"
if [ -f "/etc/kernel/cmdline" ]; then
cmdline=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' "/etc/kernel/cmdline")
else
cmdline=$(sed -e 's/^[[:space:]]//g' -e 's/[[:space:]]$//g' -e 's/initrd.*$//g' "/proc/cmdline")
fi
vmlinuz="$kernel_dir/vmlinuz"
initrd_image="$(mktemp)"
initrd_image_fallback="$(mktemp)"
efi_image="$BOOT_PATH/$kernel_name.efi"
efi_image_fallback="$BOOT_PATH/$kernel_name-fallback.efi"
echo "==> Building initrd image $kernel_name $initrd_image"
dracut --force --hostonly --no-hostonly-cmdline --kver "$kernel_version" "$initrd_image"
declare -a ukify_args=("${ukify_global_args[@]}")
ukify_args+=(--cmdline "$cmdline")
ukify_args+=(--uname "$kernel_version")
ukify_args+=(--os-release "/etc/os-release")
ukify_args+=(--output "$efi_image")
ukify_args+=("$vmlinuz" "$initrd_image")
echo "==> Ukify image $kernel_name $efi_image"
/usr/lib/systemd/ukify "${ukify_args[@]}"
echo "==> Building initrd image $kernel_name $initrd_image_fallback"
dracut --force --kver "$kernel_version" "$initrd_image_fallback"
declare -a ukify_args=("${ukify_global_args[@]}")
ukify_args+=(--cmdline "$cmdline")
ukify_args+=(--uname "$kernel_version")
ukify_args+=(--os-release "/etc/os-release")
ukify_args+=(--output "$efi_image_fallback")
ukify_args+=("$vmlinuz" "$initrd_image_fallback")
echo "==> Ukify image $kernel_name $efi_image_fallback"
/usr/lib/systemd/ukify "${ukify_args[@]}"
rm -f "$initrd_image"
rm -f "$initrd_image_fallback"
}
for kernel_name in "${!kernels[@]}"; do
kernel_version="${kernels[$kernel_name]}"
gen_image "$kernel_name" "$kernel_version"
done

11
make.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
echo -n > sha256sum.txt
for i in *;
do
([ -f $i ] && [ "$i" != "PKGBUILD" ] && [ "$i" != "$(basename $0)" ] && [ "$i" != "sha256sum.txt" ] ) || continue
echo $(sha256sum $i) | column -t >> sha256sum.txt
done
makepkg --printsrcinfo > .SRCINFO

7
sha256sum.txt Normal file
View File

@ -0,0 +1,7 @@
e9592f4f738e8ac70044db1e3f0c4839bc07f37662d5dbc221230cf1617a6b4d 10-dracut-ukify-pre-install.hook
341cd01546d840e7401f7bec868a78e2f6ca12563e93d993a07bc51efe674ed0 60-dracut-ukify-remove.hook
08225b2c3f5e2a734561b5fa9a3e84060dfffd85b2898adb0fff0ce3b068b4d0 90-dracut-ukify-install.hook
45de7b379bca66b96327b0a7957fefce5acc53968828cc412f5e5d0f13c4151f dracut-ukify
8486a10c4393cee1c25392769ddd3b2d6c242d6ec7928e1414efff7dfb2f07ef LICENSE
42a0e788242b943cebe5ed2b7e47f2c97d23836e0abd41c8d2c1a81ba443fe83 melawy-dracut-ukify-0-1-any.pkg.tar.zst
3b388b0772ec118899c52aea924f6e03b575dfea368ecfb846cd3fcdf23c63eb README.md