4 if [ "x$BOOTLOADER" == 'xgrub' ]
12 set_grub_bootloader() {
13 local GRUB_CONF='/boot/grub/grub.conf'
16 print_info 1 "Adding kernel to $GRUB_CONF..."
18 # Extract block device information from /etc/fstab
19 local GRUB_ROOTFS=$(awk '/[[:space:]]\/[[:space:]]/ { print $1 }' /etc/fstab)
20 local GRUB_BOOTFS=$(awk '/^[^#].+[[:space:]]\/boot[[:space:]]/ { print $1 }' /etc/fstab)
22 # If /boot is not defined in /etc/fstab, it must be the same as /
23 [ "x$GRUB_BOOTFS" == 'x' ] && GRUB_BOOTFS=$GRUB_ROOTFS
25 # Read GRUB device map
26 [ ! -d ${tmp} ] && mkdir ${tmp}
27 grub --batch --device-map=${tmp}/grub.map <<EOF >/dev/null
31 # Get the GRUB mapping for our device
32 local GRUB_BOOT_DISK1=$(echo $GRUB_BOOTFS | sed -e 's#\(/dev/.\+\)[[:digit:]]\+#\1#')
33 local GRUB_BOOT_DISK=$(awk '{if ($2 == "'$GRUB_BOOT_DISK1'") {gsub(/(\(|\))/, "", $1); print $1;}}' ${tmp}/grub.map)
35 local GRUB_BOOT_PARTITION=$(echo $GRUB_BOOTFS | sed -e 's#/dev/.\+\([[:digit:]]\+\)#\1#')
36 [ ! -d ${tmp} ] && rm -r ${tmp}
38 # Create grub configuration directory and file if it doesn't exist.
39 [ ! -e `basename $GRUB_CONF` ] && mkdir -p `basename $GRUB_CONF`
41 if [ ! -e $GRUB_CONF ]
43 if [ "${GRUB_BOOT_DISK}" = '' -o "${GRUB_BOOT_PARTITION}" = '' ]
45 print_error 1 'Error! /boot/grub/grub.conf does not exist and the correct settings can\'t be automatically detected.'
46 print_error 1 'Please manually create your /boot/grub/grub.conf file.'
48 # grub.conf doesn't exist - create it with standard defaults
50 echo 'default 0' >> $GRUB_CONF
51 echo 'timeout 5' >> $GRUB_CONF
54 # Add grub configuration to grub.conf
55 echo "# Genkernel generated entry, see GRUB documentation for details" >> $GRUB_CONF
56 echo "title=Gentoo Linux ($KV)" >> $GRUB_CONF
57 echo -e "\troot ($GRUB_BOOT_DISK,$GRUB_BOOT_PARTITION)" >> $GRUB_CONF
58 if [ "${BUILD_INITRD}" -eq '0' ]
60 echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=$GRUB_ROOTFS" >> $GRUB_CONF
62 echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=/dev/ram0 init=/linuxrc real_root=$GRUB_ROOTFS" >> $GRUB_CONF
63 if [ "${PAT}" -gt '4' -a "${CMD_BOOTSPLASH}" != '1' ]
65 echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> $GRUB_CONF
67 echo -e "\tinitrd /initrd-${KNAME}-${ARCH}-${KV}" >> $GRUB_CONF
73 # grub.conf already exists; so...
74 # ... Clone the first boot definition and change the version.
76 [ "${KERN_24}" -eq '1' ] && TYPE='rd' || TYPE='ramfs'
78 cp $GRUB_CONF $GRUB_CONF.bak
79 awk 'BEGIN { RS="" ; FS="\n" ; OFS="\n" ; ORS="\n\n" }
82 sub(/\(.+\)/,"(" KV ")",$1);
83 sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KNAME "-" ARCH "-" KV, $3);
84 sub(/initr(d|amfs)-[[:alnum:][:punct:]]+/, "init" TYPE "-" KNAME "-" ARCH "-" KV, $4);
87 NR != 2 { print RS $0; }' KNAME=$KNAME ARCH=$ARCH KV=$KV TYPE=$TYPE $GRUB_CONF.bak > $GRUB_CONF