ISO/archiso/hooks/archiso_pxe_nbd
Gerardo Exequiel Pozzi 7483cffb30 [archiso] Use a mount handler in archiso_pxe_nbd hook
* Register a mount_hook if booted via PXE. This allows to do all needed
steps before and after calling archiso_mount_handler.

* umount and disconnect network device if copytoram=y

Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
2010-03-18 12:03:59 -03:00

80 lines
2.2 KiB
Bash

# vim: set ft=sh:
run_hook () {
local line i address netmask gateway dns0 dns1 rootserver rootpath filename
: > /ip_opts
if [ -n "${ip}" ]; then
# setup network and save some values
ipconfig "ip=${ip}" | while read line; do
# echo ":: ${line}"
if [ "${line#"IP-Config:"}" != "${line}" ]; then
continue
fi
line="$(echo ${line} | sed -e 's/ :/:/g;s/: /=/g')"
for i in ${line}; do
case "${i}" in
address=*)
echo "${i}" >> /ip_opts
;;
netmask=*)
echo "${i}" >> /ip_opts
;;
gateway=*)
echo "${i}" >> /ip_opts
;;
dns0=*)
echo "${i}" >> /ip_opts
;;
dns1=*)
echo "${i}" >> /ip_opts
;;
rootserver=*)
echo "${i}" >> /ip_opts
;;
rootpath=*)
echo "${i}" >> /ip_opts
;;
esac
done
done
. /ip_opts
echo "IP-Config: ${address}/${netmask}"
echo "IP-Config: gw: ${gateway} dns0: ${dns0} dns1: ${dns1}"
nbdserver=${rootserver}
mount_handler="archiso_pxe_nbd_mount_handler"
fi
}
archiso_pxe_nbd_mount_handler () {
newroot="${1}"
# Module autoloading like with loop devices does not work, doing manually...
modprobe nbd 2> /dev/null
while [ ! -b /dev/nbd0 ]; do
sleep 1
done
msg "::: Setup NBD from ${nbdserver}:9040 at /dev/nbd0"
if [ "${copytoram}" = "y" ]; then
nbd-client ${nbdserver} 9040 /dev/nbd0
else
nbd-client ${nbdserver} 9040 /dev/nbd0 -persist
fi
archisodevice=/dev/nbd0
archiso_mount_handler ${newroot}
if [ "${copytoram}" = "y" ]; then
umount ${newroot}/bootmnt
umount /bootmnt
msg "::: Disconnect NBD from ${nbdserver}:9040 at /dev/nbd0"
nbd-client -d /dev/nbd0
fi
}