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
+116 -21

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 -d /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
# Pre-download linux-aarch64 and create a local pacman repo so mkarchiso
+116 -19
View File
@@ -146,31 +146,128 @@ rm -f "$PROFILE/packages.x86_64"
# ── 3. airootfs overlay — files that land in the live system ─────────
AIROOTFS="$PROFILE/airootfs"
# The archiso mkinitcpio hooks must be in the airootfs chroot so mkinitcpio
# can build a working initramfs. ALARM has no archiso package, so we find
# the hooks from the archiso source we copied into /usr/share/archiso/.
# The archiso mkinitcpio hooks are not shipped as separate files in the
# archiso git repo. ALARM has no archiso package. Write them here with
# correct module loading, device detection, and overlay setup.
mkdir -p "$AIROOTFS/usr/lib/initcpio/hooks" "$AIROOTFS/usr/lib/initcpio/install"
_find_hook() {
# Try releng airootfs first, then any other location under /usr/share/archiso
local name="$1"
local found
found=$(find /usr/share/archiso -path "*/initcpio/${name}/archiso" | head -1)
echo "${found}"
cat > "$AIROOTFS/usr/lib/initcpio/hooks/archiso" <<'HOOK'
#!/usr/bin/ash
run_earlyhook() {
# Load all modules needed for live boot before udev runs
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")
_hook_install=$(_find_hook "install")
run_hook() {
# 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
install -m755 "$_hook_runtime" "$AIROOTFS/usr/lib/initcpio/hooks/archiso"
install -m755 "$_hook_install" "$AIROOTFS/usr/lib/initcpio/install/archiso"
echo ">>> Official archiso mkinitcpio hooks installed (from $_hook_runtime)"
else
echo "ERROR: archiso mkinitcpio hooks not found under /usr/share/archiso — listing:"
find /usr/share/archiso -name "archiso" 2>/dev/null | sort
exit 1
archiso_mount_handler() {
local _newroot="${1}"
local _dev _sfs _arch _i
# Find ISO device by label; fall back to any iso9660 device
_i=0
while [ "${_i}" -lt 30 ]; do
if [ -n "${archisolabel}" ]; then
_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"
cat > "$AIROOTFS/etc/mkinitcpio.conf.d/archiso.conf" <<'MKCONF'