Index: head/sysutils/grub2-pcbsd/Makefile =================================================================== --- head/sysutils/grub2-pcbsd/Makefile (revision 361987) +++ head/sysutils/grub2-pcbsd/Makefile (revision 361988) @@ -1,93 +1,93 @@ # Created by: kmoore@FreeBSD.org # $FreeBSD$ PORTNAME= grub2-pcbsd PORTVERSION= 2.02p -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= sysutils MASTER_SITES= http://www.pcbsd.org/~kris/software/ \ ftp://ftp.pcbsd.org/pub/software/ DISTNAME= grub-2.02_1 MAINTAINER= kmoore@FreeBSD.org COMMENT= Multiboot boot loader LICENSE= GPLv3 BUILD_DEPENDS= ${LOCALBASE}/bin/flex:${PORTSDIR}/textproc/flex \ ${LOCALBASE}/bin/bash:${PORTSDIR}/shells/bash \ help2man:${PORTSDIR}/misc/help2man WRKSRC= ${WRKDIR}/grub-2.02 CONFLICTS= grub-0* grub2-2* SSP_UNSAFE= yes USE_GCC= yes USE_PYTHON= yes USE_AUTOTOOLS= automake aclocal autoconf ACLOCAL_ARGS= -Im4 GNU_CONFIGURE= yes USES= bison gettext gmake makeinfo tar:xz ONLY_FOR_ARCHS= i386 amd64 INFO= grub grub-dev MAKE_JOBS_UNSAFE= yes CONFIGURE_ARGS= --disable-werror --localedir=${PREFIX}/share/locale CONFIGURE_ENV= CPP="${CC} -E" \ LEX=${LOCALBASE}/bin/flex SUB_FILES= 00_header 10_kfreebsd 10_ktrueos 30_os-prober OPTIONS_DEFINE= MKFONT FUSE OPTIONS_DEFAULT=MKFONT MKFONT_DESC= Build grub-mkfont (require freetype2) FUSE_DESC= Build grub-mount (require FUSE) .include .if ${ARCH} != "amd64" EFIEMU= "@comment " .endif PLIST_SUB+= EFIEMU=${EFIEMU} .if ${PORT_OPTIONS:MMKFONT} LIB_DEPENDS+= libfreetype.so:${PORTSDIR}/print/freetype2 BUILD_DEPENDS+= ${LOCALBASE}/lib/X11/fonts/dejavu/DejaVuSans.ttf:${PORTSDIR}/x11-fonts/dejavu \ ${LOCALBASE}/lib/X11/fonts/local/unifont.pcf.gz:${PORTSDIR}/x11-fonts/gnu-unifont MAN1+= grub-mkfont.1 CONFIGURE_ARGS+= --enable-grub-mkfont .else CONFIGURE_ARGS+= --disable-grub-mkfont MKFONT= "@comment " .endif PLIST_SUB+= MKFONT=${MKFONT} .if ${PORT_OPTIONS:MFUSE} LIB_DEPENDS+= fuse:${PORTSDIR}/sysutils/fusefs-libs CONFIGURE_ARGS+= --enable-grub-mount .else CONFIGURE_ARGS+= --disable-grub-mount FUSE= "@comment " .endif PLIST_SUB+= FUSE=${FUSE} post-patch: @${TOUCH} -t 200001010000 ${WRKSRC}/Makefile.util.def pre-configure: @${REINPLACE_CMD} -e 's|python|${PYTHON_CMD}|g' ${WRKSRC}/autogen.sh cd ${WRKSRC} && ./autogen.sh post-configure: @${LN} -sfh /usr/include/machine /usr/include/sys /usr/include/x86 ${WRKSRC}/grub-core post-install: @${RM} -rf ${STAGEDIR}${PREFIX}/lib/charset.alias @${INSTALL_SCRIPT} ${WRKDIR}/00_header ${STAGEDIR}${PREFIX}/etc/grub.d/ @${INSTALL_SCRIPT} ${WRKDIR}/10_kfreebsd ${STAGEDIR}${PREFIX}/etc/grub.d/ @${INSTALL_SCRIPT} ${WRKDIR}/10_ktrueos ${STAGEDIR}${PREFIX}/etc/grub.d/ @${INSTALL_SCRIPT} ${WRKDIR}/30_os-prober ${STAGEDIR}${PREFIX}/etc/grub.d/ .include Index: head/sysutils/grub2-pcbsd/files/00_header.in =================================================================== --- head/sysutils/grub2-pcbsd/files/00_header.in (revision 361987) +++ head/sysutils/grub2-pcbsd/files/00_header.in (revision 361988) @@ -1,335 +1,354 @@ #! /bin/sh set -e # grub-mkconfig helper script. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # GRUB is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GRUB. If not, see . transform="s,x,x," prefix="/usr/local" exec_prefix="${prefix}" datarootdir="${prefix}/share" grub_lang=`echo $LANG | cut -d . -f 1` export TEXTDOMAIN=grub export TEXTDOMAINDIR="/usr/local/share/locale" . "${datarootdir}/grub/grub-mkconfig_lib" # Set indicator that we haven't written device access yet haveDevAccess=0 # Do this as early as possible, since other commands might depend on it. # (e.g. the `loadfont' command might need lvm or raid modules) for i in ${GRUB_PRELOAD_MODULES} ; do echo "insmod $i" done -if [ "x${GRUB_DEFAULT}" = "x" ] ; then GRUB_DEFAULT=0 ; fi +# If GRUB_DEFAULT is unset, lets figure out which beadm wants to use by default +if [ "x${GRUB_DEFAULT}" = "x" ] ; then + GRUB_DEFAULT=0 + beCount=0 + beadm list -H >/tmp/.grub-beadm.$$ 2>/dev/null + while read line + do + flags=`echo $line | awk '{print $2}'` + + # Is this BE marked as wanting to be used for next boot? Make it default if so + if [ "$flags" = "NR" -o "$flags" = "R" ] ; then + GRUB_DEFAULT="$beCount" + break + fi + + # Moving onto next target + beCount=`expr $beCount + 1` + done < /tmp/.grub-beadm.$$ + rm /tmp/.grub-beadm.$$ +fi if [ "x${GRUB_DEFAULT}" = "xsaved" ] ; then GRUB_DEFAULT='${saved_entry}' ; fi if [ "x${GRUB_TIMEOUT}" = "x" ] ; then GRUB_TIMEOUT=5 ; fi if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=auto ; fi # Check if we have more than one BE, and need to show the menu by default beNum=`beadm list 2>/dev/null | grep -v 'Mountpoint' | wc -l | awk '{print $1}'` if [ $beNum -gt 1 ] ; then GRUB_HIDDEN_TIMEOUT=""; fi if [ "x${GRUB_DEFAULT_BUTTON}" = "x" ] ; then GRUB_DEFAULT_BUTTON="$GRUB_DEFAULT" ; fi if [ "x${GRUB_DEFAULT_BUTTON}" = "xsaved" ] ; then GRUB_DEFAULT_BUTTON='${saved_entry}' ; fi if [ "x${GRUB_TIMEOUT_BUTTON}" = "x" ] ; then GRUB_TIMEOUT_BUTTON="$GRUB_TIMEOUT" ; fi cat << EOF if [ -s \$prefix/grubenv ]; then load_env fi EOF if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then cat < /dev/null ; then font_path="${path}" else continue fi break 2 done done if [ -n "${font_path}" ] ; then cat << EOF if [ x\$feature_default_font_path = xy ] ; then font=unicode else EOF # Make the font accessible if [ $haveDevAccess -ne 1 ] ; then haveDevAccess=1 prepare_grub_to_access_device `${grub_probe} --target=device "${font_path}"` fi cat << EOF font="`make_system_path_relative_to_its_root "${font_path}"`" fi if loadfont \$font ; then EOF else cat << EOF if loadfont unicode ; then EOF fi fi cat << EOF set gfxmode=${GRUB_GFXMODE} load_video insmod gfxterm EOF # Gettext variables and module if [ "x${LANG}" != "xC" -a "x${grub_lang}" != "xen_US" ] ; then cat << EOF set locale_dir=\$prefix/locale set lang=${grub_lang} insmod gettext EOF fi cat <&2 if [ $haveDevAccess -ne 1 ] ; then haveDevAccess=1 prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_THEME"` fi cat << EOF insmod gfxmenu EOF themedir="`dirname "$GRUB_THEME"`" for x in "$themedir"/*.pf2 "$themedir"/f/*.pf2; do if [ -f "$x" ]; then cat << EOF loadfont (\$root)`make_system_path_relative_to_its_root $x` EOF fi done if [ x"`echo "$themedir"/*.jpg`" != x"$themedir/*.jpg" ] || [ x"`echo "$themedir"/*.jpeg`" != x"$themedir/*.jpeg" ]; then cat << EOF insmod jpeg EOF fi if [ x"`echo "$themedir"/*.png`" != x"$themedir/*.png" ]; then cat << EOF insmod png EOF fi if [ x"`echo "$themedir"/*.tga`" != x"$themedir/*.tga" ]; then cat << EOF insmod tga EOF fi cat << EOF set theme=(\$root)`make_system_path_relative_to_its_root $GRUB_THEME` export theme EOF elif [ "x$GRUB_BACKGROUND" != x ] && [ -f "$GRUB_BACKGROUND" ] \ && is_path_readable_by_grub "$GRUB_BACKGROUND"; then gettext_printf "Found background: %s\n" "$GRUB_BACKGROUND" >&2 case "$GRUB_BACKGROUND" in *.png) reader=png ;; *.tga) reader=tga ;; *.jpg|*.jpeg) reader=jpeg ;; *) gettext "Unsupported image format" >&2; echo >&2; exit 1 ;; esac if [ $haveDevAccess -ne 1 ] ; then haveDevAccess=1 prepare_grub_to_access_device `${grub_probe} --target=device "$GRUB_BACKGROUND"` fi cat << EOF insmod $reader background_image -m stretch `make_system_path_relative_to_its_root "$GRUB_BACKGROUND"` EOF fi fi make_timeout () { if [ "x${1}" != "x" ] ; then if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ; then verbose= else verbose=" --verbose" fi cat << EOF echo "Hold Left-Shift for menu.." if sleep$verbose --interruptible ${1} ; then if keystatus --shift; then set timeout=-1 else set timeout=0 fi fi EOF else cat << EOF set timeout=${2} EOF fi } if [ "x$GRUB_BUTTON_CMOS_ADDRESS" != "x" ]; then cat </dev/null if [ $? -ne 0 ] ; then echo "Failed to mount ${1}" >&2 return fi else fMnt="" fi # Create our placeholder to save _load entries to parse touch /tmp/.lRObjs.$$ touch /tmp/.lSysCtls.$$ # Loader files, in order of which to read them lFiles="${fMnt}/boot/loader.conf.local ${fMnt}/boot/loader.conf ${fMnt}/boot/loader.conf.trueos ${fMnt}/boot/loader.conf.pcbsd" for f in $lFiles do if [ ! -e "$f" ] ; then continue ; fi # Lets parse any of the _load= lines grep "_load=" ${f} | grep -v "^#" >/tmp/.lObjs.$$ while read line do loadVal="`echo $line | cut -d '=' -f 1`" # Is this value already set in a higher priority file? grep -q "^${loadVal}" /tmp/.lRObjs.$$ if [ $? -eq 0 ];then continue; fi # Save this value for later echo "$line" >> /tmp/.lRObjs.$$ haveObjs=1 done < /tmp/.lObjs.$$ rm /tmp/.lObjs.$$ # Lets look for any sysctls to set grep "." ${f} | grep "=" | grep -v "^#" | grep -v "_load" >/tmp/.sObjs.$$ while read line do loadVal="`echo $line | cut -d '=' -f 1`" # Is this value already set in a higher priority file? grep -q "^${loadVal}" /tmp/.lSysCtls.$$ if [ $? -eq 0 ];then continue; fi # Save this value for later echo "$line" >> /tmp/.lSysCtls.$$ haveSysCtls=1 done < /tmp/.sObjs.$$ rm /tmp/.sObjs.$$ done # Now lets echo out the modules to load if [ "$haveObjs" = "1" ] ; then while read line do echo "$line" | grep -q '"YES"' if [ $? -ne 0 ] ; then continue ; fi module="`echo $line | cut -d '=' -f 1 | sed 's|_load||g'`" # Try to locate module now if [ -e "${fMnt}/boot/kernel/${module}.ko" ] ; then mPath="kernel" elif [ -e "${fMnt}/boot/modules/${module}.ko" ] ; then mPath="modules" else # This isn't a module that we can see, lets set it as a variable #echo "No such module $line, setting as a variable" >&2 echo "$line" >> /tmp/.lSysCtls.$$ continue fi echo " kfreebsd_module_elf ${loadPrefix}/@/boot/${mPath}/${module}.ko" done < /tmp/.lRObjs.$$ fi # Any sysctls to set? if [ "$haveSysCtls" = "1" ] ; then while read line do # Strip out the vfs.root.mountfrom, we set that elsewhere echo "$line" | grep -q "vfs.root.mountfrom" if [ $? -eq 0 ] ; then continue ; fi val="`echo $line | sed 's|"||g'`" echo " set kFreeBSD.${val}" done < /tmp/.lSysCtls.$$ fi rm /tmp/.lRObjs.$$ rm /tmp/.lSysCtls.$$ if [ -n "$1" ] ; then umount /mnt.$$ >/dev/null rmdir /mnt.$$ >/dev/null fi } detect_beadm() { which -s beadm if [ $? -ne 0 ] ; then return 0; fi # Check if we are running from the installer and use its beadm if [ -e "/root/beadm.install" ] ; then BEADM="/root/beadm.install" else BEADM="`which beadm`" fi ${BEADM} list >/dev/null 2>/dev/null if [ $? -ne 0 ] ; then return 0; fi if [ -e "/etc/defaults/pcbsd" ] ; then NICK="PC-BSD" else NICK="TrueOS" fi # Get list of beadm datasets - for b in `${BEADM} list 2>/dev/null| grep -v "Created" | cut -d ' ' -f 1` - do + for b in `${BEADM} list -H 2>/dev/null | awk '{print $1}'` + do # Got a beadm snapshot, lets get the complete dataset name beLine=`${BEADM} list -a | grep "/$BEDS/${b}"` cdataset=`echo $beLine | awk '{print $1}'` cdatadate=`echo $beLine | awk '{print $5}'` cdatatime=`echo $beLine | awk '{print $6}'` ztank=`echo $cdataset | cut -d '/' -f 1` shortdataset="/`echo $cdataset | cut -d '/' -f 2-5`" # First part of this dataset cat > /tmp/.grubdataset.$$.1 << EOF insmod zfs search --no-floppy -s -l $ztank EOF # Second part of loader to save cat > /tmp/.grubdataset.$$.2 << EOF kfreebsd_module ${shortdataset}/@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache set kFreeBSD.vfs.root.mountfrom=zfs:$cdataset EOF # Now lets look for options in loader.conf to load loadPrefix="${shortdataset}" # If this is the current mounted dataset, we can skip mounting it mount | grep -q -e "$cdataset on / (" -e "$cdataset on /mnt (" if [ $? -eq 0 ] ; then display_loaderopts >>/tmp/.grubdataset.$$.2 else display_loaderopts $cdataset >> /tmp/.grubdataset.$$.2 fi # Lets start a submenu for each BE cat << EOF # Start TrueOS BE Submenu submenu "${NICK} ($b) - ${cdatadate} ${cdatatime}" { EOF # Lets do the default entry first ################################# cat << EOF menuentry "Normal Bootup" { EOF # Get the dataset guts cat /tmp/.grubdataset.$$.1 echo " kfreebsd ${shortdataset}/@/boot/kernel/kernel" echo " kfreebsd_loadenv ${shortdataset}@/boot/device.hints" cat /tmp/.grubdataset.$$.2 # Set any options cat << EOF } EOF # Next lets do single user mode ################################# cat << EOF menuentry "Single User Mode" { EOF # Get the dataset guts cat /tmp/.grubdataset.$$.1 echo " kfreebsd ${shortdataset}/@/boot/kernel/kernel -s" echo " kfreebsd_loadenv ${shortdataset}@/boot/device.hints" cat /tmp/.grubdataset.$$.2 # Set any options cat << EOF } EOF # Next lets do verbose mode ################################# cat << EOF menuentry "Verbose Mode" { EOF # Get the dataset guts cat /tmp/.grubdataset.$$.1 echo " kfreebsd ${shortdataset}/@/boot/kernel/kernel -v" echo " kfreebsd_loadenv ${shortdataset}@/boot/device.hints" cat /tmp/.grubdataset.$$.2 # Set any options cat << EOF } EOF if [ -e "/etc/defaults/pcbsd" ] ; then # Next lets do display wizard ################################# cat << EOF menuentry "Run the Display Wizard" { EOF # Get the dataset guts cat /tmp/.grubdataset.$$.1 echo " kfreebsd ${shortdataset}/@/boot/kernel/kernel" echo " kfreebsd_loadenv ${shortdataset}@/boot/device.hints" cat /tmp/.grubdataset.$$.2 # Set any options cat << EOF set kFreeBSD.runwiz=YES } EOF # Now for vesa mode ################################# cat << EOF menuentry "Run X in vesa mode" { EOF # Get the dataset guts cat /tmp/.grubdataset.$$.1 echo " kfreebsd ${shortdataset}/@/boot/kernel/kernel" echo " kfreebsd_loadenv ${shortdataset}@/boot/device.hints" cat /tmp/.grubdataset.$$.2 # Set any options cat << EOF set kFreeBSD.xvesa=YES } EOF fi # Lastly lets close the submenu section cat << EOF } # End TrueOS BE EOF done # Cleanup after ourselves if [ -e "/tmp/.grubdataset.$$.1" ] ; then rm /tmp/.grubdataset.$$.1 rm /tmp/.grubdataset.$$.2 fi } # Detect our types of disk layouts detect_beadm