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 # Translate block letters into grub numbers
26 local GRUB_ROOT_DISK=$(echo $GRUB_ROOTFS | sed -e 's/\/dev\/[hs]d\([[:alpha:]]\)[[:digit:]]\+/\1/')
27 case $GRUB_ROOT_DISK in
40 # Translate partition numbers into grub numbers
41 local GRUB_ROOT_PARTITION=$(echo $GRUB_BOOTFS | sed -e 's/\/dev\/[hs]d[[:alpha:]]\([[:digit:]]\+\)/\1/')
42 local GRUB_ROOT_PARTITION=$(($GRUB_ROOT_PARTITION-1))
44 # Create grub configuration directory and file if it doesn't exist.
45 [ ! -e `basename $GRUB_CONF` ] && mkdir -p `basename $GRUB_CONF`
47 if [ ! -e $GRUB_CONF ]
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 (hd$GRUB_ROOT_DISK,$GRUB_ROOT_PARTITION)" >> $GRUB_CONF
59 if [ "${BUILD_INITRD}" -eq '0' ]
61 echo -e "\tkernel /kernel-$KV root=$GRUB_ROOTFS" >> $GRUB_CONF
63 echo -e "\tkernel /kernel-$KV root=/dev/ram0 init=/linuxrc real_root=$GRUB_ROOTFS" >> $GRUB_CONF
64 echo -e "\tinitrd /initrd-$KV" >> $GRUB_CONF
68 # grub.conf already exists; so...
69 # ... Clone the first boot definition and change the version.
70 cp $GRUB_CONF $GRUB_CONF.bak
71 awk 'BEGIN { RS="" ; FS="\n" ; OFS="\n" ; ORS="\n\n" }
74 sub(/\(.+\)/,"(" KV ")",$1);
75 sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KV, $3);
76 sub(/initrd-[[:alnum:][:punct:]]+/, "initrd-" KV, $4);
79 NR != 2 { print RS $0; }' KV=$KV $GRUB_CONF.bak > $GRUB_CONF