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
54 # Add grub configuration to grub.conf
55 echo "title=Gentoo Linux ($KV)" >> $GRUB_CONF
56 echo -e "\troot (hd$GRUB_ROOT_DISK,$GRUB_ROOT_PARTITION)" >> $GRUB_CONF
57 if [ "${BUILD_INITRD}" -eq '0' ]
59 echo -e "\tkernel /kernel-$KV root=$GRUB_ROOTFS" >> $GRUB_CONF
61 echo -e "\tkernel /kernel-$KV root=/dev/ram0 init=/linuxrc real_root=$GRUB_ROOTFS" >> $GRUB_CONF
62 echo -e "\tinitrd /initrd-$KV" >> $GRUB_CONF
65 # grub.conf already exists; so...
66 # * Copy the first boot definition and change the version.
67 cp $GRUB_CONF $GRUB_CONF.bak
68 awk 'BEGIN { RS="title=";FS="\n";OFS="\n";ORS=""}
70 sub(/\(.+\)/,"(" ch KV ch ")",$1);
71 sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KV, $3);
72 sub(/initrd-[[:alnum:][:punct:]]+/, "initrd-" KV, $4);
74 KV=$KV $GRUB_CONF.bak >> $GRUB_CONF