getarg's trailing-= convention varies by mkinitcpio version and was returning empty even when archisosearchuuid was present in cmdline. Parse /proc/cmdline directly in ash — no external tools, no version sensitivity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.1 KiB
Bash
66 lines
2.1 KiB
Bash
#!/usr/bin/ash
|
|
|
|
archiso_mount_handler() {
|
|
local _new_root="$1"
|
|
local _uuid _label _basedir _dev _img _param
|
|
|
|
for _param in $(cat /proc/cmdline); do
|
|
case "$_param" in
|
|
archisosearchuuid=*) _uuid="${_param#archisosearchuuid=}" ;;
|
|
archisolabel=*) _label="${_param#archisolabel=}" ;;
|
|
archisobasedir=*) _basedir="${_param#archisobasedir=}" ;;
|
|
esac
|
|
done
|
|
: "${_basedir:=arch}"
|
|
|
|
if [ -z "${_uuid}" ] && [ -z "${_label}" ]; then
|
|
echo "archiso: neither archisosearchuuid nor archisolabel in kernel cmdline"
|
|
return 1
|
|
fi
|
|
|
|
local _waited=0
|
|
while [ "${_waited}" -lt 30 ]; do
|
|
if [ -n "${_uuid}" ]; then
|
|
_dev="$(blkid -l -o device -t UUID="${_uuid}" 2>/dev/null)"
|
|
else
|
|
_dev="$(blkid -l -o device -t LABEL="${_label}" 2>/dev/null)"
|
|
fi
|
|
[ -n "${_dev}" ] && break
|
|
sleep 1
|
|
_waited=$(( _waited + 1 ))
|
|
done
|
|
|
|
if [ -z "${_dev}" ]; then
|
|
echo "archiso: could not find boot medium (uuid=${_uuid} label=${_label})"
|
|
return 1
|
|
fi
|
|
|
|
echo "archiso: found boot medium ${_dev}"
|
|
|
|
mkdir -p /run/archiso/bootmnt
|
|
mount -r "${_dev}" /run/archiso/bootmnt || { echo "archiso: mount bootmnt failed"; return 1; }
|
|
|
|
_img="/run/archiso/bootmnt/${_basedir}/x86_64/airootfs.sfs"
|
|
if [ ! -e "${_img}" ]; then
|
|
echo "archiso: squashfs not found at ${_img}"
|
|
return 1
|
|
fi
|
|
|
|
mkdir -p /run/archiso/airootfs
|
|
mount -r -t squashfs "${_img}" /run/archiso/airootfs || { echo "archiso: squashfs mount failed"; return 1; }
|
|
|
|
mkdir -p /run/archiso/overlay
|
|
mount -t tmpfs tmpfs -o mode=0755 /run/archiso/overlay
|
|
mkdir -p /run/archiso/overlay/upper /run/archiso/overlay/work
|
|
|
|
mount -t overlay overlay \
|
|
-o lowerdir=/run/archiso/airootfs,upperdir=/run/archiso/overlay/upper,workdir=/run/archiso/overlay/work \
|
|
"${_new_root}" || { echo "archiso: overlay mount failed"; return 1; }
|
|
|
|
echo "archiso: live root mounted on ${_new_root}"
|
|
}
|
|
|
|
run_hook() {
|
|
mount_handler="archiso_mount_handler"
|
|
}
|