Skip to content

Commit

Permalink
Merge pull request #1339 from schabrolles/GRUB_netboot
Browse files Browse the repository at this point in the history
Added support for "grub PXE style" on non x86 platform
via the new config variable PXE_CONFIG_GRUB_STYLE
together with another new config variable PXE_TFTP_IP
as described in default.conf and in the example config file
conf/examples/RHEL7-PPC64LE-Mulitpath-PXE-GRUB.conf
because some non x86 platform (like ppc64/ppc64le)
do not support native PXE boot so that now GRUB
could be used as a PXE alternative.
  • Loading branch information
jsmeix committed May 4, 2017
2 parents 2b1654b + 45a7fc1 commit ac6cc5a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 7 deletions.
10 changes: 10 additions & 0 deletions usr/share/rear/conf/default.conf
Expand Up @@ -434,6 +434,10 @@ PXE_CONFIG_URL=
# put this before the hostname on the PXE server
PXE_CONFIG_PREFIX=rear-

# TFPT IP server. needed to create grub menu when PXE_CONFIG_GRUB_STYLE=y
# If not set, we gonna try to get TFTP IP from PXE_TFTP_URL
PXE_TFTP_IP=

# where should we put the TFTP files ? (legacy way)
PXE_TFTP_PATH=/var/lib/rear/output
# where should we put the TFTP files ? (URL style)
Expand All @@ -448,6 +452,12 @@ PXE_CREATE_LINKS=MAC
# Should I remove old symlinks for this host ? [BOOL]
PXE_REMOVE_OLD_LINKS=

# Should I use PXE based on GRUB2 instead of PXE legacy. [BOOL] (default is no)
# PXE based on GRUB2 can be used by none x86 platform (like POWER ppc64/ppc64le).
# More information on the GRUB PXE setup can be found here :
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/chap-installation-server-setup.html#sect-network-boot-setup-ppc-grub2
PXE_CONFIG_GRUB_STYLE=

# The way we start up in our PXE mode (keywords known are 'automatic', 'unattended', and empty)
# 'automatic' is the auto_recover mode which means boot automatic with ReaR and execute a 'rear recover', but
# when a question has to be answered (e.g. during migration mode) it will wait on an answer...
Expand Down
36 changes: 36 additions & 0 deletions usr/share/rear/conf/examples/RHEL7-PPC64LE-Mulitpath-PXE-GRUB.conf
@@ -0,0 +1,36 @@
# Default is to create Relax-and-Recover rescue media as ISO image
# set OUTPUT to change that
# set BACKUP to activate an automated (backup and) restore of your data
# Possible configuration values can be found in /usr/share/rear/conf/default.conf
#
# This file (local.conf) is intended for manual configuration. For configuration
# through packages and other automated means we recommend creating a new
# file named site.conf next to this file and to leave the local.conf as it is.
# Our packages will never ship with a site.conf.

AUTOEXCLUDE_MULTIPATH=n
BOOT_OVER_SAN=y

OUTPUT=PXE
OUTPUT_PREFIX_PXE=rear/$HOSTNAME

PXE_CONFIG_GRUB_STYLE=y
# On your TFTP server:
# In your tftpboot dir execute the following command to create the netboot directory based on GRUB.
# grub2-mknetdir --net-directory=/var/lib/tftpboot
# config directory will be /var/lib/tftpboot/boot/grub2/powerpc-ieee1275
# More information about setting up a PXE based on Grub on POWER : https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Installation_Guide/chap-installation-server-setup.html#sect-network-boot-setup-ppc-grub2
PXE_TFTP_IP=XX.YY.ZZ.AA
PXE_CONFIG_URL="nfs://$PXE_TFTP_IP/var/lib/tftpboot/boot/grub2/powerpc-ieee1275"
PXE_CREATE_LINKS=IP
PXE_REMOVE_OLD_LINKS=y
PXE_TFTP_URL="nfs://$PXE_TFTP_IP/var/lib/tftpboot"

USE_STATIC_NETWORKING=y

BACKUP=NETFS
BACKUP_URL=nfs://XX.YY.ZZ.AA/NFS/rear
#####################################
## Optional
## Reduce the size of initrd, but can be long and use more CPU (could help when booting PPC64 in POWERVM with TFTP)
#REAR_INITRD_COMPRESSION=lzma
43 changes: 43 additions & 0 deletions usr/share/rear/lib/bootloader-functions.sh
Expand Up @@ -612,3 +612,46 @@ function make_pxelinux_config {
# end of function make_pxelinux_config
}

