# # Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. # # # This is the GRUB2 microconfig file for network booting. Its purpose is to # locate and source the per-client grub.cfg file, which can be found on the # TFTP server. # The image that this file is built into must set its $prefix to a directory # whose last component is the GRUB2 platform name of the current system. # For example, on BIOS systems, $prefix should be ".../i386-pc". This is # essential for the Solaris network boot GRUB2 configuration file, because # that's what it looks for when trying to determine the current platform. # # This script should be built into a memdisk image -- it should NOT be # passed to grub-mkimage -c, because this script uses advanced scripting # functionality that's only part of the GRUB2 `normal' module. # # By the time we get here, $root is set to "(tftp,)" and $prefix is # a platform-specific GRUB2 device path. # # IMPORTANT: The tests for existence of configfiles here MUST be done with # the -s test -- that's the only test that tries a file open and not a # directory traversal, which tftp does not support. # echo Oracle Solaris Network Boot echo -n Please wait while the network boot configuration file is located. if keystatus -s; then set debug=true echo echo Shift key pressed -- enabling network config file debug else sleep 1 if read -dn debug; then if regexp "[Dd][Dd]*" "$debug"; then echo echo "'d' key pressed - enabling network config file debug" set debug=true else unset debug fi fi fi if [ -n "$debug" ]; then echo "" set echo "" echo Searching for config file fi if [ -n "$net_default_boot_file" -a -n "$net_default_mac"]; then # Could be UEFI or BIOS set net_bootfile="$net_default_boot_file" set net_mac="$net_default_mac" elif [ -n "$net_efinet0_boot_file" ]; then # Booting via UEFI set net_bootfile="$net_efinet0_boot_file" set net_mac="$net_efinet0_mac" elif [ -n "$net_pxe_boot_file" ]; then # Booting via BIOS/PXE set net_bootfile="$net_pxe_boot_file" set net_mac="$net_pxe_mac" elif [ -n "$debug" ]; then echo Neither "(net_default_boot_file AND net_default_mac)" nor echo net_efinet0_boot_file nor net_pxe_boot_file are set. echo Config file search will only include one location. fi # check for grub.cfg.01 if [ ! -z $net_mac ]; then tr -U -s mac $net_mac regexp ([^:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]+) $mac -s 1:a -s 2:b -s 3:c -s 4:d -s 5:e -s 6:f set mac=$a$b$c$d$e$f set clientcfgfile=grub.cfg.01$mac if [ -n "$debug" ]; then echo looking for $clientcfgfile else echo -n . fi if [ -s $clientcfgfile ]; then if [ -n "$debug" ]; then echo Found. Press ENTER to continue. read discard else echo -n . fi configfile $clientcfgfile found=1 fi fi # If there is a directory component of the boot file, # march up the directory hierarchy starting there # looking for the grub.cfg[.] if [ -z "$found" -a ! -z $net_bootfile ]; then if regexp ".*/.*" $net_bootfile ; then regexp "(.*)/" $net_bootfile -s 1:path while [ -n "$path" ]; do if [ -n "$clientcfgfile" ]; then if [ -n "$debug" ]; then echo looking for "${path}/$clientcfgfile" else echo -n . fi if [ -s "${path}/$clientcfgfile" ]; then if [ -n "$debug" ]; then echo Found. Press ENTER to continue. read discard else echo -n . fi configfile "${path}/$clientcfgfile" found=1 fi fi if [ -n "$debug" ]; then echo looking for ${path}/grub.cfg else echo -n . fi if [ -s "${path}/grub.cfg" ]; then if [ -n "$debug" ]; then echo Found. Press ENTER to continue. read discard else echo -n . fi configfile "${path}/grub.cfg" found=1 fi # go to the next path component: if ! regexp "(.*)/" $path -s 1:path; then break fi done fi # Check for grub.cfg. # For BIOS PXE: regexp "pxegrub2\.(.*)" $net_bootfile -s 1:suffix if [ -z $suffix ]; then # For UEFI64 network boot application: regexp "grub2netx64\.efi\.(.*)" $net_bootfile -s 1:suffix if [ -z $suffix ]; then set suffix=$net_bootfile fi fi set cfgfile=grub.cfg.$suffix if [ -n "$debug" ]; then echo looking for $cfgfile else echo -n . fi if [ -s $cfgfile ]; then if [ -n "$debug" ]; then echo Found. Press ENTER to continue. read discard else echo -n . fi configfile $cfgfile found=1 fi fi if [ -z "$found" ]; then # Check for grub.cfg set cfgfile=boot/grub/grub.cfg if [ -n "$debug" ]; then echo Final attempt: looking for $cfgfile else echo -n . fi if [ -s $cfgfile ]; then if [ -n "$debug" ]; then echo Found. Press ENTER to continue. read discard else echo -n . fi configfile $cfgfile found=1 fi fi if [ -z "$found" ]; then echo echo No GRUB2 network configuration file could be located on the TFTP server! echo echo "Press 'r' to reboot or press to enter GRUB" read input if [ "$input" = "r" -o "$input" = "R" ]; then echo Rebooting... reboot fi fi