Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 4.36 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --- /etc/grub.d/09_xen.orig     1969-12-31 21:00:00.000000000 -0300
  2. +++ /etc/grub.d/09_xen  2010-07-31 21:31:51.131694550 -0300
  3. @@ -0,0 +1,129 @@
  4. +#! /bin/sh -e
  5. +
  6. +if [ -f /usr/lib/grub/grub-mkconfig_lib ]; then
  7. +  . /usr/lib/grub/grub-mkconfig_lib
  8. +else
  9. +  # no grub file, so we notify and exit gracefully
  10. +  echo "Cannot find grub config file, exiting." >&2
  11. +  exit 0
  12. +fi
  13. +
  14. +XEN_HYPERVISOR_CMDLINE=
  15. +XEN_LINUX_CMDLINE="console=tty0"
  16. +[ -r /etc/xen/grub.conf ] && . /etc/xen/grub.conf
  17. +
  18. +CLASS="--class gnu-linux --class gnu --class os"
  19. +
  20. +if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
  21. +  OS=GNU/Linux
  22. +else
  23. +  OS="${GRUB_DISTRIBUTOR} GNU/Linux"
  24. +  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
  25. +fi
  26. +
  27. +# loop-AES arranges things so that /dev/loop/X can be our root device, but
  28. +# the initrds that Linux uses don't like that.
  29. +case ${GRUB_DEVICE} in
  30. +  /dev/loop/*|/dev/loop[0-9])
  31. +    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
  32. +  ;;
  33. +esac
  34. +
  35. +if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
  36. +    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
  37. +    || [ "`grub-probe -t abstraction --device ${GRUB_DEVICE} | sed -e 's,.*\(lvm\).*,\1,'`" = "lvm"  ] ; then
  38. +  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
  39. +else
  40. +  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
  41. +fi
  42. +
  43. +xen_entry ()
  44. +{
  45. +  os="$1"
  46. +  xen_version="$2"
  47. +  version="$3"
  48. +  xen_args="$4"
  49. +  args="$5"
  50. +  printf "menuentry 'Xen %s / %s, with Linux %s' --class xen ${CLASS} {\n" "${xen_version}" "${os}" "${version}"
  51. +  save_default_entry | sed -e "s/^/\t/"
  52. +
  53. +  if [ -z "${prepare_boot_cache}" ]; then
  54. +    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
  55. +  fi
  56. +  printf '%s\n' "${prepare_boot_cache}"
  57. +  cat << EOF
  58. +       echo    '$(printf "Loading Xen %s ..." ${xen_version})'
  59. +       multiboot       ${rel_dirname}/${xen_basename} ${rel_dirname}/${xen_basename} ${xen_args}
  60. +       echo    $(printf "$(gettext "Loading Linux %s ...")" ${version})
  61. +       module  ${rel_dirname}/${basename} ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
  62. +EOF
  63. +  if test -n "${initrd}" ; then
  64. +    cat << EOF
  65. +       echo    "Loading initial ramdisk ..."
  66. +       module  ${rel_dirname}/${initrd}
  67. +EOF
  68. +  fi
  69. +  cat << EOF
  70. +}
  71. +EOF
  72. +}
  73. +
  74. +xen_list=`for i in /boot/xen-*.gz /xen-*.gz ; do
  75. +       if grub_file_is_not_garbage "$i" ; then echo -n "$i "; fi
  76. +done`
  77. +prepare_boot_cache=
  78. +
  79. +while [ "x$xen_list" != "x" ] ; do
  80. +  xen=`version_find_latest $xen_list`
  81. +  echo "Found Xen hypervisor image: $xen" >&2
  82. +  xen_basename=`basename $xen`
  83. +  xen_dirname=`dirname $xen`
  84. +  rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
  85. +  xen_version=`echo $xen_basename | sed -e "s,^[^0-9]*-,,g" | sed -e "s,.gz,,g"`
  86. +  alt_xen_version=`echo $xen_version | sed -e "s,\.old$,,g"`
  87. +
  88. +  xen_configfiles=`grep -l 'CONFIG_XEN_PRIVILEGED_GUEST=y' /boot/config-*`
  89. +
  90. +  for i in $xen_configfiles ; do
  91. +    i=`echo $i | sed -e "s,/boot/config-,/boot/vmlinuz26-,g"`;
  92. +    if grub_file_is_not_garbage "$i"; then
  93. +      list="$list $i";
  94. +    fi
  95. +  done
  96. +
  97. +  while [ "x$list" != "x" ] ; do
  98. +    linux=`version_find_latest $list`
  99. +    echo -e "\tFound linux image: $linux" >&2
  100. +    basename=`basename $linux`
  101. +    dirname=`dirname $linux`
  102. +    rel_dirname=`make_system_path_relative_to_its_root $dirname`
  103. +    version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
  104. +    base_init=`echo $basename | sed -e "s,vmlinuz,kernel,g"`
  105. +    alt_version="${base_init}-fallback"
  106. +    linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
  107. +    initrd=
  108. +
  109. +    for i in "${base_init}.img"; do
  110. +       if test -e "${dirname}/${i}" ; then
  111. +         initrd="$i"
  112. +         break
  113. +       fi
  114. +    done
  115. +    if test -n "${initrd}" ; then
  116. +      echo -e "\tFound initrd image: ${dirname}/${initrd}" >&2
  117. +    else
  118. +      # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
  119. +      linux_root_device_thisversion=${GRUB_DEVICE}
  120. +    fi
  121. +
  122. +    xen_entry "${OS}" "${xen_version}" "${version}" \
  123. +        "${XEN_HYPERVISOR_CMDLINE}" \
  124. +       "${XEN_LINUX_CMDLINE}"
  125. +
  126. +    list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
  127. +  done
  128. +
  129. +  xen_list=`echo $xen_list | tr ' ' '\n' | grep -vx $xen | tr '\n' ' '`
  130. +done
  131. +
  132. +