PageRenderTime 61ms CodeModel.GetById 50ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/grub.d/10_linux

http://github.com/brinkman83/bashrc
Shell | 153 lines | 116 code | 16 blank | 21 comment | 24 complexity | 937e21c78def99a9cf22d2c95280ef88 MD5 | raw file
  1#! /bin/sh -e
  2
  3# grub-mkconfig helper script.
  4# Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
  5#
  6# GRUB is free software: you can redistribute it and/or modify
  7# it under the terms of the GNU General Public License as published by
  8# the Free Software Foundation, either version 3 of the License, or
  9# (at your option) any later version.
 10#
 11# GRUB is distributed in the hope that it will be useful,
 12# but WITHOUT ANY WARRANTY; without even the implied warranty of
 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14# GNU General Public License for more details.
 15#
 16# You should have received a copy of the GNU General Public License
 17# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 18
 19prefix=/usr
 20exec_prefix=${prefix}
 21bindir=${exec_prefix}/bin
 22libdir=${exec_prefix}/lib
 23. ${libdir}/grub/grub-mkconfig_lib
 24
 25export TEXTDOMAIN=grub
 26export TEXTDOMAINDIR=@LOCALEDIR@
 27
 28CLASS="--class gnu-linux --class gnu --class os"
 29
 30if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
 31  OS=GNU/Linux
 32else
 33  OS="${GRUB_DISTRIBUTOR}"
 34  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr '[A-Z]' '[a-z]' | cut -d' ' -f1) ${CLASS}"
 35fi
 36
 37# loop-AES arranges things so that /dev/loop/X can be our root device, but
 38# the initrds that Linux uses don't like that.
 39case ${GRUB_DEVICE} in
 40  /dev/loop/*|/dev/loop[0-9])
 41    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
 42    # We can't cope with devices loop-mounted from files here.
 43    case ${GRUB_DEVICE} in
 44      /dev/*) ;;
 45      *) exit 0 ;;
 46    esac
 47  ;;
 48esac
 49
 50if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
 51    || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
 52    || [ "`grub-probe -t abstraction --device ${GRUB_DEVICE} | sed -e 's,.*\(lvm\).*,\1,'`" = "lvm"  ] ; then
 53  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
 54else
 55  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
 56fi
 57
 58# add crashkernel option if we have the required tools
 59if [ -x "/usr/bin/makedumpfile" ] && [ -x "/sbin/kexec" ]; then
 60    GRUB_CMDLINE_EXTRA="$GRUB_CMDLINE_EXTRA crashkernel=384M-2G:64M,2G-:128M"
 61fi
 62
 63linux_entry ()
 64{
 65  os="$1"
 66  version="$2"
 67  recovery="$3"
 68  args="$4"
 69  if ${recovery} ; then
 70    title="$(gettext_quoted "%s, with Linux %s (recovery mode)")"
 71  else
 72    title="$(gettext_quoted "%s, with Linux %s")"
 73  fi
 74  printf "menuentry '${title}' ${CLASS} {\n" "${os}" "${version}"
 75  cat << EOF
 76	recordfail
 77EOF
 78  save_default_entry | sed -e "s/^/\t/"
 79
 80  if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ]; then
 81	  cat << EOF
 82	set gfxpayload=$GRUB_GFXPAYLOAD_LINUX
 83EOF
 84  fi
 85
 86  if [ -z "${prepare_boot_cache}" ]; then
 87    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/")"
 88  fi
 89  printf '%s\n' "${prepare_boot_cache}"
 90  if [ "x$5" != "xquiet" ]; then
 91    cat << EOF
 92	echo	'$(printf "$(gettext_quoted "Loading Linux %s ...")" ${version})'
 93EOF
 94  fi
 95  cat << EOF
 96	linux	${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
 97EOF
 98  if [ "x$5" != "xquiet" ]; then
 99    cat << EOF
100	echo	'$(gettext_quoted "Loading initial ramdisk ...")'
101EOF
102  fi
103  if test -n "${initrd}" ; then
104    cat << EOF
105	initrd	${rel_dirname}/${initrd}
106EOF
107  fi
108  cat << EOF
109}
110EOF
111}
112
113list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do
114        if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
115      done`
116prepare_boot_cache=
117
118while [ "x$list" != "x" ] ; do
119  linux=`version_find_latest $list`
120  echo "Found linux image: $linux" >&2
121  basename=`basename $linux`
122  dirname=`dirname $linux`
123  rel_dirname=`make_system_path_relative_to_its_root $dirname`
124  version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
125  alt_version=`echo $version | sed -e "s,\.old$,,g"`
126  linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
127
128  initrd=
129  for i in "initrd.img-${version}" "initrd-${version}.img" \
130	   "initrd-${version}" "initrd.img-${alt_version}" \
131	   "initrd-${alt_version}.img" "initrd-${alt_version}"; do
132    if test -e "${dirname}/${i}" ; then
133      initrd="$i"
134      break
135    fi
136  done
137  if test -n "${initrd}" ; then
138    echo "Found initrd image: ${dirname}/${initrd}" >&2
139  else
140    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
141    linux_root_device_thisversion=${GRUB_DEVICE}
142  fi
143
144  linux_entry "${OS}" "${version}" false \
145      "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_EXTRA} ${GRUB_CMDLINE_LINUX_DEFAULT}" \
146      quiet
147  if [ "x${GRUB_DISABLE_LINUX_RECOVERY}" != "xtrue" ]; then
148    linux_entry "${OS}" "${version}" true \
149	"single ${GRUB_CMDLINE_LINUX}"
150  fi
151
152  list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
153done