Switch default mount point from /lib/live/mount/medium to /run/live/medium
[grml-terminalserver.git] / templates / grub-pxelinux_config
1 # the following variables are available in the template:
2 #
3 # $INTERFACE_     (interface for the terminalserver)
4 # $IP_            (ip for the terminalserver to bind)
5 # $NETMASK_       (network mask)
6 # $GW_            (gateway)
7 # $NAMESERVERS_   (nameservers for the nodes)
8 # $IPRANGE_FROM_  (user configured iprange, first ip)
9 # $IPRANGE_TO_    (user configured iprange, last ip)
10 # $NETWORK_       (first ip in this subnet)
11 # $OPTIONS_       (options for grml-terminalserver)
12 # $BOOT_ARGS_     (boot arguments for the nodes)
13 #
14 # NOTE:
15 # templates are shellscript fragments and will be sourced from the
16 # terminalserver
17 #
18 # GLOBAL_README_END
19
20 # default boot arguments used for both grub and pxelinux
21 if [ -e "$MOUNT_POINT_" ]; then
22     default_boot_args_="root=/dev/nfs rw nfsroot=$IP_:$MOUNT_POINT_ \
23 noprompt noeject"
24 else
25     default_boot_args_="ramdisk_size=24000 root=/dev/ram0 rw \
26 init=/etc/init nfsdir=$IP_:$MOUNT_POINT_ nodhcp noprompt noeject \
27 apm=power-off nomce"
28 fi
29
30 # special boot arguments required by pxelinux
31 pxe_def_boot_args_="$default_boot_args_"
32
33 ###
34 ## create pxelinux config
35 ###
36 DEST_DIR=$(mktemp -d)
37 if [ -d /run/live/medium ] ; then # since December 2018
38   grml2usb --bootloader-only \
39       --bootoptions="$pxe_def_boot_args_ $BOOT_ARGS_" \
40       --remove-bootoption=nodhcp \
41       /run/live/medium "$DEST_DIR"
42
43   mv "$DEST_DIR"/boot/syslinux/* "$TFTPD_DATA_DIR_/"
44   rmdir "$DEST_DIR"/boot/syslinux
45
46   mv "$DEST_DIR"/boot/ "$TFTPD_DATA_DIR_"
47 elif [ -d /lib/live/mount/medium ] ; then
48   grml2usb --bootloader-only \
49       --bootoptions="$pxe_def_boot_args_ $BOOT_ARGS_" \
50       --remove-bootoption=nodhcp \
51       /lib/live/mount/medium "$DEST_DIR"
52
53   mv "$DEST_DIR"/boot/syslinux/* "$TFTPD_DATA_DIR_/"
54   rmdir "$DEST_DIR"/boot/syslinux
55
56   mv "$DEST_DIR"/boot/ "$TFTPD_DATA_DIR_"
57 else
58   if [ ! -d /usr/share/grml-live/templates/boot/isolinux ] ; then
59     echo "E: Could not find isolinux directory, can not operate without.
60
61 Did you boot the system with the toram=... boot option? If so please
62 either do not use the toram boot option at all or use boot option toram
63 without any arguments (just \"toram\" instead of \"toram=...\")." >&2
64     exit 2
65   fi
66
67   array=( $(cat /etc/grml_version) )
68   grml_name_=${array[0]}
69   grml_version_=${array[1]}
70
71   cp /usr/share/grml-live/templates/boot/isolinux/* "$TFTPD_DATA_DIR_/"
72
73   config_files_=$(find "$TFTPD_DATA_DIR_/" -name "*.cfg" -type f)
74   sed -i "s/%ARCH%/$(uname -m)/" $config_files_
75   sed -i "s/%BOOTID%/$RANDOM/" $config_files_
76   sed -i "s/%SHORT_NAME%/dummy/" $config_files_
77   sed -i "s/%VERSION%/$grml_version_/" $config_files_
78   sed -i "s/%GRML_NAME%/$grml_name_/" $config_files_
79   sed -i "s/%DISTRI_SPLASH%/grml.png/" $config_files_
80   sed -i "s/%DISTRI_INFO%/Grml/" $config_files_
81   sed -i "s#\(^.*append.*initrd.*$\)#\1 $pxe_def_boot_args_ $BOOT_ARGS_#" $config_files_
82   cat > "$TFTPD_DATA_DIR_/grmlmain.cfg"<<EOT
83   include default.cfg
84 include menuoptions.cfg
85 include grml.cfg
86 include options.cfg
87 include isoprompt.cfg
88 include hd.cfg
89 include hidden.cfg
90 EOT
91
92 fi
93
94 # Copy initrd.img and vmlinuz from all directories which name begins
95 # with grml, e.g. grml32full and grml64full
96 # This way we can boot multiple ISOs
97 for filename in "${MULTIBOOT_PATH_}"/grml* ; do
98   [ -d "$filename" ] || continue
99   cp -r "${filename}" "${TFTPD_DATA_DIR_}/boot/"
100 done
101
102 config_files_=$(find "$TFTPD_DATA_DIR_/" -name "*.cfg" -type f)
103
104 # cd is multi iso, grml2usb got it right ;0
105 if [ -d "$MOUNT_POINT_"/boot/release ] ; then
106    sed -i -e 's#\(.*\)/boot/\(.*\)#\1\2#' $config_files_
107 fi
108
109 # adjust ldbsd.com bootline
110 sed -i -e 's#\(.*kernel .*/ldbsd.com\)#\1 set image /boot/addons/bsd4grml/bsd.rd`echo Type "boot" to load MirOS bsd4grml via keeppxe#' "$TFTPD_DATA_DIR_/"addon_*_bsd.cfg
111
112 # remove grub entries
113 rm -f "$TFTPD_DATA_DIR_/"addon_*grub*.cfg
114
115 mv "$TFTPD_DATA_DIR_/syslinux.cfg" "$TFTPD_DATA_DIR_/pxelinux.cfg/default"
116 rm -rf "$DEST_DIR"
117
118 let ret_=$ret_+$?
119 return $ret_