Debian Codegraph @

sbin/generate-pxe-menu

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: Output pxelinux config on DRBL server.
5
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9 [ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf
10 [ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions
11
12 # Default settings
13 pxe_mode="graphic"
14
15 export LC_ALL=C
16 #
17 USAGE() {
18 echo "Generate the PXELINUX menu for DRBL clients."
19 echo "Usage: $(basename $0) [OPTION]"
20 echo "Options:"
21 echo "-b, --background PIC: set the background picture as picture file PIC."
22 echo "-c, --console OPT: set the console output parameters."
23 echo "-d, --dir DIR: Assign the netinstall files are in DIR instead of default dir $pxecfg_pd"
24 echo "-s, --serial OPT: set the PXE menu to work with serial console output."
25 echo "-g, --graphic [y|n]: Option to set client to use graphical mode or not when booting GNU/Linux (now only for Fedora Core)"
26 echo "-m, --pxe-mode [text|graphic]: Set the default PXE Linux menu mode to text or graphic"
27 echo "-p, --pxelinux-dir DIR: Assign PXELINUX config dir as DIR instead of deafult dir $PXELINUX_DIR."
28 echo "-v, --verbose: verbose mode."
29 echo "Ex:"
30 echo "To create the console output in DRBL client:"
31 echo "$(basename $0) -v -s \"serial 0 38400\" -c \"console=ttyS0,38400n81 console=tty0\" "
32 echo "Note! You must put the \" before and after your serial OPT and console OPT."
33 }
34
35 #
36 check_if_root
37
38 # Parse command-line options
39 while [ $# -gt 0 ]; do
40 case "$1" in
41 -b|--background)
42 shift
43 if [ -z "$(echo $1 |grep ^-.)" ]; then
44 # skip the -xx option, in case
45 background_pic="$1"
46 shift
47 fi
48 [ -z "$background_pic" ] && USAGE && exit 1
49 ;;
50 -c|--console)
51 shift
52 if [ -z "$(echo $1 |grep ^-.)" ]; then
53 # skip the -xx option, in case
54 CONSOLE_OUTPUT="$1"
55 shift
56 fi
57 [ -z "$CONSOLE_OUTPUT" ] && USAGE && exit 1
58 ;;
59 -d|--dir)
60 shift
61 if [ -z "$(echo $1 |grep ^-.)" ]; then
62 # skip the -xx option, in case
63 TDIR="$1"
64 shift
65 fi
66 [ -z "$TDIR" ] && USAGE && exit 1
67 ;;
68 -f|--fdos)
69 shift
70 if [ -z "$(echo $1 |grep ^-.)" ]; then
71 # skip the -xx option, in case
72 fdos_img_output="$1"
73 shift
74 fi
75 [ -z "$fdos_img_output" ] && USAGE && exit 1
76 ;;
77 -g|--graphic)
78 shift
79 if [ -z "$(echo $1 |grep ^-.)" ]; then
80 # skip the -xx option, in case
81 graphical_boot="$1"
82 shift
83 fi
84 [ -z "$graphical_boot" ] && USAGE && exit 1
85 ;;
86 -m|--pxe-mode)
87 shift;
88 # skip the -xx option, in case
89 if [ -z "$(echo $1 |grep ^-.)" ]; then
90 pxe_mode="$1"
91 shift
92 fi
93 [ -z "$pxe_mode" ] && USAGE && exit 1
94 ;;
95 -p|--pxelinux-dir)
96 shift
97 if [ -z "$(echo $1 |grep ^-.)" ]; then
98 # skip the -xx option, in case
99 PXECFG_DIR="$1"
100 shift
101 fi
102 [ -z "$PXECFG_DIR" ] && USAGE && exit 1
103 ;;
104 -s|--serial)
105 shift
106 if [ -z "$(echo $1 |grep ^-.)" ]; then
107 # skip the -xx option, in case
108 PXE_SERIAL_OUTPUT="$1"
109 shift
110 fi
111 [ -z "$PXE_SERIAL_OUTPUT" ] && USAGE && exit 1
112 ;;
113 -v|--verbose) shift; verbose="on" ;;
114 -*) echo "${0}: ${1}: invalid option" >&2
115 USAGE >& 2
116 exit 2 ;;
117 *) break ;;
118 esac
119 done
120
121 # fdos_img_output should be in /etc/drbl/drbl.conf
122 [ -z "$fdos_img_output" ] && echo "You must provide the FreeDOS image filename! Program terminated!!!" && exit 1
123
124 # if console output is assign, default to use menu.c32 instead of vesamenu.c32
125 if [ -n "$CONSOLE_OUTPUT" ]; then
126 pxe_mode="text"
127 fi
128
129 [ -z "$PXECFG_DIR" ] && PXECFG_DIR="$PXELINUX_DIR"
130 [ -z "$TDIR" ] && TDIR="$pxecfg_pd"
131
132 # Find the IP address of this server. Here we choose the first one in the list, since it's just an example.
133
134 echo "Generating default pxelinux config ($PXECFG_DIR/default)..."
135 # clean the old one
136 [ -f "$PXECFG_DIR/default" ] && rm -f $PXECFG_DIR/default
137
138 # get the OS_Version and OS_type
139 check_distribution_name
140
141 # $graphical_boot is in drbl.conf or from command parameter.
142 case "$graphical_boot" in
143 y|Y|[yY][eE][sS])
144 case "$OS_Version" in
145 FC*)
146 echo "Use graphical boot for DRBL Fedora Core client..."
147 # We'd better use "rhgb" instead of "quiet rhgb" since if something goes wrong in net initrd, it's not easy to debug.
148 drbl_dist_append="rhgb"
149 ;;
150 esac
151 ;;
152 n|N|[nN][oO])
153 drbl_dist_append=""
154 ;;
155 esac
156 case "$OS_Version" in
157 DBN*)
158 # Put quiet for Debian and Ubuntu clients.
159 quiet_opt="quiet"
160 ;;
161 *)
162 # Do not put quiet since for centos 6 clients since it seems after pxelinux booting, no output on screen.
163 quiet_opt=""
164 ;;
165 esac
166 #
167 # PXE Linux menu mode
168 case "$pxe_mode" in
169 text*|TEXT*) MENUC32="menu.c32" ;;
170 graphic*|GRAPHIC*) MENUC32="vesamenu.c32" ;;
171 esac
172
173 # background logo and memtest
174 if [ -n "$background_pic" ]; then
175 drbl_logo="$background_pic"
176 else
177 drbl_logo="$(basename $pxelinux_bg_img)"
178 fi
179
180 # show some prompts
181 echo "Use com32 module: $MENUC32"
182 [ -n "$PXE_SERIAL_OUTPUT" ] && echo "PXE serial output param: $PXE_SERIAL_OUTPUT"
183 [ -n "$CONSOLE_OUTPUT" ] && echo "Linux console output param: $CONSOLE_OUTPUT"
184 [ -n "$drbl_dist_append" ] && echo "Extra param: $drbl_dist_append"
185
186 # read drbl_deploy.conf if this program is run again after drblpush is done.
187 [ -f /etc/drbl/drbl_deploy.conf ] && . /etc/drbl/drbl_deploy.conf
188 [ "$drbl_mode" = "drbl_ssi_mode" ] && drbl_mode_opt="clientdir=node_root"
189 [ "$clonezilla_mode" = "clonezilla_box_mode" ] && clonezilla_mode_opt="clientdir=node_root"
190
191 # Get version number.
192 case "$OS_Version" in
193 RH*|FC*|CO*|MDK*|MDV*|SUSE*)
194 drbl_ver="$(rpm -q drbl | sed -e "s/^drbl-//g")"
195 ocs_ver="$(rpm -q clonezilla | sed -e "s/^clonezilla-//g")"
196 memtest_ver="$(cat $TDIR/MEMTEST86+_VERSION 2>/dev/null)"
197 ;;
198 DBN*)
199 drbl_ver="$(dpkg -l drbl | tail -n 1 | awk -F" " '{print $3}')"
200 ocs_ver="$(dpkg -l clonezilla | tail -n 1 | awk -F" " '{print $3}')"
201 memtest_ver="$(cat $TDIR/MEMTEST86+_VERSION 2>/dev/null)"
202 ;;
203 esac
204 [ -z "$drbl_ver" ] && drbl_ver="Unknown"
205 [ -z "$ocs_ver" ] && ocs_ver="Unknown"
206
207 #
208 [ -f "$PXECFG_DIR/default" ] && mv -f $PXECFG_DIR/default $PXECFG_DIR/default.drblsaved
209
210 # Kernel EDD (sysfs interface to BIOS EDD information) is useful for partclone.ntfsreloc. However, if it's compiled as builtin in kernel, it might be off by default, as the kernel config:
211 # CONFIG_EDD=y
212 # CONFIG_EDD_OFF=y
213 # If so, we have to put edd=on in boot parameter so the edd will be on when booting
214 edd_opt=""
215 if [ -e "$pxecfg_pd/kernel_version_in_initrd.txt" ]; then
216 # Client's kernel config exists, i.e. this program is run after client's kernel is copied.
217 client_kver="$(cat $pxecfg_pd/kernel_version_in_initrd.txt 2>/dev/null)"
218 if [ -n "$(grep -Ew "CONFIG_EDD=y" $drbl_common_root/boot/config-${client_kver} 2>/dev/null)" ] && [ -n "$(grep -Ew "CONFIG_EDD_OFF=y" $drbl_common_root/boot/config-${client_kver} 2>/dev/null)" ]; then
219 edd_opt="edd=on"
220 fi
221 else
222 # Client's kernel config does not exists, i.e. this program is run BEFORE client's kernel is copied. Here we assume the running kernel on server has the same config with that on client.
223 client_kver="$(uname -r)"
224 if [ -n "$(grep -Ew "CONFIG_EDD=y" /boot/config-${client_kver} 2>/dev/null)" ] && [ -n "$(grep -Ew "CONFIG_EDD_OFF=y" /boot/config-${client_kver} 2>/dev/null)" ]; then
225 edd_opt="edd=on"
226 fi
227 fi
228
229 now_year="$(LC_ALL=C date +%Y)"
230 pxe_ver="$(LC_ALL=C awk -F" " '{print $2}' $pxecfg_pd/PXELINUX_VERSION)"
231 echo "Adding menus for DRBL, local boot, memtest86+, FreeDOS..."
232 cat <<-PXE_END > $PXECFG_DIR/default
233 # Created by generate-pxe-menu! Do NOT edit unless you know what you are doing!
234 # Keep those comment "MENU DEFAULT" and "MENU HIDE"! Do NOT remove them.
235 # Note!!! If "serial" directive exists, it must be the first directive
236 $PXE_SERIAL_OUTPUT
237 default $MENUC32
238 timeout 70
239 prompt 0
240 noescape 1
241 MENU MARGIN 5
242 MENU BACKGROUND ${drbl_logo}
243 # Set the color for unselected menu item and timout message
244 MENU COLOR UNSEL 7;32;41 #c0000090 #00000000
245 MENU COLOR TIMEOUT_MSG 7;32;41 #c0000090 #00000000
246 MENU COLOR TIMEOUT 7;32;41 #c0000090 #00000000
247 MENU COLOR HELP 7;32;41 #c0000090 #00000000
248
249 # MENU MASTER PASSWD
250
251 say **********************************************
252 say Welcome to DRBL.
253 say NCHC Free Software Labs, Taiwan.
254 say http://drbl.org; http://drbl.nchc.org.tw
255 say **********************************************
256
257 # Allow client to edit boot parameters
258 ALLOWOPTIONS 1
259
260 PXE_END
261
262 # PATH is supported after syslinux/pxelinux >=5
263 if [ "$pxe_ver" \> 5.0 ]; then
264 cat <<-PXE_END >> $PXECFG_DIR/default
265 # Set PATH to bios/ or efi64/, which is relative to PXE root dir ($PXELINUX_DIR).
266 # bios is for legacy PXE booting, while efi64 is for uEFI network booting.
267 # This might be improved in syslinux 7.0 using auto detection.
268 # For more info, please check:
269 # http://www.syslinux.org/archives/2014-April/thread.html#21974
270 #PATH efi64/
271 PATH bios/
272
273 PXE_END
274 fi
275
276 cat <<-PXE_END >> $PXECFG_DIR/default
277 # simple menu title
278 MENU TITLE DRBL (http://drbl.org)
279
280 label drbl
281 MENU DEFAULT
282 # MENU HIDE
283 MENU LABEL $FULL_OS_Version $powerful_client_menu_label
284 # MENU PASSWD
285 # If necessary, uncomment "IPAPPEND 1" to get DHCP/BOOTP in kernel command line,
286 # i.e., ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
287 # IPAPPEND 1
288 kernel vmlinuz-pxe
289 append initrd=initrd-pxe.img devfs=nomount drblthincli=off selinux=0 $quiet_opt $edd_opt $CONSOLE_OUTPUT $drbl_mode_opt $drbl_dist_append
290 TEXT HELP
291 * DRBL version: $drbl_ver. (C) 2003-${now_year}, NCHC, Taiwan
292 * Disclaimer: DRBL comes with ABSOLUTELY NO WARRANTY
293 ENDTEXT
294
295 label clonezilla
296 # MENU DEFAULT
297 MENU HIDE
298 MENU LABEL Clonezilla
299 # MENU PASSWD
300 # If necessary, uncomment "IPAPPEND 1" to get DHCP/BOOTP in kernel command line,
301 # i.e., ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
302 # IPAPPEND 1
303 kernel vmlinuz-pxe
304 append initrd=initrd-pxe.img devfs=nomount drblthincli=off selinux=0 $quiet_opt text 1 $edd_opt $CONSOLE_OUTPUT $clonezilla_mode_opt $drbl_dist_append
305 TEXT HELP
306 * Clonezilla version: $ocs_ver. (C) 2003-${now_year}, NCHC, Taiwan
307 * Disclaimer: Clonezilla comes with ABSOLUTELY NO WARRANTY
308 ENDTEXT
309
310 label local
311 # MENU DEFAULT
312 # MENU HIDE
313 MENU LABEL $local_os_menu_label
314 # MENU PASSWD
315 # 2 method to boot local device:
316 # (1) For localboot 0, it is decided by boot order in BIOS, so uncomment the follow 1 line if you want this method:
317 # localboot 0
318
319 # (2) For chain.c32, you can assign the boot device.
320 # Ref: extlinux.doc from syslinux
321 # Syntax: APPEND [hd|fd]<number> [<partition>]
322 # [<partition>] is optional.
323 # Ex:
324 # Second partition (2) on the first hard disk (hd0);
325 # Linux would *typically* call this /dev/hda2 or /dev/sda2, then it's "APPEND hd0 2"
326 #
327 kernel chain.c32
328 append hd0
329 TEXT HELP
330 Boot local OS from first hard disk if it's available
331 ENDTEXT
332
333 PXE_END
334
335 # For memtest86+
336 # memtest86+.bin -> mt86+x32.mbr
337 # memtest86+x32.bin -> mt86+x32.mbr
338 # memtest86+x32.efi -> mt86+x32.efi
339 if [ -e "$pxecfg_pd/mt86+x32.mbr" ]; then
340 cat <<-PXE_END >> $PXECFG_DIR/default
341 label memtest (32 bits)
342 # MENU DEFAULT
343 # MENU HIDE
344 MENU LABEL Memory test using Memtest86+ (32 bits)
345 # MENU PASSWD
346 kernel mt86+x32.mbr
347 TEXT HELP
348 Run memory test using 32-bit Memtest86+ $memtest_ver
349 ENDTEXT
350
351 PXE_END
352 fi
353
354 if [ -e "$pxecfg_pd/mt86+x64.mbr" ]; then
355 cat <<-PXE_END >> $PXECFG_DIR/default
356 label memtest (64 bits)
357 # MENU DEFAULT
358 # MENU HIDE
359 MENU LABEL Memory test using Memtest86+ (64 bits)
360 # MENU PASSWD
361 kernel mt86+x64.mbr
362 TEXT HELP
363 Run memory test using 64-bit Memtest86+ $memtest_ver
364 ENDTEXT
365
366 PXE_END
367 fi
368
369 if [ -e "$pxecfg_pd/$fdos_img_output" ]; then
370 cat <<-PXE_END >> $PXECFG_DIR/default
371 # ref: http://syslinux.zytor.com/memdisk.php
372 label fdos
373 # MENU DEFAULT
374 MENU HIDE
375 MENU LABEL FreeDOS
376 # MENU PASSWD
377 kernel memdisk
378 append initrd=$fdos_img_output
379 TEXT HELP
380 Run FreeDOS
381 ENDTEXT
382
383 PXE_END
384 fi
385 cat <<-PXE_END >> $PXECFG_DIR/default
386 label drbl-terminal
387 # MENU DEFAULT
388 MENU HIDE
389 MENU LABEL $FULL_OS_Version $thin_client_menu_label
390 # MENU PASSWD
391 # If necessary, uncomment "IPAPPEND 1" to get DHCP/BOOTP in kernel command line,
392 # i.e., ip=<client-ip>:<boot-server-ip>:<gw-ip>:<netmask>
393 # IPAPPEND 1
394 kernel vmlinuz-pxe
395 append initrd=initrd-pxe.img devfs=nomount drblthincli=on $quiet_opt
396 TEXT HELP
397 Run DRBL in terminal mode.
398 ENDTEXT
399
400 # Example for AoE booting
401 label AoE-client
402 # MENU DEFAULT
403 MENU HIDE
404 MENU LABEL Diskless client (AoE booting)
405 # MENU PASSWD
406 kernel sanboot.c32
407 append aoe:e0.0
408 TEXT HELP
409 Boot from AoE device
410 ENDTEXT
411
412 # Example for Xen client. ///NOTE/// You might have to copy the required file, e.g. xen-3.0.3-1-i386-pae.gz in this case, from /boot to /tftpboot/nbi_img manually.
413 # label Xen client
414 # # MENU DEFAULT
415 # MENU HIDE
416 # MENU LABEL Xen client
417 # # MENU PASSWD
418 # kernel mboot.c32
419 # append xen-3.0.3-1-i386-pae.gz --- vmlinuz-2.6.18-6-xen-vserver-686 root=/dev/sda1 ro console=tty0 --- initrd-pxe.2.6.18-6-xen-vserver-686.img
420 # TEXT HELP
421 # DRBL client running on Xen kernel
422 # ENDTEXT
423
424 # Example for Clonezilla live PXE booting
425 # //NOTE// Remember to change the file names to match your files and check parameters in syslinux/syslinux.cfg from the zip file, copy them to here. It might be different from here, say vmlinuz1 path maybe different.
426 #label Clonezilla Live
427 # # MENU DEFAULT
428 # MENU HIDE
429 # MENU LABEL Clonezilla Live
430 # # MENU PASSWD
431 # kernel vmlinuz1
432 # append initrd=initrd1.img boot=live union=aufs noswap noeject nolocales ip=frommedia vga=788 fetch=tftp://\$YOUR_SERVER_IP/filesystem.squashfs
433 # TEXT HELP
434 # Boot Clonezilla live via network
435 # ENDTEXT
436
437
438 # Example for GParted live PXE booting
439 # //NOTE// Remember to change the file names to match your files and check parameters in syslinux/syslinux.cfg from the zip file, copy them to here. It might be different from here, say vmlinuz1 path maybe different.
440 #label GParted Live
441 # # MENU DEFAULT
442 # MENU HIDE
443 # MENU LABEL GParted Live
444 # # MENU PASSWD
445 # kernel vmlinuz1
446 # append initrd=initrd1.img boot=live union=aufs noswap noeject ip=frommedia vga=788 fetch=tftp://\$YOUR_SERVER_IP/filesystem.squashfs
447 # TEXT HELP
448 # Boot GParted live via network
449 # ENDTEXT
450
451 PXE_END
452
453 output_netinstall_boot_menu $TDIR $PXECFG_DIR/default
454
455 echo "done!"