Make sure we don't override live-media-path if /lib/live/mount/medium/boot exists
[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 if grep -q live-media-path= /proc/cmdline 2>/dev/null ; then
21   live_media_path_="live-media-path=$(awk -F live-media-path= '{print $2}' /proc/cmdline | awk '{print $1}')"
22 fi
23 if [ ! -d /live/image/boot ] && [ ! -d /lib/live/mount/medium/boot ] ; then
24   live_media_path_="live-media-path=/"
25 fi
26
27 # default boot arguments used for both grub and pxelinux
28 if [ -e "$MOUNT_POINT_" ]; then
29     default_boot_args_="root=/dev/nfs rw nfsroot=$IP_:$MOUNT_POINT_ \
30 noprompt noeject"
31 else
32     default_boot_args_="ramdisk_size=24000 root=/dev/ram0 rw \
33 init=/etc/init nfsdir=$IP_:$MOUNT_POINT_ nodhcp noprompt noeject \
34 apm=power-off nomce"
35 fi
36
37 # special boot arguments required by grub
38 grub_def_boot_args_="/vmlinuz $default_boot_args_ $live_media_path_"
39
40 # special boot arguments required by pxelinux
41 pxe_def_boot_args_="$default_boot_args_"
42
43 # default arguments for framebuffer console
44 def_fb_args_="vga=791"
45 no_fb_args_="vga=normal"
46
47 ###
48 ## create grub config
49 ###
50
51 cat >"$TFTPD_DATA_DIR_/menu.lst" <<EOT
52 default=0
53 timeout=10
54 title GRML
55   root (nd)
56   kernel $grub_def_boot_args_ $def_fb_args_ $BOOT_ARGS_
57   initrd /initrd.img
58
59 title GRML no framebuffer
60   root (nd)
61   kernel $grub_def_boot_args_ $no_fb_args_ $BOOT_ARGS_
62
63 title GRML small
64   root (nd)
65   kernel $grub_def_boot_args_ small $def_fb_args_ $BOOT_ARGS_
66   initrd /initrd.img
67
68 title GRML small nofb
69   root (nd)
70   kernel $grub_def_boot_args_ small $no_fb_args_ $BOOT_ARGS_
71   initrd /initrd.img
72
73 title GRML debuginit
74   root (nd)
75   kernel $grub_def_boot_args_ debuginitrd $def_fb_args_ $BOOT_ARGS_
76   initrd /initrd.img
77
78 title GRML debuginit nofb
79   root (nd)
80   kernel $grub_def_boot_args_ debuginitrd $no_fb_args_ $BOOT_ARGS_
81   initrd /initrd.img
82
83 title GRML rescue
84   root (nd)
85   kernel $grub_def_boot_args_ $no_fb_args_
86   initrd /initrd.img
87
88 title memtest
89   root (nd)
90   kernel /memtest
91
92 title Reload config
93   configfile (nd)/menu.lst
94 EOT
95
96 ret_=$?
97
98
99 ###
100 ## create pxelinux config
101 ###
102 DEST_DIR=$(mktemp -d)
103 if [ -d /lib/live/mount/medium/boot ] ; then # since around December 2012
104   grml2usb --bootloader-only \
105       --bootoptions="$pxe_def_boot_args_ $BOOT_ARGS_" \
106       --remove-bootoption=nodhcp \
107       /lib/live/mount/medium "$DEST_DIR"
108
109   mv "$DEST_DIR"/boot/syslinux/* "$TFTPD_DATA_DIR_/"
110   rmdir "$DEST_DIR"/boot/syslinux
111
112   mv "$DEST_DIR"/boot/ "$TFTPD_DATA_DIR_"
113 elif [ -d /live/image/boot ] ; then # until around December 2012
114   grml2usb --bootloader-only \
115       --bootoptions="$pxe_def_boot_args_ $BOOT_ARGS_" \
116       --remove-bootoption=nodhcp \
117       /live/image "$DEST_DIR"
118
119   mv "$DEST_DIR"/boot/syslinux/* "$TFTPD_DATA_DIR_/"
120   rmdir "$DEST_DIR"/boot/syslinux
121
122   mv "$DEST_DIR"/boot/ "$TFTPD_DATA_DIR_"
123 else # there is no kernel inside /live/image copy it from /boot
124   if [ ! -d /usr/share/grml-live/templates/boot/isolinux ] ; then
125     echo "E: Could not find isolinux directory, can not operate without.
126
127 Did you boot the system with the toram=... boot option? If so please
128 either do not use the toram boot option at all or use boot option toram
129 without any arguments (just \"toram\" instead of \"toram=...\")." >&2
130     exit 2
131   fi
132
133   array=( $(cat /etc/grml_version) )
134   grml_name_=${array[0]}
135   grml_version_=${array[1]}
136
137   cp /usr/share/grml-live/templates/boot/isolinux/* "$TFTPD_DATA_DIR_/"
138
139   config_files_=$(find "$TFTPD_DATA_DIR_/" -name "*.cfg" -type f)
140   sed -i "s/%ARCH%/$(uname -m)/" $config_files_
141   sed -i "s/%BOOTID%/$RANDOM/" $config_files_
142   sed -i "s/%SHORT_NAME%/dummy/" $config_files_
143   sed -i "s/%VERSION%/$grml_version_/" $config_files_
144   sed -i "s/%GRML_NAME%/$grml_name_/" $config_files_
145   sed -i "s/%DISTRI_SPLASH%/grml.png/" $config_files_
146   sed -i "s/%DISTRI_INFO%/Grml/" $config_files_
147   sed -i "s#\(^.*append.*initrd.*$\)#\1 $pxe_def_boot_args_ $BOOT_ARGS_#" $config_files_
148   cat > "$TFTPD_DATA_DIR_/grmlmain.cfg"<<EOT
149   include default.cfg
150 include menuoptions.cfg
151 include grml.cfg
152 include options.cfg
153 include isoprompt.cfg
154 include hd.cfg
155 include hidden.cfg
156 EOT
157
158 fi
159
160
161 config_files_=$(find "$TFTPD_DATA_DIR_/" -name "*.cfg" -type f)
162
163 # cd is multi iso, grml2usb got it right ;0
164 if [ -d "$MOUNT_POINT_"/boot/release ] ; then
165    sed -i -e 's#\(.*\)/boot/\(.*\)#\1\2#' $config_files_
166 else
167   # remove normal kernel path and use our image
168   sed -i -e 's/.*kernel.*vmlinuz/  kernel vmlinuz/' $config_files_
169   sed -i -e 's/\(initrd\)=[[:alnum:]/._-]*/\1=initrd.img/' $config_files_
170   # remove live-media-path per default
171   sed -i -e 's#live-media-path=[[:alnum:]/._-]*##' $config_files_
172
173   # append live-media-path if needed
174   if [ ! -z "$live_media_path_" ] ; then
175     sed -i -e "s#\(^.*append.*initrd.*$\)#\1 $live_media_path_#" $config_files_
176   fi
177
178 fi
179 # adjust ldbsd.com bootline
180 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
181
182 # remove grub entries
183 rm -f "$TFTPD_DATA_DIR_/"addon_*grub*.cfg
184
185 mv "$TFTPD_DATA_DIR_/syslinux.cfg" "$TFTPD_DATA_DIR_/pxelinux.cfg/default"
186 rm -rf "$DEST_DIR"
187
188 let ret_=$ret_+$?
189 return $ret_