function make_pxelinux_config_grub {
net_default_server_opt=""

# Be sure that TFTP Server IP is set with TFTP_SERVER_IP Variable.
# else set it based on PXE_TFTP_UR variable.
if [[ -z $PXE_TFTP_IP ]] ; then
if [[ -z $PXE_TFTP_URL ]] ; then
LogPrint "Can't find TFTP IP information. Variable TFTP_SERVER_IP or PXE_TFTP_URL with clear IP address must be set."
return
else
# Get IP address from PXE_TFTP_URL (ex:http://xx.yy.zz.aa:port/foo/bar)
PXE_TFTP_IP=$(echo "$PXE_TFTP_URL" | awk -F'[/:]' '{ print $4 }')
fi
fi

if [ ! -z $PXE_TFTP_IP ]; then
net_default_server_opt="set net_default_server=$PXE_TFTP_IP"
else
LogPrint "WARNING: No valid TFTP IP found. GRUB menu will be generated without net_default_server"
fi

# we use this function only when $PXE_CONFIG_URL is set and $PXE_CONFIG_GRUB_STYLE=y
# TODO First Draft. Need to complete with all other options (see make_pxelinux_config).
echo "menuentry 'Relax-and-Recover v$VERSION' {"
echo "insmod tftp"
echo "$net_default_server_opt"
echo "echo 'Network status: '"
echo "net_ls_cards"
echo "net_ls_addr"
echo "net_ls_routes"
echo "echo"
echo "echo \" Relax-and-Recover Rescue image\""
echo "echo \"---------------------------------\""
echo "echo \"build from host: $HOSTNAME ($OS_VENDOR $OS_VERSION $ARCH)\""
echo "echo \"kernel $KERNEL_VERSION ${IPADDR:+on $IPADDR} $(date -R)\""
echo "echo \"${BACKUP:+BACKUP=$BACKUP} ${OUTPUT:+OUTPUT=$OUTPUT} ${BACKUP_URL:+BACKUP_URL=$BACKUP_URL}\""
echo "echo"
echo "echo 'Loading kernel ...'"
echo "linux (tftp)/$PXE_KERNEL root=/dev/ram0 vga=normal rw $KERNEL_CMDLINE"
echo "echo 'Loading initial ramdisk ...'"
echo "initrd (tftp)/$PXE_INITRD"
echo "}"
}
3 changes: 1 addition & 2 deletions usr/share/rear/output/PXE/default/800_copy_to_tftp.sh
Expand Up @@ -65,7 +65,7 @@ fi


if [[ ! -z "$PXE_TFTP_URL" ]] ; then
LogPrint "Copied kernel+initrd $( du -shc $KERNEL_FILE "$TMP_DIR/$REAR_INITRD_FILENAME" | tail -n 1 | tr -s "\t " " " | cut -d " " -f 1 ) to $PXE_TFTP_URL"
LogPrint "Copied kernel+initrd $( du -shc $KERNEL_FILE "$TMP_DIR/$REAR_INITRD_FILENAME" | tail -n 1 | tr -s "\t " " " | cut -d " " -f 1 ) to $PXE_TFTP_URL/$OUTPUT_PREFIX_PXE"
umount_url $PXE_TFTP_URL $BUILD_DIR/tftpbootfs
rmdir $BUILD_DIR/tftpbootfs >&2
if [[ $? -eq 0 ]] ; then
Expand All @@ -77,4 +77,3 @@ else
# Add to result files
RESULT_FILES=( "${RESULT_FILES[@]}" "$PXE_TFTP_LOCAL_PATH/$PXE_KERNEL" "$PXE_TFTP_LOCAL_PATH/$PXE_INITRD" "$PXE_TFTP_LOCAL_PATH/$PXE_MESSAGE" )
fi

31 changes: 26 additions & 5 deletions usr/share/rear/output/PXE/default/810_create_pxelinux_cfg.sh
Expand Up @@ -25,7 +25,11 @@ fi
# PXE_CONFIG_PREFIX is a "string" (by default rear-) - is the name of PXE boot configuration of $HOSTNAME
PXE_CONFIG_FILE="${PXE_CONFIG_PREFIX}$HOSTNAME"
if [[ ! -z "$PXE_CONFIG_URL" ]] ; then
make_pxelinux_config >"$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
if is_true "$PXE_CONFIG_GRUB_STYLE" ; then
make_pxelinux_config_grub >"$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
else
make_pxelinux_config >"$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
fi
chmod 444 "$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
else
# legacy way using PXE_LOCAL_PATH default
Expand Down Expand Up @@ -53,15 +57,33 @@ if test "$PXE_CREATE_LINKS" -a "$PXE_REMOVE_OLD_LINKS" ; then
done
fi

# When using Grub network boot via tftp/bootp,
# the client is looking at a file named "grub.cfg-01-<MAC>"
# or grub.cfg-<IP in hex>. It is like PXE, but prefixed with "grub.cfg-"
if is_true $PXE_CONFIG_GRUB_STYLE ; then
pxe_link_prefix="grub.cfg-"
else
pxe_link_prefix=""
fi

case "$PXE_CREATE_LINKS" in
IP)
# look only at IPv4 and skip localhost (127...)
ip a | grep inet\ | grep -v inet\ 127 | \
while read inet IP junk ; do
IP=${IP%/*}
ln -sf $v "$PXE_CONFIG_FILE" $(gethostip -x $IP) >&2
# to capture the whole subnet as well
ln -sf $v "$PXE_CONFIG_FILE" $(gethostip -x $IP | cut -c 1-6) >&2
# check if gethostip is available.
if has_binary gethostip &>/dev/null ; then
ln -sf $v "$PXE_CONFIG_FILE" $(gethostip -x $IP) >&2
# to capture the whole subnet as well
ln -sf $v "$PXE_CONFIG_FILE" $(gethostip -x $IP | cut -c 1-6) >&2
else
# if gethostip is not available on your platform (like ppc64),
# use awk to generate IP in hex mode.
ln -sf $v "$PXE_CONFIG_FILE" $pxe_link_prefix$(printf '%02X' ${IP//./ }) >&2
# to capture the whole subnet as well
ln -sf $v "$PXE_CONFIG_FILE" $pxe_link_prefix$(printf '%02X' ${IP//./ } | cut -c 1-6) >&2
fi
done
;;
MAC)
Expand Down Expand Up @@ -93,4 +115,3 @@ else
# Add to result files
RESULT_FILES=( "${RESULT_FILES[@]}" "$PXE_LOCAL_PATH/$PXE_CONFIG_FILE" )
fi

0 comments on commit ac6cc5a

Please sign in to comment.