Advertisement
digrouz

/mnt/gentoo/etc/grub.d/20_linux_xen

Jan 16th, 2012
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.26 KB | None | 0 0
  1. cat /mnt/gentoo/etc/grub.d/20_linux_xen
  2. #! /bin/sh
  3. set -e
  4.  
  5. # grub-mkconfig helper script.
  6. # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  7. #
  8. # GRUB is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # GRUB is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  20.  
  21. prefix=/usr
  22. exec_prefix=${prefix}
  23. bindir=/bin
  24. libdir=/lib64
  25. . ${libdir}/grub/grub-mkconfig_lib
  26.  
  27. export TEXTDOMAIN=grub
  28. export TEXTDOMAINDIR=${prefix}/share/locale
  29.  
  30. CLASS="--class gnu-linux --class gnu --class os --class xen"
  31.  
  32. if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  33.   OS=GNU/Linux
  34. else
  35.   OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  36.   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1) ${CLASS}"
  37. fi
  38.  
  39. # loop-AES arranges things so that /dev/loop/X can be our root device, but
  40. # the initrds that Linux uses don't like that.
  41. case ${GRUB_DEVICE} in
  42.   /dev/loop/*|/dev/loop[0-9])
  43.     GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  44.   ;;
  45. esac
  46.  
  47. if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  48.     || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  49.     || uses_abstraction "${GRUB_DEVICE}" lvm; then
  50.   LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  51. else
  52.   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  53. fi
  54.  
  55. if [ "x`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2>/dev/null || true`" = xbtrfs ]; then
  56.   rootsubvol="`make_system_path_relative_to_its_root /`"
  57.   rootsubvol="${rootsubvol#/}"
  58.   if [ "x${rootsubvol}" != x ]; then
  59.     GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
  60.   fi
  61. fi
  62.  
  63. linux_entry ()
  64. {
  65.   os="$1"
  66.   version="$2"
  67.   xen_version="$3"
  68.   recovery="$4"
  69.   args="$5"
  70.   xen_args="$6"
  71.   if ${recovery} ; then
  72.     title="$(gettext_quoted "%s, with Xen %s and Linux %s (recovery mode)")"
  73.  else
  74.    title="$(gettext_quoted "%s, with Xen %s and Linux %s")"
  75.  fi
  76.  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${xen_version}" "${version}"
  77.  if ! ${recovery} ; then
  78.      save_default_entry | sed -e "s/^/\t/"
  79.  fi
  80.  
  81.  if [ -z "${prepare_boot_cache}" ]; then
  82.    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  83.  fi
  84.  printf '%s\n' "${prepare_boot_cache}"
  85.  xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
  86.  lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
  87.  cat << EOF
  88.        echo    '$xmessage'
  89.        multiboot       ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args}
  90.        echo    '$lmessage'
  91.        module  ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
  92. EOF
  93.  if test -n "${initrd}" ; then
  94.    message="$(gettext_printf "Loading initial ramdisk ...")"
  95.    cat << EOF
  96.        echo    '$message'
  97.        module  ${rel_dirname}/${initrd}
  98. EOF
  99.  fi
  100.  cat << EOF
  101. }
  102. EOF
  103. }
  104.  
  105. linux_list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
  106.    if grub_file_is_not_garbage "$i"; then
  107.        basename=$(basename $i)
  108.        version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
  109.        dirname=$(dirname $i)
  110.        config=
  111.        for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
  112.            if test -e "${j}" ; then
  113.                config="${j}"
  114.                break
  115.            fi
  116.        done
  117.        if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then echo -n "$i " ; fi
  118.    fi
  119.    done`
  120. if [ "x${linux_list}" = "x" ] ; then
  121.    exit 0
  122. fi
  123. xen_list=`for i in /boot/xen*; do
  124.        if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
  125.      done`
  126. prepare_boot_cache=
  127.  
  128. while [ "x${xen_list}" != "x" ] ; do
  129.    list="${linux_list}"
  130.    current_xen=`version_find_latest $xen_list`
  131.    xen_basename=`basename ${current_xen}`
  132.    xen_dirname=`dirname ${current_xen}`
  133.    rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
  134.    xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
  135.    echo "submenu \"Xen ${xen_version}\" {"
  136.    while [ "x$list" != "x" ] ; do
  137.        linux=`version_find_latest $list`
  138.        echo "Found linux image: $linux" >&2
  139.        basename=`basename $linux`
  140.        dirname=`dirname $linux`
  141.        rel_dirname=`make_system_path_relative_to_its_root $dirname`
  142.        version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  143.        alt_version=`echo $version | sed -e "s,\.old$,,g"`
  144.        linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  145.  
  146.        initrd=
  147.        for i in "initrd.img-${version}" "initrd-${version}.img" \
  148.            "initrd-${version}" "initrd.img-${alt_version}" \
  149.            "initrd-${alt_version}.img" "initrd-${alt_version}" \
  150.            "initramfs-genkernel-${version}" \
  151.            "initramfs-genkernel-${alt_version}" ; do
  152.            if test -e "${dirname}/${i}" ; then
  153.                initrd="$i"
  154.                break
  155.            fi
  156.        done
  157.        if test -n "${initrd}" ; then
  158.            echo "Found initrd image: ${dirname}/${initrd}" >&2
  159.        else
  160.    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
  161.            linux_root_device_thisversion=${GRUB_DEVICE}
  162.        fi
  163.  
  164.        linux_entry "${OS}" "${version}" "${xen_version}" false \
  165.            "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
  166.        if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
  167.            linux_entry "${OS}" "${version}" "${xen_version}" true \
  168.                "single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
  169.        fi
  170.  
  171.        list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  172.    done
  173.    echo "}"
  174.    xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $current_xen | tr '\n' ' '`
  175. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement