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

Bring alpine initrd closer to other flavors #1088

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/alpine/collection.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
packages:
- name: "alpine"
category: "initrd"
version: "3.8.2"
version: "3.8.1-4"
description: "Provides custom initrd scripts for alpine"
# This syncs with the alpine version at https://gitlab.alpinelinux.org/alpine/mkinitfs/-/blob/master/initramfs-init.in?ref_type=heads
# any changes to the initramfs-init.in file should be looked at and backported if necessary
40 changes: 24 additions & 16 deletions packages/alpine/files/initramfs-init
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/bin/sh

VERSION=3.8.1-kairos2
VERSION=3.8.1-kairos4
INIT=/sbin/init
sysroot="$ROOT"/sysroot
# This is where we mount the livecd
liveroot=/run/initramfs/live
# This is where we mount the root squash file
rootfsbase=/run/rootfsbase
# This is the base dir for the overlay, it needs to be RW
rootRW=/run/overlay
# This is the name of the rootfs squash that comes in the livecd/netboot
rootfssquash=rootfs.squashfs

# some helpers
ebegin() {
Expand Down Expand Up @@ -201,9 +209,9 @@ retry() {
done
}

# uses the first "eth" interface with state 'up'.
# uses the first network interface with state 'up'.
ip_choose_if() {
for x in "$ROOT"/sys/class/net/eth*; do
for x in "$ROOT"/sys/class/net/*; do
if grep -iq up $x/operstate 2>/dev/null;then
[ -e "$x" ] && echo ${x##*/} && return
fi
Expand Down Expand Up @@ -375,16 +383,16 @@ if grep -q netboot /proc/cmdline; then
sync
# Create mountpoints
ebegin "Create mountpoints"
mkdir -p /media/root-rw /run/rootfsbase $sysroot/media/root-rw $sysroot/run/rootfsbase
mkdir -p $rootRW $rootfsbase $sysroot$rootRW $sysroot$rootfsbase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I understand correctly this:

/media/root-rw /run/rootfsbase $sysroot/media/root-rw $sysroot/run/rootfsbase

Becomes this

/run/overlay /run/rootfsbase $sysroot/run/overlay $sysroot/run/rootfsbase

so that means that /media/root-rw got changed to /run/overlay and same to the one that is prefixed by the $sysroot

why did the location change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to have it in line with what immucore does. We mount a writable /run/overlay and then submounts things there (/etc /var and so on, basically the ephemeral parts)

So in this case, this initrd was just doing its own thing. In this case it should not matter much as nothing should be using that, especially during live boot, but having ti be the same makes it easier to understand both what dracut does and what we do :)

eend $?

ebegin "Download rootfs"
wget -q "$root" -O /tmp/rootfs.squashfs
wget -q "$root" -O /tmp/$rootfssquash
eend $?

# Mount squashfs into loop device
ebegin "Mount rootfs as squashfs device"
retry 5 losetup /dev/loop0 /tmp/rootfs.squashfs
retry 5 losetup /dev/loop0 /tmp/$rootfssquash
eend $?
sync
rd_break post-netboot
Expand All @@ -398,20 +406,20 @@ if grep -q cdroot /proc/cmdline ;then
label=$(grep -o CDLABEL.* /proc/cmdline | cut -f 1 -d ' ' | cut -f 2 -d '=' )
# Create mountpoints
ebegin "Create mountpoints"
mkdir -p /media/root-ro /media/root-rw /run/rootfsbase $sysroot/media/root-ro $sysroot/media/root-rw $sysroot/run/rootfsbase
mkdir -p $liveroot $rootRW $rootfsbase $sysroot$liveroot $sysroot$rootRW $sysroot$rootfsbase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here similar comment, why did /media/root-ro got moved to /run/initramfs/live?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing. On dracut it automounts the livecd under that path but we were mounting it under root-ro because the upstream init from alpine did that. It makes no sense for us to deviate from what we expect and it shows, this was causing alpine to not autoinstall with a config bundled, because the livecd was mounted under that path and agent looks under /run/initramfs/live to read any configs coming from the live media.

eend $?
# Between udev starting, we loading the modules and the cdrom appearing sometimes there is a delay, so lets wait a bit here
ebegin "Waiting for Live Media to be available"
retry 10 test -e /dev/disk/by-label/$label
eend
# Mount read-only livecd
ebegin "Mount Live Media RO"
retry 10 mount /dev/disk/by-label/$label /media/root-ro
retry 10 mount /dev/disk/by-label/$label $liveroot
eend $?
sync
# Mount squashfs into loop device
ebegin "Mount rootfs as squashfs device"
retry 5 losetup /dev/loop0 /media/root-ro/rootfs.squashfs
retry 5 losetup /dev/loop0 $liveroot/$rootfssquash
eend $?
sync
rd_break post-livecd
Expand All @@ -422,18 +430,18 @@ 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
retry 5 mount /dev/loop0 $rootfsbase
eend $?
sync
# Mount writable overlay tmpfs
ebegin "Mount base overlay"
mount -t tmpfs -o "mode=0755,rw,size=25%" root-tmpfs /media/root-rw
mount -t tmpfs -o "mode=0755,rw,size=25%" root-tmpfs $rootRW
eend $?
sync
# Create additional mountpoints and do the overlay mount
mkdir -p /media/root-rw/work /media/root-rw/root
mkdir -p $rootRW/work $rootRW/root
ebegin "Mount rootfs overlay into sysroot"
mount -t overlay -o lowerdir=/run/rootfsbase,upperdir=/media/root-rw/root,workdir=/media/root-rw/work overlayfs $sysroot
mount -t overlay -o lowerdir=$rootfsbase,upperdir=$rootRW/root,workdir=$rootRW/work overlayfs $sysroot
eend $?
sync
rd_break pre-immucore
Expand All @@ -447,9 +455,9 @@ if grep -q cdroot /proc/cmdline || grep -q netboot /proc/cmdline;then
cat "$ROOT"/proc/mounts 2>/dev/null | while read DEV DIR TYPE OPTS ; do
# shellcheck disable=SC2166
if [ "$DIR" != "/" -a "$DIR" != "$sysroot" -a -d "$DIR" ]; then
ebegin "Moving $DIR to $sysroot/$DIR"
mkdir -p $sysroot/$DIR
mount -o move $DIR $sysroot/$DIR
ebegin "Moving $DIR to $sysroot$DIR"
mkdir -p $sysroot$DIR
mount -o move $DIR $sysroot$DIR
eend $?
fi
done
Expand Down
Loading