1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # XXX: we need to review menu.lst vs grub.conf handling. We've been converting
6 # all systems to grub.conf (and symlinking menu.lst to grub.conf), but
7 # we never updated any of the source code (it still all wants menu.lst),
8 # and there is no indication that upstream is making the transition.
10 inherit eutils mount-boot
12 PATCHVER="1.7" # Not used, just for tracking with main grub
14 DESCRIPTION="GNU GRUB Legacy boot loader (static build)"
16 HOMEPAGE="http://www.gnu.org/software/grub/"
17 SRC_URI="mirror://gentoo/${PF}.tar.bz2"
20 KEYWORDS="-* amd64 ~x86"
22 DEPEND="!<sys-boot/grub-2"
26 cp -a "${WORKDIR}"/* "${D}"/
30 # Below this point, everything is also used in grub-static!
31 # Please keep in sync!
38 [[ ! -e ${dir} ]] && die "${dir} does not exist!"
39 [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot"
41 if [[ ! -e ${dir} ]] ; then
42 mkdir "${dir}" || die "${dir} does not exist!"
45 # change menu.lst to grub.conf
46 if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then
47 mv -f "${dir}"/menu.lst "${dir}"/grub.conf
49 ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf"
53 if [[ ! -e ${dir}/menu.lst ]]; then
54 einfo "Linking from new grub.conf name to menu.lst"
55 ln -snf grub.conf "${dir}"/menu.lst
58 if [[ -e ${dir}/stage2 ]] ; then
59 mv "${dir}"/stage2{,.old}
60 ewarn "*** IMPORTANT NOTE: you must run grub and install"
61 ewarn "the new version's stage1 to your MBR. Until you do,"
62 ewarn "stage1 and stage2 will still be the old version, but"
63 ewarn "later stages will be the new version, which could"
64 ewarn "cause problems such as an unbootable system."
65 ewarn "This means you must use either grub-install or perform"
66 ewarn "root/setup manually! For more help, see the handbook:"
67 ewarn "https://www.gentoo.org/doc/en/handbook/handbook-${ARCH}.xml?part=1&chap=10#grub-install-auto"
71 einfo "Copying files from /lib/grub, /usr/lib/grub and /usr/share/grub to ${dir}"
73 "${ROOT}"/lib*/grub/*/* \
74 "${ROOT}"/usr/lib*/grub/*/* \
75 "${ROOT}"/usr/share/grub/* ; do
76 [[ -f ${x} ]] && cp -p "${x}" "${dir}"/
79 if [[ ! -e ${dir}/grub.conf ]] ; then
80 s="${ROOT}/usr/share/doc/${PF}/grub.conf.gentoo"
81 [[ -e "${s}" ]] && cat "${s}" >${dir}/grub.conf
82 [[ -e "${s}.gz" ]] && zcat "${s}.gz" >${dir}/grub.conf
83 [[ -e "${s}.bz2" ]] && bzcat "${s}.bz2" >${dir}/grub.conf
86 # Per bug 218599, we support grub.conf.install for users that want to run a
87 # specific set of Grub setup commands rather than the default ones.
88 grub_config=${dir}/grub.conf.install
89 [[ -e ${grub_config} ]] || grub_config=${dir}/grub.conf
90 if [[ -e ${grub_config} ]] ; then
92 -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \
95 --device-map="${dir}"/device.map \
99 # the grub default commands silently piss themselves if
100 # the default file does not exist ahead of time
101 if [[ ! -e ${dir}/default ]] ; then
102 grub-set-default --root-directory="${boot_dir}" default
104 einfo "Grub has been installed to ${boot_dir} successfully."
108 if [[ -n ${DONT_MOUNT_BOOT} ]]; then
109 elog "WARNING: you have DONT_MOUNT_BOOT in effect, so you must apply"
110 elog "the following instructions for your /boot!"
111 elog "Neglecting to do so may cause your system to fail to boot!"
114 setup_boot_dir "${ROOT}"/boot
115 # Trailing output because if this is run from pkg_postinst, it gets mixed into
119 elog "To interactively install grub files to another device such as a USB"
120 elog "stick, just run the following and specify the directory as prompted:"
121 elog " emerge --config =${PF}"
122 elog "Alternately, you can export GRUB_ALT_INSTALLDIR=/path/to/use to tell"
123 elog "grub where to install in a non-interactive way."
129 if [ ! -d "${GRUB_ALT_INSTALLDIR}" ]; then
130 einfo "Enter the directory where you want to setup grub:"
133 dir="${GRUB_ALT_INSTALLDIR}"
135 setup_boot_dir "${dir}"