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