Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements for alpine initramfs #484

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/alpine/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ copy:
version: ">=0"
source: "/usr/bin/immucore"
destination: "/usr/bin/immucore"
- package:
category: "system"
name: "kairos-agent"
version: ">=0"
source: "/usr/bin/kairos-agent"
destination: "/usr/bin/kairos-agent"
package_dir: "/package"
prelude:
- apk update
- apk add linux-rpi4 mkinitfs linux-firmware-none udev lvm2 findmnt rsync parted cryptsetup
# multipath-tools and cryptsetup is needed to bring modules and udev rules
- apk add linux-rpi4 linux-firmware-none mkinitfs eudev eudev-hwids mdadm-udev device-mapper-udev lvm2 findmnt rsync parted cryptsetup multipath-tools openrc blkid
steps:
- kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}"
- mkdir -p /package/boot
Expand Down Expand Up @@ -45,7 +52,8 @@ copy:
package_dir: "/package"
prelude:
- apk update
- apk add linux-lts linux-firmware-none mkinitfs udev lvm2 findmnt rsync parted cryptsetup
# multipath-tools and cryptsetup is needed to bring modules and udev rules
- apk add linux-lts linux-firmware-none mkinitfs eudev eudev-hwids mdadm-udev device-mapper-udev lvm2 findmnt rsync parted cryptsetup multipath-tools openrc blkid
steps:
- kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}"
- mkdir -p /package/boot
Expand Down
4 changes: 2 additions & 2 deletions packages/alpine/collection.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
packages:
- name: "alpine"
category: "distro-kernel"
version: "6.1.56-1"
version: "6.1.56-2"
description: "Provides kernel and custom initrd for alpine"
labels:
autobump.strategy: "custom"
Expand All @@ -14,7 +14,7 @@ packages:
package.version: "6.1.56"
- name: "alpine-rpi"
category: "distro-kernel"
version: "6.1.55-1"
version: "6.1.55-2"
description: "Provides kernel and custom initrd for alpine"
labels:
autobump.strategy: "custom"
Expand Down
8 changes: 6 additions & 2 deletions packages/alpine/files/immucore.files
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/usr/bin/immucore
/usr/bin/kairos-agent
/sbin/lvm
/sbin/cryptsetup
/sbin/blkid
/bin/findmnt
/bin/udevadm
/sbin/udevadm
/sbin/udevd
/sbin/dmsetup
/etc/udev/*
/lib/udev/*
/usr/lib/udev/*
/usr/lib/libudev*
/usr/bin/rsync
/usr/sbin/parted
/usr/sbin/parted
/sbin/openrc
/sbin/openrc-run
40 changes: 38 additions & 2 deletions packages/alpine/files/initramfs-init
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ eudev_start()
cat "$file" >> /etc/udev/rules.d/"$dest" && rm -f "$file"
done

udevadm hwdb --update

# Populating /dev with existing devices through uevents
udevadm trigger --type=subsystems --action=add
udevadm trigger --type=devices --action=add
Expand Down Expand Up @@ -238,6 +240,14 @@ is_url() {
esac
}

rd_break() {
if grep -q "rd.break=$1" /proc/cmdline; then
echo "initramfs emergency recovery shell launched" > "$ROOT"/dev/kmsg
echo "initramfs emergency recovery shell launched"
exec /bin/busybox sh
fi
}

/bin/busybox mkdir -p "$ROOT"/usr/bin \
"$ROOT"/usr/sbin \
"$ROOT"/proc \
Expand Down Expand Up @@ -299,9 +309,10 @@ done

# hide kernel messages
# dmesg -n 1
rd_break pre-modprobe
# load available drivers to get access to media
ebegin "Loading boot drivers"
modprobe -a ahci virtio_blk virtio_net virtio_console virtio_pci nvme overlay usb_storage libata cdrom sr_mod iso9660 loop squashfs simpledrm ext4 tpm dm_mod 2> /dev/null
modprobe -a ahci virtio_blk virtio_net virtio_console virtio_pci nvme overlay usb_storage libata cdrom sr_mod iso9660 loop squashfs simpledrm ext4 tpm dm_mod dm_crypt 2> /dev/null
if [ -f "$ROOT"/etc/modules ] ; then
sed 's/\#.*//g' < /etc/modules |
while read module args; do
Expand All @@ -315,17 +326,24 @@ fi

