GRUB Bootloader support - bug #57576. Thanks to Mathias Gug for the patch!
authorTim Yamin <plasmaroo@gentoo.org>
Wed, 21 Jul 2004 14:05:24 +0000 (14:05 +0000)
committerTim Yamin <plasmaroo@gentoo.org>
Wed, 21 Jul 2004 14:05:24 +0000 (14:05 +0000)
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/genkernel/trunk@116 67a159dc-881f-0410-a524-ba9dfbe2cb84

gen_bootloader.sh [new file with mode: 0644]
gen_cmdline.sh
gen_determineargs.sh
genkernel
genkernel.conf

diff --git a/gen_bootloader.sh b/gen_bootloader.sh
new file mode 100644 (file)
index 0000000..6570635
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+set_bootloader() {
+       if [ "x$BOOTLOADER" == 'xgrub' ]
+       then
+               set_grub_bootloader
+       else
+               return 0
+       fi
+}
+
+set_grub_bootloader() {
+       local GRUB_CONF='/boot/grub/grub.conf'
+
+       print_info 1 ''
+       print_info 1 "Adding kernel to $GRUB_CONF..."
+
+       # Extract block device information from /etc/fstab
+       local GRUB_ROOTFS=$(awk '/[[:space:]]\/[[:space:]]/ { print $1 }' /etc/fstab)
+       local GRUB_BOOTFS=$(awk '/[[:space:]]\/boot[[:space:]]/ { print $1 }' /etc/fstab)
+
+       # If /boot is not defined in /etc/fstab, it must be the same as /
+       [ "x$GRUB_BOOTFS" == 'x' ] && GRUB_BOOTFS=$GRUB_ROOTFS
+
+       # Translate block letters into grub numbers
+       local GRUB_ROOT_DISK=$(echo $GRUB_ROOTFS | sed -e 's/\/dev\/[hs]d\([[:alpha:]]\)[[:digit:]]\+/\1/')
+       case $GRUB_ROOT_DISK in
+               a )
+                       GRUB_ROOT_DISK='0' ;;
+               b )
+                       GRUB_ROOT_DISK='1' ;;
+               c )
+                       GRUB_ROOT_DISK='2' ;;
+               d )
+                       GRUB_ROOT_DISK='3' ;;
+               e )
+                       GRUB_ROOT_DISK='4' ;;
+       esac
+
+       # Translate partition numbers into grub numbers
+       local GRUB_ROOT_PARTITION=$(echo $GRUB_BOOTFS | sed -e 's/\/dev\/[hs]d[[:alpha:]]\([[:digit:]]\+\)/\1/')
+       local GRUB_ROOT_PARTITION=$(($GRUB_ROOT_PARTITION-1))
+
+       # Create grub configuration directory and file if it doesn't exist.
+       [ ! -e `basename $GRUB_CONF` ] && mkdir -p `basename $GRUB_CONF`
+
+       if [ ! -e $GRUB_CONF ]
+       then
+               # grub.conf doesn't exist - create it with standard defaults
+               touch $GRUB_CONF
+               echo 'default 0' >> $GRUB_CONF
+               echo 'timeout 5' >> $GRUB_CONF
+
+               # Add grub configuration to grub.conf   
+               echo "title=Gentoo Linux ($KV)" >> $GRUB_CONF
+               echo -e "\troot (hd$GRUB_ROOT_DISK,$GRUB_ROOT_PARTITION)" >> $GRUB_CONF
+               if [ "${BUILD_INITRD}" -eq '0' ]
+               then
+                       echo -e "\tkernel /kernel-$KV root=$GRUB_ROOTFS" >> $GRUB_CONF
+               else
+                       echo -e "\tkernel /kernel-$KV root=/dev/ram0 init=/linuxrc real_root=$GRUB_ROOTFS" >> $GRUB_CONF
+                       echo -e "\tinitrd /initrd-$KV" >> $GRUB_CONF
+               fi
+       else
+               # grub.conf already exists; so...
+               # * Copy the first boot definition and change the version.
+               cp $GRUB_CONF $GRUB_CONF.bak
+               awk 'BEGIN { RS="title=";FS="\n";OFS="\n";ORS=""} 
+                       NR == 2 { 
+                               sub(/\(.+\)/,"(" ch KV ch ")",$1);
+                               sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KV, $3);
+                               sub(/initrd-[[:alnum:][:punct:]]+/, "initrd-" KV, $4);
+                               print RS ch $0 }' 
+                       KV=$KV $GRUB_CONF.bak >> $GRUB_CONF
+       fi
+}
index 87ae1b161005a471b4e63afaf4e39de010a5210e..b2665714866d6c145ac8b30c285a1141de717ad3 100755 (executable)
@@ -58,6 +58,7 @@ longusage() {
   echo "       --bootsplash=<theme>    Force bootsplash using <theme>."
   echo "       --do-keymap-auto        Forces keymap selection at boot."
   echo "       --no-lvm2               Don't add in LVM2 support."
+  echo "        --bootloader=grub       Add new kernel to grub configuration"
   echo "  Internals"
   echo "       --tempdir=<dir>   Location of Genkernel's temporary directory"
   echo "       --arch-override=<arch>  Force to arch instead of autodetect"
@@ -147,6 +148,10 @@ parse_cmdline() {
                      CMD_NOLVM2=1
                      print_info 2 'CMD_NOLVM2: 1'
              ;;
+             --bootloader*)
+                     CMD_BOOTLOADER=`parse_opt "$*"`
+                     print_info 2 "CMD_BOOTLOADER: $CMD_BOOTLOADER"
+             ;;
              --debuglevel*)
                      CMD_DEBUGLEVEL=`parse_opt "$*"`
                      DEBUGLEVEL="${CMD_DEBUGLEVEL}"
