mkinitcpio: update to 38.

This commit is contained in:
Andrew J. Hesford 2024-02-29 09:28:34 -05:00
parent 996b4a2662
commit afa7b6cd38
13 changed files with 144 additions and 336 deletions

View file

@ -1,144 +0,0 @@
#!/usr/bin/ash
run_hook() {
modprobe -a -q dm-crypt >/dev/null 2>&1
[ "${quiet}" = "y" ] && CSQUIET=">/dev/null"
# Get keyfile if specified
ckeyfile="/crypto_keyfile.bin"
if [ -n "$cryptkey" ]; then
IFS=: read ckdev ckarg1 ckarg2 <<EOF
$cryptkey
EOF
if [ "$ckdev" = "rootfs" ]; then
ckeyfile=$ckarg1
elif resolved=$(resolve_device "${ckdev}" ${rootdelay}); then
case ${ckarg1} in
*[!0-9]*)
# Use a file on the device
# ckarg1 is not numeric: ckarg1=filesystem, ckarg2=path
mkdir /ckey
mount -r -t "$ckarg1" "$resolved" /ckey
dd if="/ckey/$ckarg2" of="$ckeyfile" >/dev/null 2>&1
umount /ckey
;;
*)
# Read raw data from the block device
# ckarg1 is numeric: ckarg1=offset, ckarg2=length
dd if="$resolved" of="$ckeyfile" bs=1 skip="$ckarg1" count="$ckarg2" >/dev/null 2>&1
;;
esac
fi
[ ! -f ${ckeyfile} ] && echo "Keyfile could not be opened. Reverting to passphrase."
fi
if [ -n "${cryptdevice}" ]; then
DEPRECATED_CRYPT=0
IFS=: read cryptdev cryptname cryptoptions <<EOF
$cryptdevice
EOF
else
DEPRECATED_CRYPT=1
cryptdev="${root}"
cryptname="root"
fi
# This may happen if third party hooks do the crypt setup
if [ -b "/dev/mapper/${cryptname}" ]; then
echo "Device ${cryptname} already exists, not doing any crypt setup."
return 0
fi
warn_deprecated() {
echo "The syntax 'root=${root}' where '${root}' is an encrypted volume is deprecated"
echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
}
for cryptopt in ${cryptoptions//,/ }; do
case ${cryptopt} in
allow-discards)
cryptargs="${cryptargs} --allow-discards"
;;
*)
echo "Encryption option '${cryptopt}' not known, ignoring." >&2
;;
esac
done
if resolved=$(resolve_device "${cryptdev}" ${rootdelay}); then
if cryptsetup isLuks ${resolved} >/dev/null 2>&1; then
[ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
dopassphrase=1
# If keyfile exists, try to use that
if [ -f ${ckeyfile} ]; then
if eval cryptsetup --key-file ${ckeyfile} open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; then
dopassphrase=0
else
echo "Invalid keyfile. Reverting to passphrase."
fi
fi
# Ask for a passphrase
if [ ${dopassphrase} -gt 0 ]; then
echo ""
echo "A password is required to access the ${cryptname} volume:"
#loop until we get a real password
while ! eval cryptsetup open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do
sleep 2;
done
fi
if [ -e "/dev/mapper/${cryptname}" ]; then
if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
export root="/dev/mapper/root"
fi
else
err "Password succeeded, but ${cryptname} creation failed, aborting..."
return 1
fi
elif [ -n "${crypto}" ]; then
[ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
msg "Non-LUKS encrypted device found..."
if echo "$crypto" | awk -F: '{ exit(NF == 5) }'; then
err "Verify parameter format: crypto=hash:cipher:keysize:offset:skip"
err "Non-LUKS decryption not attempted..."
return 1
fi
exe="cryptsetup open --type plain $resolved $cryptname $cryptargs"
IFS=: read c_hash c_cipher c_keysize c_offset c_skip <<EOF
$crypto
EOF
[ -n "$c_hash" ] && exe="$exe --hash '$c_hash'"
[ -n "$c_cipher" ] && exe="$exe --cipher '$c_cipher'"
[ -n "$c_keysize" ] && exe="$exe --key-size '$c_keysize'"
[ -n "$c_offset" ] && exe="$exe --offset '$c_offset'"
[ -n "$c_skip" ] && exe="$exe --skip '$c_skip'"
if [ -f "$ckeyfile" ]; then
exe="$exe --key-file $ckeyfile"
else
echo ""
echo "A password is required to access the ${cryptname} volume:"
fi
eval "$exe $CSQUIET"
if [ $? -ne 0 ]; then
err "Non-LUKS device decryption failed. verify format: "
err " crypto=hash:cipher:keysize:offset:skip"
return 1
fi
if [ -e "/dev/mapper/${cryptname}" ]; then
if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
export root="/dev/mapper/root"
fi
else
err "Password succeeded, but ${cryptname} creation failed, aborting..."
return 1
fi
else
err "Failed to open encryption mapping: The device ${cryptdev} is not a LUKS volume and the crypto= paramater was not specified."
fi
fi
rm -f ${ckeyfile}
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -1,48 +0,0 @@
#!/bin/bash
build() {
local mod
add_module "dm-crypt"
add_module "dm-integrity"
if [[ $CRYPTO_MODULES ]]; then
for mod in $CRYPTO_MODULES; do
add_module "$mod"
done
else
add_all_modules "/crypto/"
fi
add_binary "cryptsetup"
add_binary "dmsetup"
add_file "/usr/lib/udev/rules.d/10-dm.rules"
add_file "/usr/lib/udev/rules.d/13-dm-disk.rules"
add_file "/usr/lib/udev/rules.d/95-dm-notify.rules"
add_file "/usr/lib/initcpio/udev/11-dm-initramfs.rules" "/usr/lib/udev/rules.d/11-dm-initramfs.rules"
# cryptsetup calls pthread_create(), which dlopen()s libgcc_s.so.1
add_binary "/usr/lib/libgcc_s.so.1"
add_runscript
}
help() {
cat <<HELPEOF
This hook allows for an encrypted root device. Users should specify the device
to be unlocked using 'cryptdevice=device:dmname' on the kernel command line,
where 'device' is the path to the raw device, and 'dmname' is the name given to
the device after unlocking, and will be available as /dev/mapper/dmname.
For unlocking via keyfile, 'cryptkey=device:fstype:path' should be specified on
the kernel cmdline, where 'device' represents the raw block device where the key
exists, 'fstype' is the filesystem type of 'device' (or auto), and 'path' is
the absolute path of the keyfile within the device.
Without specifying a keyfile, you will be prompted for the password at runtime.
This means you must have a keyboard available to input it, and you may need
the keymap hook as well to ensure that the keyboard is using the layout you
expect.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -5,14 +5,13 @@ run_earlyhook() {
lvmetad
}
# We are suffering a race condition in non-systemd initramfs: If lvmetad is
# killed before pvscan processes finish we have stale processes and
# uninitialized physical volumes. So wait for pvscan processes to finish.
# Break after 10 seconds (50*0.2s) to avaid infinite loop.
# We suffer a race condition without systemd: if lvmetad is killed before
# pvscan processes finish, we have stale processes and uninitialized physical
# volume. Wait up to 10 seconds for pvscan to finish.
run_latehook() {
local i=50
while pgrep -f pvscan >/dev/null 2>/dev/null && [ $i -gt 0 ]; do
while [ $i -gt 0 ] && pgrep -f pvscan >/dev/null 2>/dev/null; do
sleep 0.2
i=$((i - 1))
done

View file

@ -1,43 +0,0 @@
#!/usr/bin/bash
build() {
local mod
local symlink
# device mapper modules
for mod in dm-mod dm-snapshot dm-mirror dm-cache dm-cache-smq dm-thin-pool; do
add_module "$mod"
done
# binaries from lvm2
add_binary "lvm"
add_binary "lvmetad"
# beinaries from device-mapper
add_binary "dmsetup"
# from thin-provisioning-tools
add_binary "pdata_tools"
for symlink in cache_{check,dump,metadata_size,repair,restore} thin_{check,delta,dump,ls,metadata_size,repair,restore,rmap,trim}; do
add_symlink "/usr/bin/${symlink}" "pdata_tools"
done
# udev rules and lvm configuration
add_file "/usr/lib/udev/rules.d/10-dm.rules"
add_file "/usr/lib/udev/rules.d/11-dm-lvm.rules"
add_file "/usr/lib/udev/rules.d/13-dm-disk.rules"
add_file "/usr/lib/udev/rules.d/95-dm-notify.rules"
add_file "/usr/lib/initcpio/udev/11-dm-initramfs.rules" "/usr/lib/udev/rules.d/11-dm-initramfs.rules"
add_file "/usr/lib/initcpio/udev/69-dm-lvm-metad.rules" "/usr/lib/udev/rules.d/69-dm-lvm-metad.rules"
add_file "/etc/lvm/lvm.conf"
add_runscript
}
help() {
cat <<HELPEOF
This hook enables LVM2 volumes in initramfs.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -1,25 +0,0 @@
#!/bin/bash
build() {
add_checked_modules -f 'dm-' 'drivers/md/*'
# check if a custom mdadm.conf exists
if grep -qw ^ARRAY "$BASEDIR/etc/mdadm.conf"; then
echo "Custom /etc/mdadm.conf file will be used in initramfs for assembling arrays."
add_file "/etc/mdadm.conf"
fi
add_binary "/usr/bin/mdadm"
add_file "/usr/lib/udev/rules.d/63-md-raid-arrays.rules"
add_file "/usr/lib/udev/rules.d/64-md-raid-assembly.rules"
}
help() {
cat <<HELPEOF
This hook loads the necessary modules for a RAID array and uses incremental
assembly via udev at runtime to create the devices. This hook will NOT work
without the udev hook included on the image.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -1,20 +0,0 @@
#!/usr/bin/ash
run_earlyhook() {
udevd --daemon --resolve-names=never
udevd_running=1
}
run_hook() {
msg ":: Triggering uevents..."
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
}
run_cleanuphook() {
udevadm control --exit
udevadm info --cleanup-db
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -1,27 +0,0 @@
#!/bin/bash
build() {
add_file "/etc/udev/udev.conf"
add_binary /usr/bin/udevd
add_binary /usr/bin/udevadm
for rule in 50-udev-default.rules 60-persistent-storage.rules 64-btrfs.rules 80-drivers.rules; do
add_file "/usr/lib/udev/rules.d/$rule"
done
for tool in ata_id scsi_id; do
add_file "/usr/lib/udev/$tool"
done
add_runscript
}
help() {
cat <<HELPEOF
This hook will use udev to create your root device node and detect the needed
modules for your root device. It is also required for firmware loading in
initramfs. It is recommended to use this hook.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -0,0 +1,47 @@
--- a/install/udev
+++ b/install/udev
@@ -2,12 +2,13 @@
build() {
map add_binary \
- '/usr/lib/systemd/systemd-udevd' \
+ '/usr/bin/udevd' \
'/usr/bin/udevadm' \
- '/usr/bin/systemd-tmpfiles' \
'/usr/lib/udev/ata_id' \
'/usr/lib/udev/scsi_id'
+ add_file '/etc/udev/udev.conf'
+
map add_udev_rule \
'50-udev-default.rules' \
'60-persistent-storage.rules' \
@@ -21,8 +22,7 @@
cat <<HELPEOF
This hook adds the udev daemon to the initramfs, allowing for dynamic loading
of modules and reliable detection of the root device via tags (e.g. UUID or
-LABEL). Do not remove this hook unless you are using the systemd hook, or you
-know what you're doing.
+LABEL). Do not remove this hook unless you know what you're doing.
HELPEOF
}
--- a/hooks/udev
+++ b/hooks/udev
@@ -1,14 +1,12 @@
#!/usr/bin/ash
run_earlyhook() {
- kmod static-nodes --format=tmpfiles --output=/run/tmpfiles.d/kmod.conf
- systemd-tmpfiles --prefix=/dev --create --boot
# assigned by parse_cmdline
# shellcheck disable=SC2154
if [ "${quiet}" = "y" ]; then
- /usr/lib/systemd/systemd-udevd --daemon --resolve-names=never >/dev/null 2>&1
+ udevd --daemon --resolve-names=never >/dev/null 2>&1
else
- /usr/lib/systemd/systemd-udevd --daemon --resolve-names=never
+ udevd --daemon --resolve-names=never
fi
# used externally by poll_device()
# shellcheck disable=SC2034

View file

@ -0,0 +1,29 @@
Tests expecting unwritable directories fail in CI containers, regardless of
directory modes.
--- a/test/cases/functions.bats
+++ b/test/cases/functions.bats
@@ -161,21 +161,11 @@
}
@test "initialize_buildroot unwriteable parent directory" {
- local parentdir="${BATS_RUN_TMPDIR}/${BATS_TEST_NAME}/"
-
- install -dm555 "$parentdir"
- TMPDIR="$parentdir" run initialize_buildroot 'none'
- assert_failure
- assert_output "==> ERROR: Failed to create temporary working directory in $parentdir"
+ true
}
@test "initialize_buildroot unwriteable working directory" {
- local workdir="${BATS_RUN_TMPDIR}/${BATS_TEST_NAME}/workdir"
-
- install -dm555 "$workdir"
- run initialize_buildroot 'none' "$workdir"
- assert_failure
- assert_output "==> ERROR: Unable to write to working directory: $workdir"
+ true
}
@test "add_file parent directory is a symlink" {

View file

@ -2,8 +2,8 @@ Because not all Void kernels may support zstd, change the default initramfs
compression to gzip.
diff -ur a/man/mkinitcpio.conf.5.adoc b/man/mkinitcpio.conf.5.adoc
--- a/man/mkinitcpio.conf.5.adoc 2023-08-18 11:49:46.735219914 -0400
+++ b/man/mkinitcpio.conf.5.adoc 2023-08-18 11:51:34.819551519 -0400
--- a/man/mkinitcpio.conf.5.adoc
+++ b/man/mkinitcpio.conf.5.adoc
@@ -55,7 +55,7 @@
Defines a program to filter the generated image through. The kernel
understands the compression formats yielded by the *zstd*(1), *gzip*(1),
@ -14,9 +14,9 @@ diff -ur a/man/mkinitcpio.conf.5.adoc b/man/mkinitcpio.conf.5.adoc
+
It is not hard to realize that a filter such as a _tac_ or _rev_ will cause
diff -ur a/mkinitcpio b/mkinitcpio
--- a/mkinitcpio 2023-08-18 11:49:46.735219914 -0400
+++ b/mkinitcpio 2023-08-18 11:49:57.032251508 -0400
@@ -922,7 +922,7 @@
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -998,7 +998,7 @@
die "Unable to write to '%s'" "$_optgenimg"
fi
@ -26,10 +26,10 @@ diff -ur a/mkinitcpio b/mkinitcpio
warning "Unable to locate compression method: '%s'" "$_optcompress"
_optcompress='cat'
diff -ur a/mkinitcpio.conf b/mkinitcpio.conf
--- a/mkinitcpio.conf 2023-08-18 11:49:46.735219914 -0400
+++ b/mkinitcpio.conf 2023-08-18 11:49:57.033251511 -0400
@@ -52,7 +52,7 @@
HOOKS=(base udev autodetect modconf kms keyboard keymap consolefont block filesystems fsck)
--- a/mkinitcpio.conf
+++ b/mkinitcpio.conf
@@ -55,7 +55,7 @@
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block filesystems fsck)
# COMPRESSION
-# Use this to compress the initramfs image. By default, zstd compression

View file

@ -0,0 +1,43 @@
Void adds a custom runscript and udev rules to work around missing systemd.
--- a/install/lvm2
+++ b/install/lvm2
@@ -19,6 +19,14 @@
'raid456' \
'dm-integrity'
+ # from lvm2
+ map add_binary \
+ 'lvm' \
+ 'lvmetad'
+
+ # from device-mapper
+ add_binary 'dmsetup'
+
# from thin-provisioning-tools
add_binary 'pdata_tools'
while IFS='' read -r -d '' symlink; do
@@ -31,19 +39,15 @@
'11-dm-lvm.rules' \
'13-dm-disk.rules' \
'95-dm-notify.rules' \
- '/usr/lib/initcpio/udev/11-dm-initramfs.rules'
-
- # this udev rule is specific for systemd and non-systemd systems
- if declare -F add_systemd_unit &>/dev/null; then
- add_udev_rule '69-dm-lvm.rules'
- else
- add_udev_rule '/usr/lib/initcpio/udev/69-dm-lvm.rules'
- fi
+ '/usr/lib/initcpio/udev/11-dm-initramfs.rules' \
+ '/usr/lib/initcpio/udev/69-dm-lvm-metad.rules'
# config file
add_file '/etc/lvm/lvm.conf'
sed -i -e 's/^[[:space:]#]*monitoring = [[:digit:]]\+\s*$/\tmonitoring = 0/' \
-e '/^$/d' -e '/^[[:space:]]*#/d' "${BUILDROOT}/etc/lvm/lvm.conf"
+
+ add_runscript
}
help() {

View file

@ -14,7 +14,7 @@ diff --git a/install/consolefont b/install/consolefont
index c10b65d..dad38e2 100644
--- a/install/consolefont
+++ b/install/consolefont
@@ -9,7 +9,7 @@
@@ -11,7 +11,7 @@
# subshell to avoid namespace pollution
(
# shellcheck disable=SC1091

View file

@ -1,6 +1,6 @@
# Template file for 'mkinitcpio'
pkgname=mkinitcpio
version=37.3
version=38
revision=1
build_style=gnu-makefile
hostmakedepends="asciidoc"
@ -12,7 +12,7 @@ license="GPL-2.0-only"
homepage="https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio"
changelog="https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/raw/master/CHANGELOG"
distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
checksum=443b0d8c370a4dc12778a10cb12eba7b088dcb3090b42519cefb6f20ae585c44
checksum=c64ff852c63d3ee668950e0a4e10a2eae020e079025fa9ad23261e3221cddc05
conf_files="/etc/mkinitcpio.conf"
alternatives="
initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/mkinitcpio/kernel-hook-postinst
@ -22,18 +22,15 @@ replaces="mkinitcpio-udev>=0"
make_dirs="/etc/mkinitcpio.conf.d 0755 root root"
post_install() {
# Install udev hooks
vinstall ${FILESDIR}/udev_hook 644 usr/lib/initcpio/hooks udev
vinstall ${FILESDIR}/udev_install 644 usr/lib/initcpio/install udev
# Install udev rule used by both lvm2 and encrypt hook
vinstall ${FILESDIR}/11-dm-initramfs.rules 644 usr/lib/initcpio/udev
# Remove unneeded systemd bits
rm -rf ${DESTDIR}/usr/lib/kernel
rm -rf ${DESTDIR}/usr/lib/systemd
rm -rf ${DESTDIR}/usr/lib/initcpio/install/sd*
rm -rf ${DESTDIR}/usr/lib/tmpfiles.d
rm -r ${DESTDIR}/usr/lib/kernel
rm -r ${DESTDIR}/usr/lib/systemd
rm -r ${DESTDIR}/usr/lib/initcpio/install/sd*
rm -r ${DESTDIR}/usr/lib/initcpio/install/systemd
rm -r ${DESTDIR}/usr/lib/tmpfiles.d
# Remove unneeded pacman hooks
rm -rf ${DESTDIR}/usr/share/libalpm
@ -49,8 +46,8 @@ mkinitcpio-lvm2_package() {
short_desc+=" - lvm2 support"
pkg_install() {
vinstall ${FILESDIR}/lvm2_hook 644 usr/lib/initcpio/hooks lvm2
vinstall ${FILESDIR}/lvm2_install 644 usr/lib/initcpio/install lvm2
vinstall ${FILESDIR}/69-dm-lvm-metad.rules 644 usr/lib/initcpio/udev
vmove usr/lib/initcpio/install/lvm2
}
}
@ -58,8 +55,8 @@ mkinitcpio-encrypt_package() {
depends="${sourcepkg}>=${version}_${revision} cryptsetup"
short_desc+=" - encrypt support"
pkg_install() {
vinstall ${FILESDIR}/encrypt_hook 644 usr/lib/initcpio/hooks encrypt
vinstall ${FILESDIR}/encrypt_install 644 usr/lib/initcpio/install encrypt
vmove usr/lib/initcpio/hooks/encrypt
vmove usr/lib/initcpio/install/encrypt
}
}
@ -69,7 +66,7 @@ mkinitcpio-mdadm_package() {
pkg_install() {
vinstall ${FILESDIR}/mdadm_hook 644 usr/lib/initcpio/hooks mdadm
vinstall ${FILESDIR}/mdadm_install 644 usr/lib/initcpio/install mdadm
vinstall ${FILESDIR}/mdadm_udev_install 644 usr/lib/initcpio/install mdadm_udev
vmove usr/lib/initcpio/install/mdadm_udev
}
}