eend

rd_break post-modprobe

rd_break pre-udev
# persistent device names from eudev in order for immucore to mount stuff
[ -x "/sbin/udevadm" ] && eudev_start
rd_break post-udev

rd_break pre-network
# Mount network if we got rd.neednet=1 or netboot
if grep -q "rd.neednet=1" /proc/cmdline || grep -q netboot /proc/cmdline ;then
configure_ip
fi
rd_break post-network

# Path for booting from netboot
if grep -q netboot /proc/cmdline; then
echo "Netbooting"
rd_break pre-netboot

for x in $(cat /proc/cmdline); do
# shellcheck disable=SC2039
Expand Down Expand Up @@ -353,10 +371,12 @@ if grep -q netboot /proc/cmdline; then
retry 5 losetup /dev/loop0 /tmp/rootfs.squashfs
eend $?
sync
rd_break post-netboot
fi

# Path for booting from livecd
if grep -q cdroot /proc/cmdline ;then
rd_break pre-livecd
echo "Mounting LiveCD"
sync
# Create mountpoints
Expand All @@ -377,10 +397,12 @@ if grep -q cdroot /proc/cmdline ;then
retry 5 losetup /dev/loop0 /media/root-ro/rootfs.squashfs
eend $?
sync
rd_break post-livecd
fi

# shared path for netboot and livecd, we expect the rootfs to be already in /dev/loop0
if grep -q cdroot /proc/cmdline || grep -q netboot /proc/cmdline;then
rd_break pre-mounts
# Mount loop device into the rootfsbase
ebegin "Mount loop device into rootfsbase"
retry 5 mount /dev/loop0 /run/rootfsbase
Expand Down Expand Up @@ -412,17 +434,24 @@ if grep -q cdroot /proc/cmdline || grep -q netboot /proc/cmdline;then
eend $?
fi
done
rd_break post-mounts
# stop udevd, will be relaunched by openrc
udevadm control --exit

# shellcheck disable=SC2093
exec switch_root "$sysroot" "$INIT"
echo "initramfs emergency recovery shell launched"
exec /bin/busybox sh
fi

rd_break pre-immucore
# Path for booting active/passive/recovery
ebegin "Run immucore"
immucore
eend $?

rd_break post-immucore

# by now the system should be mounted in /sysroot
if [ -f "$sysroot/etc/.default_boot_services" ]; then
# add some boot services by default
Expand Down Expand Up @@ -474,21 +503,24 @@ else
fi


rd_break pre-binds
# Mount bind system mounts to sysroot to keep them going
mkdir -p $sysroot/sys $sysroot/proc $sysroot/dev $sysroot/run
mount -o bind /sys $sysroot/sys
mount -o bind /proc $sysroot/proc
mount -o bind /dev $sysroot/dev
mount -o bind /run $sysroot/run
rd_break post-binds

# remount according default fstab from package
if [ -z "$has_fstab" ] && [ -f "$sysroot"/etc/fstab ]; then
remount_fstab_entry "$sysroot"/etc/fstab
fi


rd_break pre-console
# fix inittab if alternative console
setup_inittab_console
rd_break post-console

! [ -f "$sysroot"/etc/resolv.conf ] && [ -f /etc/resolv.conf ] && \
cp /etc/resolv.conf "$sysroot"/etc
Expand All @@ -499,6 +531,10 @@ if [ ! -x "${sysroot}${INIT}" ]; then
/bin/busybox sh
fi

rd_break pre-switch
# stop udevd, will be relaunched by openrc
udevadm control --exit

# switch over to new root
echo ""
# shellcheck disable=SC2093
Expand Down
2 changes: 1 addition & 1 deletion packages/alpine/files/mkinitfs.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
features="ata base cdrom ext4 ext2 keymap kms mmc lvm nvme raid scsi usb network dhcp virtio zfs squashfs immucore tpm"
features="ata base cdrom ext4 ext2 keymap kms mmc lvm nvme raid scsi usb network dhcp virtio zfs squashfs immucore tpm cryptsetup kms mmc xfs"
Loading