index 55053b279344b24d22608f5a0889b20fb728bedd..129a5d0bb426d75eee685c51fac71a16a0b953b4 100644 (file)
@@ -166,4 +166,9 @@ determine_real_args() {
        then
                INSTALL_MOD_PATH="${CMD_INSTALL_MOD_PATH}"
        fi
+
+       if [ "${CMD_BOOTLOADER}" != '' ]
+       then
+               BOOTLOADER="${CMD_BOOTLOADER}"
+       fi
 }
index 06e294d86dfd4a7dda4ac881eaf6afa7911bdfe8..e768ff697de6c128261af3e2fd9e12bb48ef186d 100755 (executable)
--- a/genkernel
+++ b/genkernel
@@ -20,6 +20,7 @@ source ${GK_BIN}/gen_configkernel.sh || gen_die "Could not read ${GK_BIN}/gen_co
 source ${GK_BIN}/gen_initrd.sh || gen_die "Could not read ${GK_BIN}/gen_initrd.sh"
 source ${GK_BIN}/gen_moddeps.sh || gen_die "Could not read ${GK_BIN}/gen_moddeps.sh"
 source ${GK_BIN}/gen_package.sh || gen_die "Could not read ${GK_BIN}/gen_package.sh"
+source ${GK_BIN}/gen_bootloader.sh || gen_die "Could not read ${GK_BIN}/gen_bootloader.sh"
 
 BUILD_KERNEL=0
 BUILD_INITRD=0
@@ -222,6 +223,7 @@ fi
 
 if [ "${BUILD_KERNEL}" -eq '1' ]
 then
+       set_bootloader
        print_info 1 ''
        print_info 1 "Kernel compiled successfully!"
        print_info 1 ''
index 1fb96732be0d39bb94978f5f830464639267039f..9d21b1bcbc5197d9e772c9a29670a2684c7bdc9d 100755 (executable)
@@ -30,6 +30,9 @@ SAVE_CONFIG="yes"
 # Use Color output in Genkernel?
 USECOLOR="yes"
 
+# Add new kernel to grub?
+# BOOTLOADER="grub"
+
 # =========GENKERNEL LOCATION CONFIGURATION============
 # Variables:
 #   %%ARCH%% - Final determined architecture