initcpio: add miso_pxe_nbd and miso_pxe_nfs

This commit is contained in:
udeved 2016-10-10 22:06:57 +02:00
parent 6af31b6e6e
commit da8b6a828a
7 changed files with 167 additions and 68 deletions

View file

@ -88,7 +88,9 @@ CPIOHOOKS = \
initcpio/hooks/miso_overlayfs \
initcpio/hooks/miso_loop_mnt \
initcpio/hooks/miso_pxe_common \
initcpio/hooks/miso_pxe_http
initcpio/hooks/miso_pxe_http \
initcpio/hooks/miso_pxe_nbd \
initcpio/hooks/miso_pxe_nfs
CPIOINST = \
initcpio/inst/miso \
@ -96,6 +98,8 @@ CPIOINST = \
initcpio/inst/miso_loop_mnt \
initcpio/inst/miso_pxe_common \
initcpio/inst/miso_pxe_http \
initcpio/inst/miso_pxe_nbd \
initcpio/inst/miso_pxe_nfs \
initcpio/inst/miso_kms
MAN_XML = \

View file

@ -127,11 +127,6 @@ testdevice() {
probedevice() {
if [[ -n "${ip}" && -n "${miso_http_srv}" && -f "${isomounts}" ]]; then
found="yes"
return
fi
# Loop device test every second up to some limit
if [ "x${usbdelay}" != "x" ]; then
waittime=${usbdelay}
@ -162,37 +157,34 @@ probedevice() {
fi
# still nothing found, we will look for boot device
if [ -z "${found}" ]; then
[ ${waitcount} -eq 0 ] && msg ":: Looking for boot device"
if [ "x${nocd}" = "x" ]; then
# Look for CD
cdroms=$( /bin/cat /proc/sys/dev/cdrom/info | { while read a b c; do
if [ "${a}" = "drive" -a "${b}" = "name:" ]; then
echo "${c}"
break
fi
done
} )
for i in ${cdroms}; do
MDEV=/dev/${i}
testdevice
if [ "x${MDEV}" != "x" ]; then
[ ${waitcount} -eq 0 ] && msg ":: Looking for boot device"
if [ "x${nocd}" = "x" ]; then
# Look for CD
cdroms=$( /bin/cat /proc/sys/dev/cdrom/info | { while read a b c; do
if [ "${a}" = "drive" -a "${b}" = "name:" ]; then
echo "${c}"
break
fi
done
fi
# Test partitions
if [ "x${MDEV}" = "x" ]; then
for d in /dev/sd[a-z][0-9]*; do
MDEV=${d}
testdevice
if [ "x${MDEV}" != "x" ]; then
break
fi
done
fi
} )
for i in ${cdroms}; do
MDEV=/dev/${i}
testdevice
if [ "x${MDEV}" != "x" ]; then
break
fi
done
fi
# Test partitions
if [ "x${MDEV}" = "x" ]; then
for d in /dev/sd[a-z][0-9]*; do
MDEV=${d}
testdevice
if [ "x${MDEV}" != "x" ]; then
break
fi
done
fi
[ "x${MDEV}" != "x" ] && break
@ -208,7 +200,7 @@ miso_mount_handler() {
# Probe all devices
probedevice
if [ -z "${found}" ]; then
echo ">> ERROR: unable to find boot device"
echo " Falling back to interactive prompt"

View file

@ -118,11 +118,6 @@ testdevice() {
probedevice() {
if [[ -n "${ip}" && -n "${miso_http_srv}" && -f "${isomounts}" ]]; then
found="yes"
return
fi
# Loop device test every second up to some limit
if [ "x${usbdelay}" != "x" ]; then
waittime=${usbdelay}
@ -153,37 +148,34 @@ probedevice() {
fi
# still nothing found, we will look for boot device
if [ -z "${found}" ]; then
[ ${waitcount} -eq 0 ] && msg ":: Looking for boot device"
if [ "x${nocd}" = "x" ]; then
# Look for CD
cdroms=$( /bin/cat /proc/sys/dev/cdrom/info | { while read a b c; do
if [ "${a}" = "drive" -a "${b}" = "name:" ]; then
echo "${c}"
break
fi
done
} )
for i in ${cdroms}; do
MDEV=/dev/${i}
testdevice
if [ "x${MDEV}" != "x" ]; then
[ ${waitcount} -eq 0 ] && msg ":: Looking for boot device"
if [ "x${nocd}" = "x" ]; then
# Look for CD
cdroms=$( /bin/cat /proc/sys/dev/cdrom/info | { while read a b c; do
if [ "${a}" = "drive" -a "${b}" = "name:" ]; then
echo "${c}"
break
fi
done
fi
# Test partitions
if [ "x${MDEV}" = "x" ]; then
for d in /dev/sd[a-z][0-9]*; do
MDEV=${d}
testdevice
if [ "x${MDEV}" != "x" ]; then
break
fi
done
fi
} )
for i in ${cdroms}; do
MDEV=/dev/${i}
testdevice
if [ "x${MDEV}" != "x" ]; then
break
fi
done
fi
# Test partitions
if [ "x${MDEV}" = "x" ]; then
for d in /dev/sd[a-z][0-9]*; do
MDEV=${d}
testdevice
if [ "x${MDEV}" != "x" ]; then
break
fi
done
fi
[ "x${MDEV}" != "x" ] && break
@ -200,7 +192,7 @@ miso_mount_handler() {
# Probe all devices
probedevice
if [ -z "${found}" ]; then
echo ">> ERROR: unable to find boot device"
echo " Falling back to interactive prompt"
@ -230,7 +222,7 @@ miso_mount_handler() {
# check if the overlay should be loaded
overlay_arg_available "$kernelarg"
if [ $? == 1 ] && [ "$kernelarg" != "" ]; then
continue
fi

View file

@ -0,0 +1,47 @@
# vim: set ft=sh:
run_earlyhook() {
if [[ -n "${ip}" && -n "${miso_nbd_srv}" ]]; then
# Module autoloading like with loop devices does not work, doing manually...
modprobe nbd 2> /dev/null
fi
}
run_hook() {
if [[ -n "${ip}" && -n "${miso_nbd_srv}" ]]; then
miso_nbd_srv=$(eval echo ${miso_nbd_srv})
[[ -z "${miso_nbd_name}" ]] && miso_nbd_name="miso"
mount_handler="miso_pxe_nbd_mount_handler"
fi
}
miso_pxe_nbd_mount_handler () {
newroot="${1}"
msg ":: Waiting for boot device..."
while ! poll_device /dev/nbd0 30; do
echo "ERROR: boot device didn't show up after 30 seconds..."
echo " Falling back to interactive prompt"
echo " You can try to fix the problem manually, log out when you are finished"
launch_interactive_shell
done
msg ":: Setup NBD from ${miso_nbd_srv} at /dev/nbd0"
if [[ "${copytoram}" != "n" ]]; then
nbd-client ${miso_nbd_srv} -N ${miso_nbd_name} /dev/nbd0
copytoram="y"
else
nbd-client ${miso_nbd_srv} -N ${miso_nbd_name} -systemd-mark -persist /dev/nbd0
fi
misodevice=/dev/nbd0
miso_mount_handler ${newroot}
if [[ "${copytoram}" == "y" ]]; then
msg ":: Disconnect NBD from ${miso_nbd_srv} at /dev/nbd0"
nbd-client -d /dev/nbd0
fi
}

View file

@ -0,0 +1,30 @@
# vim: set ft=sh:
run_hook() {
if [[ -n "${ip}" && -n "${miso_nfs_srv}" ]]; then
miso_nfs_srv=$(eval echo ${miso_nfs_srv})
[[ -n "${miso_nfs_opt}" ]] && miso_nfs_opt="-o ${miso_nfs_opt}"
mount_handler="miso_nfs_mount_handler"
fi
}
miso_nfs_mount_handler() {
newroot="${1}"
mkdir -p "/run/miso/bootmnt"
msg ":: Mounting '${miso_nfs_srv}'"
# Do not put "${miso_nfs_opt}" nfsmount fails!
if ! nfsmount ${miso_nfs_opt} "${miso_nfs_srv}" "/run/miso/bootmnt"; then
echo "ERROR: Mounting '${miso_nfs_srv}'"
echo " Falling back to interactive prompt"
echo " You can try to fix the problem manually, log out when you are finished"
launch_interactive_shell
fi
if [[ "${copytoram}" != "n" ]]; then
copytoram="y"
fi
miso_mount_handler ${newroot}
}

View file

@ -0,0 +1,17 @@
#!/bin/bash
build() {
add_module "nbd"
add_runscript
add_binary nbd-client
}
help() {
cat<<HELPEOF
This hook loads the necessary modules for boot via PXE and NBD.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et:

View file

@ -0,0 +1,17 @@
#!/bin/bash
build() {
add_module "nfs"
add_runscript
add_binary /usr/lib/initcpio/nfsmount /bin/nfsmount
}
help() {
cat <<HELPEOF
This hook loads the necessary modules for boot via PXE and NFS.
HELPEOF
}
# vim: set ft=sh ts=4 sw=4 et: