4 if [ "x$BOOTLOADER" == 'xgrub' ]
12 set_grub_bootloader() {
13 local GRUB_CONF="${BOOTDIR}/grub/grub.conf"
16 print_info 1 "Adding kernel to $GRUB_CONF..."
17 if [ "${BOOTFS}" != '' ]
21 # Extract block device information from /etc/fstab
22 GRUB_ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab)
23 GRUB_BOOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "'${BOOTDIR}'") { print $1; exit }' /etc/fstab)
25 # If ${BOOTDIR} is not defined in /etc/fstab, it must be the same as /
26 [ "x$GRUB_BOOTFS" == 'x' ] && GRUB_BOOTFS=$GRUB_ROOTFS
29 # Read GRUB device map
30 [ ! -d ${TEMP} ] && mkdir ${TEMP}
31 grub --batch --device-map=${TEMP}/grub.map <<EOF >/dev/null 2>&1
34 # Get the GRUB mapping for our device
35 local GRUB_BOOT_DISK1=$(echo $GRUB_BOOTFS | sed -e 's#\(/dev/.\+\)[[:digit:]]\+#\1#')
36 local GRUB_BOOT_DISK=$(awk '{if ($2 == "'$GRUB_BOOT_DISK1'") {gsub(/(\(|\))/, "", $1); print $1;}}' ${TEMP}/grub.map)
38 local GRUB_BOOT_PARTITION=$(echo $GRUB_BOOTFS | sed -e 's#/dev/.\+\([[:digit:]]?*\)#\1#')
39 [ ! -d ${TEMP} ] && rm -r ${TEMP}
41 # Create grub configuration directory and file if it doesn't exist.
42 [ ! -e `basename $GRUB_CONF` ] && mkdir -p `basename $GRUB_CONF`
44 if [ ! -e $GRUB_CONF ]
46 if [ "${GRUB_BOOT_DISK}" != '' -a "${GRUB_BOOT_PARTITION}" != '' ]
48 GRUB_BOOT_PARTITION=`expr ${GRUB_BOOT_PARTITION} - 1`
49 # grub.conf doesn't exist - create it with standard defaults
51 echo 'default 0' >> $GRUB_CONF
52 echo 'timeout 5' >> $GRUB_CONF
55 # Add grub configuration to grub.conf
56 echo "# Genkernel generated entry, see GRUB documentation for details" >> $GRUB_CONF
57 echo "title=Gentoo Linux ($KV)" >> $GRUB_CONF
58 echo -e "\troot ($GRUB_BOOT_DISK,$GRUB_BOOT_PARTITION)" >> $GRUB_CONF
59 if [ "${BUILD_INITRD}" -eq '0' ]
61 echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=$GRUB_ROOTFS" >> $GRUB_CONF
63 echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=/dev/ram0 init=/linuxrc real_root=$GRUB_ROOTFS" >> $GRUB_CONF
64 if [ "${PAT}" -gt '4' -a "${CMD_BOOTSPLASH}" != '1' ]
66 echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> $GRUB_CONF
68 echo -e "\tinitrd /initrd-${KNAME}-${ARCH}-${KV}" >> $GRUB_CONF
73 print_error 1 "Error! ${BOOTDIR}/grub/grub.conf does not exist and the correct settings can not be automatically detected."
74 print_error 1 "Please manually create your ${BOOTDIR}/grub/grub.conf file."
77 # grub.conf already exists; so...
78 # ... Clone the first boot definition and change the version.
80 [ "${KERN_24}" -eq '1' ] && TYPE='rd' || TYPE='ramfs'
82 cp -f $GRUB_CONF $GRUB_CONF.bak
83 awk 'BEGIN { RS="\n"; }
85 if(match($0, "kernel-" KNAME "-" ARCH "-" KV))
87 if(match($0, "init" TYPE "-" KNAME "-" ARCH "-" KV))
89 if(have_k == "1" && have_i == "1")
91 }' KNAME=$KNAME ARCH=$ARCH KV=$KV TYPE=$TYPE $GRUB_CONF.bak
94 local LIMIT=$(wc -l $GRUB_CONF.bak)
95 awk -f ${GK_BIN}/gen_bootloader_grub.awk LIMIT=${LIMIT/ */} KNAME=$KNAME ARCH=$ARCH KV=$KV TYPE=$TYPE $GRUB_CONF.bak > $GRUB_CONF
97 print_info 1 "GRUB: Definition found, not duplicating."