/usr/sbin/gen-grub-efi-nb-menu is in drbl 2.20.11-4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | #!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL
# Description: Output grub efi network boot config on DRBL server.
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
[ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf
[ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions
export LC_ALL=C
#
USAGE() {
echo "Generate the Grub EFI network boot menu for DRBL clients."
echo "Usage: $(basename $0) [OPTION]"
echo "Options:"
echo "-c, --console OPT: set the console output parameters."
echo "-d, --dir DIR: Assign the netinstall files are in DIR instead of default dir $pxecfg_pd"
echo "-m, --bg-mode [text|graphic]: Set the default GRUB menu mode to text or graphic"
echo "-s, --serial OPT: set the grub menu to work with serial console output. OPT is like: serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
echo "-g, --graphic [y|n]: Option to set client to use graphical mode or not when booting GNU/Linux (now only for Fedora Core)"
echo "-p, --grub-efi-dir DIR: Assign grub config dir as DIR instead of deafult dir $GRUB_EFINB_DIR"
echo "-v, --verbose: verbose mode."
echo "Ex:"
echo "To create the console output in DRBL client:"
echo "$(basename $0) -v -s \"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1\" -c \"console=ttyS0,38400n81 console=tty0\" "
echo "Note! You must put the \" before and after your serial OPT and console OPT."
}
# Default settings
# GRUB_EFINB_DIR is from drbl.conf, and GRUB_EFI_D is for using only in the program.
bg_mode="graphic"
#
check_if_root
# Parse command-line options
while [ $# -gt 0 ]; do
case "$1" in
-s|--serial)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
GRUB_SERIAL_OUTPUT="$1"
shift
fi
[ -z "$GRUB_SERIAL_OUTPUT" ] && USAGE && exit 1
;;
-c|--console)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
CONSOLE_OUTPUT="$1"
shift
fi
[ -z "$CONSOLE_OUTPUT" ] && USAGE && exit 1
;;
-m|--bg-mode)
shift;
# skip the -xx option, in case
if [ -z "$(echo $1 |grep ^-.)" ]; then
bg_mode="$1"
shift
fi
[ -z "$bg_mode" ] && USAGE && exit 1
;;
-g|--graphic)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
graphical_boot="$1"
shift
fi
[ -z "$graphical_boot" ] && USAGE && exit 1
;;
-d|--dir)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
TDIR="$1"
shift
fi
[ -z "$TDIR" ] && USAGE && exit 1
;;
-p|--grub-efi-dir)
shift
if [ -z "$(echo $1 |grep ^-.)" ]; then
# skip the -xx option, in case
GRUB_EFI_D="$1"
shift
fi
[ -z "$GRUB_EFI_D" ] && USAGE && exit 1
;;
-v|--verbose)
shift; verbose="on"
;;
-*) echo "${0}: ${1}: invalid option" >&2
USAGE >& 2
exit 2 ;;
*) break ;;
esac
done
[ -z "$GRUB_EFI_D" ] && GRUB_EFI_D="$GRUB_EFINB_DIR"
[ -z "$TDIR" ] && TDIR="$pxecfg_pd"
# Find the IP address of this server. Here we choose the first one in the list, since it's just an example.
echo "Generating default GRUB network boot config ($GRUB_EFI_D/grub.cfg)..."
# clean the old one
[ -f "$GRUB_EFI_D/grub.cfg" ] && rm -f $GRUB_EFI_D/grub.cfg
# get the OS_Version and OS_type
check_distribution_name
# $graphical_boot is in drbl.conf or from command parameter.
case "$graphical_boot" in
y|Y|[yY][eE][sS])
case "$OS_Version" in
FC*)
echo "Use graphical boot for DRBL Fedora Core client..."
# We'd better use "rhgb" instead of "quiet rhgb" since if something goes wrong in net initrd, it's not easy to debug.
drbl_dist_append="rhgb"
;;
esac
;;
n|N|[nN][oO])
drbl_dist_append=""
;;
esac
case "$OS_Version" in
DBN*)
# Put quiet for Debian and Ubuntu clients.
quiet_opt="quiet"
;;
*)
# Do not put quiet since for centos 6 clients since it seems after pxelinux booting, no output on screen.
quiet_opt=""
;;
esac
#
# GRUB Linux menu mode
# find the drbl background logo and memtest
drbl_logo="$(basename $grub_bg_img)"
# show some prompts
[ -n "$GRUB_SERIAL_OUTPUT" ] && echo "GRUB serial output param: $GRUB_SERIAL_OUTPUT"
[ -n "$CONSOLE_OUTPUT" ] && echo "Linux console output param: $CONSOLE_OUTPUT"
[ -n "$drbl_dist_append" ] && echo "Extra param: $drbl_dist_append"
# read drbl_deploy.conf if this program is run again after drblpush is done.
[ -f /etc/drbl/drbl_deploy.conf ] && . /etc/drbl/drbl_deploy.conf
[ "$drbl_mode" = "drbl_ssi_mode" ] && drbl_mode_opt="clientdir=node_root"
[ "$clonezilla_mode" = "clonezilla_box_mode" ] && clonezilla_mode_opt="clientdir=node_root"
# Get version number.
case "$OS_Version" in
RH*|FC*|CO*|MDK*|MDV*|SUSE*)
drbl_ver="$(rpm -q drbl | sed -e "s/^drbl-//g")"
ocs_ver="$(rpm -q clonezilla | sed -e "s/^clonezilla-//g")"
;;
DBN*)
drbl_ver="$(dpkg -l drbl | tail -n 1 | awk -F" " '{print $3}')"
ocs_ver="$(dpkg -l clonezilla | tail -n 1 | awk -F" " '{print $3}')"
;;
esac
[ -z "$drbl_ver" ] && drbl_ver="Unknown"
[ -z "$ocs_ver" ] && ocs_ver="Unknown"
#
[ -f "$GRUB_EFI_D/grub.cfg" ] && mv -f $GRUB_EFI_D/grub.cfg $GRUB_EFI_D/grub.cfg.drblsaved
# 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:
# CONFIG_EDD=y
# CONFIG_EDD_OFF=y
# If so, we have to put edd=on in boot parameter so the edd will be on when booting
edd_opt=""
if [ -e "$pxecfg_pd/kernel_version_in_initrd.txt" ]; then
# Client's kernel config exists, i.e. this program is run after client's kernel is copied.
client_kver="$(cat $pxecfg_pd/kernel_version_in_initrd.txt 2>/dev/null)"
if [ -n "$(grep -Ew "CONFIG_EDD=y" $drbl_common_root/boot/config-${client_kver})" ] && [ -n "$(grep -Ew "CONFIG_EDD_OFF=y" $drbl_common_root/boot/config-${client_kver})" ]; then
edd_opt="edd=on"
fi
else
# 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.
client_kver="$(uname -r)"
if [ -n "$(grep -Ew "CONFIG_EDD=y" /boot/config-${client_kver})" ] && [ -n "$(grep -Ew "CONFIG_EDD_OFF=y" /boot/config-${client_kver})" ]; then
edd_opt="edd=on"
fi
fi
# Bacground mode
case "$bg_mode" in
text*|TEXT*) g_bg_f="no" ;;
graphic*|GRAPHIC*) g_bg_f="yes" ;;
esac
grub_ver="$(LC_ALL=C cat $pxecfg_pd/GRUB_VERSION)"
echo "Adding GRUB EFI boot menu for DRBL, Clonezilla..."
cat <<-GRUB_END > $GRUB_EFI_D/grub.cfg
# Created by gen-grub-efi-nb-menu! Do NOT edit unless you know what you are doing!
GRUB_END
# GRUB serial console
# Ref: ttps://www.gnu.org/software/grub/manual/grub.html#serial
if [ -n "$GRUB_SERIAL_OUTPUT" ]; then
cat <<-GRUB_END >> $GRUB_EFI_D/grub.cfg
$GRUB_SERIAL_OUTPUT
terminal_input --append serial
terminal_output --append serial
GRUB_END
fi
cat <<-GRUB_END >> $GRUB_EFI_D/grub.cfg
set default=drbl-client
set timeout_style=menu
set timeout=7
set hidden_timeout_quiet=false
set graphic_bg=${g_bg_f}
#
function load_gfxterm {
set gfxmode=auto
insmod efi_gop
insmod efi_uga
insmod gfxterm
terminal_output gfxterm
}
# Somehow the grub2 from CentOS 7 will look for unicode.pf2.pf2 if using "loadfont unicode.pf2". While in Debian/Ubuntu it's OK to use "loadfont unicode.pf2".
if [ x"\${graphic_bg}" = xyes ]; then
if loadfont unicode; then
load_gfxterm
elif loadfont unicode.pf2; then
load_gfxterm
fi
fi
if background_image drblwp.png; then
set color_normal=black/black
set color_highlight=magenta/black
else
set color_normal=cyan/blue
set color_highlight=white/blue
fi
GRUB_END
cat <<-GRUB_END >> $GRUB_EFI_D/grub.cfg
menuentry "$FULL_OS_Version $powerful_client_menu_label" --id drbl-client {
echo "Enter DRBL..."
echo "Loading Linux kernel vmlinuz-pxe..."
linux vmlinuz-pxe devfs=nomount drblthincli=off selinux=0 $quiet_opt $edd_opt $CONSOLE_OUTPUT $drbl_mode_opt $drbl_dist_append
echo "Loading initial ramdisk initrd-pxe.img..."
initrd initrd-pxe.img
}
#menuentry "Clonezilla" --id clonezilla-se-client {
# echo "Enter Clonezilla..."
# echo 'Loading Linux kernel vmlinuz-pxe...'
# linux vmlinuz-pxe devfs=nomount drblthincli=off selinux=0 $quiet_opt text 1 $edd_opt $CONSOLE_OUTPUT $clonezilla_mode_opt $drbl_dist_append
# echo 'Loading initial ramdisk initrd-pxe.img...'
# initrd initrd-pxe.img
#}
menuentry "Local operating system (if available)" --id local-disk {
echo "Booting first local disk..."
set root=(hd0,1)
if [ -e /EFI/redhat/grub.efi ]; then
chainloader /EFI/redhat/grub.efi +1
elif [ -e /EFI/fedora/shim.efi ]; then
chainloader /EFI/fedora/shim.efi +1
elif [ -e /EFI/fedora/grubx64.efi ]; then
chainloader /EFI/fedora/grubx64.efi +1
elif [ -e /EFI/debian/grubx64.efi ]; then
chainloader /EFI/debian/grubx64.efi +1
elif [ -e /EFI/ubuntu/grubx64.efi ]; then
chainloader /EFI/ubuntu/grubx64.efi +1
elif [ -e /EFI/mageia/grubx64.efi ]; then
chainloader /EFI/mageia/grubx64.efi +1
elif [ -e /EFI/opensuse/grubx64.efi ]; then
chainloader /EFI/opensuse/grubx64.efi +1
elif [ -e /EFI/sled12/grubx64.efi ]; then
# SuSE Linux Enterprise 12
chainloader /EFI/sled12/grubx64.efi +1
elif [ -e /EFI/SuSE/elilo.efi ]; then
# SuSE Linux Enterprise 11
chainloader /EFI/SuSE/elilo.efi +1
elif [ -e /EFI/Boot/bootx64.efi ]; then
# MS Windows
chainloader /EFI/Boot/bootx64.efi +1
elif [ -e /EFI/Microsoft/Boot/bootmgfw.efi ]; then
chainloader /EFI/Microsoft/Boot/bootmgfw.efi +1
else
echo "No uEFI image was found!"
sleep 15
fi
}
menuentry "Reboot" --id reboot {
echo "System rebooting..."
reboot
}
menuentry "Shutdown" --id shutdown {
echo "System shutting down..."
halt
}
GRUB_END
output_netinstall_syslinux_pxelinux_menu --efi $TDIR $GRUB_EFI_D/grub.cfg
echo "done!"
|