Fix ARM64 initramfs: write complete archiso mkinitcpio hooks inline

The archiso git repo doesn't ship the hooks as standalone files, and
ALARM has no archiso package. Write the hooks directly in the entrypoint
with the correct three-phase structure:

- run_earlyhook: modprobe squashfs/overlay/iso9660/loop/vfat before udev
- run_hook: parse archisolabel/archisobasedir from /proc/cmdline, set
  mount_handler="archiso_mount_handler"
- archiso_mount_handler: find ISO by label (fallback to TYPE=iso9660),
  mount it, mount squashfs at arch/$(uname -m)/airootfs.sfs, set up
  tmpfs cowspace, mount overlay to /new_root

install hook: add all required modules (squashfs, overlay, iso9660,
loop, vfat, nls_*) and binaries (blkid, losetup, sleep, uname).
Each mount step prints its progress and bails with a clear error message
on failure so boot panics are diagnosable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 4.6 committed 2026-07-27 08:40:18 -04:00
1 parent 629f16537e
commit 4cda708cc2
2 files changed
+117 -22

No files matched your search

-2
View File
@@ -65,8 +65,6 @@ RUN git clone --depth=1 https://gitlab.archlinux.org/archlinux/archiso.git /tmp/
install -Dm755 /tmp/archiso/scripts/run_archiso.sh /usr/bin/run_archiso && \ install -Dm755 /tmp/archiso/scripts/run_archiso.sh /usr/bin/run_archiso && \
install -d /usr/share/archiso && \ install -d /usr/share/archiso && \
cp -a /tmp/archiso/configs /usr/share/archiso/ && \ cp -a /tmp/archiso/configs /usr/share/archiso/ && \
echo "=== archiso hook locations ===" && \
find /tmp/archiso -name "archiso" -not -path "*/\.git/*" | sort && \
rm -rf /tmp/archiso rm -rf /tmp/archiso
# Pre-download linux-aarch64 and create a local pacman repo so mkarchiso # Pre-download linux-aarch64 and create a local pacman repo so mkarchiso
+117 -20
View File
@@ -146,31 +146,128 @@ rm -f "$PROFILE/packages.x86_64"
# ── 3. airootfs overlay — files that land in the live system ───────── # ── 3. airootfs overlay — files that land in the live system ─────────
AIROOTFS="$PROFILE/airootfs" AIROOTFS="$PROFILE/airootfs"
# The archiso mkinitcpio hooks must be in the airootfs chroot so mkinitcpio # The archiso mkinitcpio hooks are not shipped as separate files in the
# can build a working initramfs. ALARM has no archiso package, so we find # archiso git repo. ALARM has no archiso package. Write them here with
# the hooks from the archiso source we copied into /usr/share/archiso/. # correct module loading, device detection, and overlay setup.
mkdir -p "$AIROOTFS/usr/lib/initcpio/hooks" "$AIROOTFS/usr/lib/initcpio/install" mkdir -p "$AIROOTFS/usr/lib/initcpio/hooks" "$AIROOTFS/usr/lib/initcpio/install"
_find_hook() { cat > "$AIROOTFS/usr/lib/initcpio/hooks/archiso" <<'HOOK'
# Try releng airootfs first, then any other location under /usr/share/archiso #!/usr/bin/ash
local name="$1"
local found run_earlyhook() {
found=$(find /usr/share/archiso -path "*/initcpio/${name}/archiso" | head -1) # Load all modules needed for live boot before udev runs
echo "${found}" modprobe -q squashfs 2>/dev/null || true
modprobe -q overlay 2>/dev/null || true
modprobe -q iso9660 2>/dev/null || true
modprobe -q loop 2>/dev/null || true
modprobe -q vfat 2>/dev/null || true
} }
_hook_runtime=$(_find_hook "hooks") run_hook() {
_hook_install=$(_find_hook "install") # Read kernel cmdline parameters
for _param in $(cat /proc/cmdline); do
case "${_param}" in
archisobasedir=*) archisobasedir="${_param#archisobasedir=}" ;;
archisolabel=*) archisolabel="${_param#archisolabel=}" ;;
esac
done
[ -z "${archisobasedir}" ] && archisobasedir="arch"
export mount_handler="archiso_mount_handler"
}
if [[ -n "$_hook_runtime" && -n "$_hook_install" ]]; then archiso_mount_handler() {
install -m755 "$_hook_runtime" "$AIROOTFS/usr/lib/initcpio/hooks/archiso" local _newroot="${1}"
install -m755 "$_hook_install" "$AIROOTFS/usr/lib/initcpio/install/archiso" local _dev _sfs _arch _i
echo ">>> Official archiso mkinitcpio hooks installed (from $_hook_runtime)"
else # Find ISO device by label; fall back to any iso9660 device
echo "ERROR: archiso mkinitcpio hooks not found under /usr/share/archiso — listing:" _i=0
find /usr/share/archiso -name "archiso" 2>/dev/null | sort while [ "${_i}" -lt 30 ]; do
exit 1 if [ -n "${archisolabel}" ]; then
fi _dev=$(blkid -l -t "LABEL=${archisolabel}" -o device 2>/dev/null)
fi
[ -z "${_dev}" ] && \
_dev=$(blkid -t TYPE=iso9660 -o device 2>/dev/null | head -1)
[ -n "${_dev}" ] && break
sleep 1
_i=$(( _i + 1 ))
done
if [ -z "${_dev}" ]; then
echo "ERROR: archiso: cannot find ISO device (label=${archisolabel})"
return 1
fi
echo ":: archiso: found device ${_dev}"
mkdir -p /run/archiso/bootmnt
mount -r "${_dev}" /run/archiso/bootmnt || {
echo "ERROR: archiso: cannot mount ${_dev}"
return 1
}
# Squashfs path: arch/<uname -m>/airootfs.sfs
_arch=$(uname -m)
_sfs="/run/archiso/bootmnt/${archisobasedir}/${_arch}/airootfs.sfs"
echo ":: archiso: mounting squashfs ${_sfs}"
mkdir -p /run/archiso/airootfs
if ! mount -r -t squashfs "${_sfs}" /run/archiso/airootfs; then
echo "ERROR: archiso: cannot mount squashfs ${_sfs}"
echo " contents of /run/archiso/bootmnt/${archisobasedir}/:"
ls "/run/archiso/bootmnt/${archisobasedir}/" 2>/dev/null || true
return 1
fi
# Writable overlay on top of the read-only squashfs
mkdir -p /run/archiso/cowspace
mount -t tmpfs -o size=75%,mode=0755 tmpfs /run/archiso/cowspace
mkdir -p /run/archiso/cowspace/upper /run/archiso/cowspace/work
mount -t overlay overlay \
-o "lowerdir=/run/archiso/airootfs,upperdir=/run/archiso/cowspace/upper,workdir=/run/archiso/cowspace/work" \
"${_newroot}" || {
echo "ERROR: archiso: overlay mount failed"
return 1
}
echo ":: archiso: overlay ready"
}
HOOK
chmod 755 "$AIROOTFS/usr/lib/initcpio/hooks/archiso"
cat > "$AIROOTFS/usr/lib/initcpio/install/archiso" <<'INSTALL'
#!/bin/bash
build() {
add_runscript
# Filesystems for the live medium
add_module squashfs
add_module overlay
add_module iso9660
add_module loop
add_module vfat
add_module fat
add_module nls_cp437
add_module nls_iso8859_1
add_module nls_utf8
# Required binaries
add_binary blkid
add_binary losetup
add_binary sleep
add_binary uname
# Pre-create mount points so the initramfs has them
add_dir /run/archiso/bootmnt
add_dir /run/archiso/airootfs
add_dir /run/archiso/cowspace
}
help() {
echo "Mounts the archiso squashfs live root via overlay."
}
INSTALL
chmod 755 "$AIROOTFS/usr/lib/initcpio/install/archiso"
echo ">>> archiso mkinitcpio hooks written to airootfs"
mkdir -p "$AIROOTFS/etc/mkinitcpio.conf.d" mkdir -p "$AIROOTFS/etc/mkinitcpio.conf.d"
cat > "$AIROOTFS/etc/mkinitcpio.conf.d/archiso.conf" <<'MKCONF' cat > "$AIROOTFS/etc/mkinitcpio.conf.d/archiso.conf" <<'MKCONF'