3 # A basic script to setup a PXE server enviroment for Arch Linux live-media.
4 # Contributed by Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
6 # Requires: dnsmasq and nbd packages
10 TMPDIR
=/tmp
/archiso-pxe-server
23 mkdir
-p ${TMPDIR}/mnt
24 mount
${ISO} ${TMPDIR}/mnt
-o ro
,loop
25 trap 'iso_umount' 0 1 2 15
32 echo "archiso-pxe-server version ${VERSION}"
34 echo "archiso-pxe-server [options]"
37 echo " -i [ip] ip address of the local interface to serve"
38 echo " (default: ${IP} )"
39 echo " -d [device] boot device of Arch Linux Live media"
40 echo " (default: ${DEVICE} )"
41 echo " -l [install_dir] install_dir of Arch Linux Live media"
42 echo " (default: ${INSTALL_DIR} )"
43 echo " -s [isofile] Arch Linux Live media iso image"
44 echo " (default: ${ISO} )"
45 echo " -m [mountpoint] path to [device] is mounted"
46 echo " (default: ${MNTPNT} )"
47 echo " -t [tftpboot] path to setup PXE enviroment"
48 echo " (default: ${TMPDIR} )"
49 echo " -j Skip dnsmasq start up"
50 echo " (default: ${DNSMASQ_SKIP} )"
51 echo " -k Skip nbd start up"
52 echo " (default: ${NBD_SKIP} )"
59 rm -rf ${TMPDIR}/syslinux
60 mkdir
-p ${TMPDIR}/${INSTALL_DIR}
61 cp -r ${MNTPNT}/${INSTALL_DIR}/boot ${TMPDIR}/${INSTALL_DIR}
62 mv ${TMPDIR}/${INSTALL_DIR}/boot/syslinux ${TMPDIR}
63 mv ${TMPDIR}/${INSTALL_DIR} ${TMPDIR}/syslinux
64 sed -i 's|^#IPAPPEND|IPAPPEND|g' ${TMPDIR}/syslinux
/*.cfg
65 mkdir
-p ${TMPDIR}/syslinux
/pxelinux.cfg
66 cp ${TMPDIR}/syslinux
/syslinux.cfg
${TMPDIR}/syslinux
/pxelinux.cfg
/default
71 pkill dnsmasq
> /dev
/null
2>&1 || true
75 --tftp-root=${TMPDIR} \
76 --dhcp-boot=syslinux
/pxelinux
.0,"${IP}" \
77 --dhcp-range=${IP%.*}.2,${IP%.*}.254,86400
82 pkill nbd-server
> /dev
/null
2>&1 || true
83 echo "[generic]" > ${TMPDIR}/nbd-server.conf
84 echo "[archiso]" >> ${TMPDIR}/nbd-server.conf
85 echo " readonly = true" >> ${TMPDIR}/nbd-server.conf
86 echo " exportname = ${DEVICE}" >> ${TMPDIR}/nbd-server.conf
87 nbd-server
-C ${TMPDIR}/nbd-server.conf
92 if grep archisolabel
/proc
/cmdline
> /dev
/null
; then
93 DEVICE
=/dev
/disk
/by-label
/$
(sed "s/.*archisolabel=\([^ ]\+\).\+/\1/" /proc
/cmdline
)
97 if grep archisobasedir
/proc
/cmdline
> /dev
/null
; then
98 INSTALL_DIR
=$
(sed "s/.*archisobasedir=\([^ ]\+\).\+/\1/" /proc
/cmdline
)
101 IP
=$
(ip
-f inet
-o addr show dev eth0 scope global | cut
-d' ' -f 7 | cut
-d / -f 1)
106 if [ -z "${IP}" ]; then
107 echo "ERROR: missing IP address"
111 if [ -n "${ISO}" ]; then
113 DEVICE
=$
(readlink
-f ${ISO})
114 MNTPNT
="${TMPDIR}/mnt"
117 if [ -z "${DEVICE}" ]; then
118 echo "ERROR: can not determine boot device, please specify on command line"
125 while getopts 'i:s:d:l:m:t:jkh' arg
; do
128 s
) ISO
="${OPTARG}" ;;
129 d
) DEVICE
=$
(readlink
-f ${OPTARG}) ;;
130 l
) INSTALL_DIR
="${OPTARG}" ;;
131 m
) MNTPNT
="${OPTARG}" ;;
132 t
) TMPDIR
="${OPTARG}" ;;
133 j
) DNSMASQ_SKIP
=true
;;
136 *) echo; echo "*ERROR*: invalid argument '${arg}'"; show_help
1 ;;
142 if ! ${DNSMASQ_SKIP} ; then
145 if ! ${NBD_SKIP} ; then