Initial commit for re-adding support for --bootloader=grub
authorAndrew Gaffney <agaffney@gentoo.org>
Mon, 15 Dec 2008 01:18:33 +0000 (19:18 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Mon, 15 Dec 2008 01:18:33 +0000 (19:18 -0600)
ChangeLog
gen_bootloader.sh [new file with mode: 0644]
gen_cmdline.sh
gen_determineargs.sh
genkernel

index 95d7f055227a658b759e2c4b89df252a7f167933..16c7d19f862d3d502a049e63a7a97af394995011 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 # Copyright 1999-2008 Gentoo Foundation; 2008 Chris Gianelloni, Andrew Gaffney
 # Distributed under the GPL v2
 
+  15 Dec 2008; Andrew Gaffney <agaffney@gentoo.org> +gen_bootloader.sh,
+  gen_cmdline.sh, gen_determineargs.sh, genkernel:
+  Initial commit for re-adding support for --bootloader=grub
+
   14 Dec 2008; Andrew Gaffney <agaffney@gentoo.org> netboot/linuxrc.x:
   Change -f checks to -e for /dev nodes Check that dropbear exists before
   starting it
diff --git a/gen_bootloader.sh b/gen_bootloader.sh
new file mode 100644 (file)
index 0000000..d39b6bd
--- /dev/null
@@ -0,0 +1,84 @@
+set_bootloader() {
+       case "${BOOTLOADER}" in
+               grub)
+                       set_bootloader_grub
+                       ;;
+               *)
+                       print_warning "Bootloader ${BOOTLOADER} is not currently supported"
+                       ;;
+       esac
+}
+
+set_bootloader_read_fstab() {
+       local ROOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "/" ) { print $1; exit }' /etc/fstab)
+       local BOOTFS=$(awk 'BEGIN{RS="((#[^\n]*)?\n)"}( $2 == "'${BOOTDIR}'") { print $1; exit }' /etc/fstab)
+
+       # If ${BOOTDIR} is not defined in /etc/fstab, it must be the same as /
+       [ -z "${BOOTFS}" ] && BOOTFS=${ROOTFS}
+
+       echo "${ROOTFS} ${BOOTFS}"
+}
+
+set_bootloader_grub_read_device_map() {
+       # Read GRUB device map
+       [ ! -d ${TEMP} ] && mkdir ${TEMP}
+       echo "quit" | grub --batch --device-map=${TEMP}/grub.map &>/dev/null
+       echo "${TEMP}/grub.map"
+}
+
+set_bootloader_grub() {
+       local GRUB_CONF="${BOOTDIR}/grub/grub.conf"
+
+       print_info 1 "Adding kernel to ${GRUB_CONF}..."
+
+       if [ ! -e ${GRUB_CONF} ]
+       then
+               local GRUB_BOOTFS
+               if [ -n "${BOOTFS}" ]
+               then
+                       GRUB_BOOTFS=$BOOTFS
+               else
+                       GRUB_BOOTFS=$(set_bootloader_read_fstab | cut -d' ' -f2)
+               fi
+
+               # Get the GRUB mapping for our device
+               local GRUB_BOOT_DISK1=$(echo ${GRUB_BOOTFS} | sed -e 's#\(/dev/.\+\)[[:digit:]]\+#\1#')
+               local GRUB_BOOT_DISK=$(awk '{if ($2 == "'${GRUB_BOOT_DISK1}'") {gsub(/(\(|\))/, "", $1); print $1;}}' ${TEMP}/grub.map)
+               local GRUB_BOOT_PARTITION=$(($(echo ${GRUB_BOOTFS} | sed -e 's#/dev/.\+\([[:digit:]]?*\)#\1#') - 1))
+
+               if [ -n "${GRUB_BOOT_DISK}" -a -n "${GRUB_BOOT_PARTITION}" ]
+               then
+
+                       # Create grub configuration directory and file if it doesn't exist.
+                       [ ! -d `dirname ${GRUB_CONF}` ] && mkdir -p `dirname ${GRUB_CONF}`
+
+                       touch ${GRUB_CONF}
+                       echo 'default 0' >> ${GRUB_CONF}
+                       echo 'timeout 5' >> ${GRUB_CONF}
+                       echo "root (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${GRUB_CONF}
+                       echo >> ${GRUB_CONF}
+
+                       # Add grub configuration to grub.conf   
+                       echo "# Genkernel generated entry, see GRUB documentation for details" >> ${GRUB_CONF}
+                       echo "title=Gentoo Linux ($KV)" >> ${GRUB_CONF}
+                       if [ "${BUILD_INITRD}" -eq '0' ]
+                       then
+                               echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
+                       else
+                               echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=/dev/ram0 init=/linuxrc real_root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
+                               if [ "${PAT}" -gt '4' ]
+                               then
+                                   echo -e "\tinitrd /initramfs-${KNAME}-${ARCH}-${KV}" >> ${GRUB_CONF}
+                               fi
+                       fi
+                       echo >> ${GRUB_CONF}
+               else
+                       print_error 1 "Error! ${BOOTDIR}/grub/grub.conf does not exist and the correct settings can not be automatically detected."
+                       print_error 1 "Please manually create your ${BOOTDIR}/grub/grub.conf file."
+               fi
+
+       else
+               # The grub.conf already exists, so let's try to duplicate the default entry
+       fi
+
+}
index 5577df90781be5629186a7d1aac7eb5cbe9a777b..954112f4eedd662154ab3444a9d6a38adbe92d9d 100755 (executable)
@@ -84,15 +84,16 @@ longusage() {
   echo "       --mdadm                 Copy /etc/mdadm.conf to initramfs"
   echo "       --dmraid                Include DMRAID support"
   echo "       --slowusb               Enables extra pauses for slow USB CD boots"
+  echo "       --bootloader=grub       Add new kernel to GRUB configuration"
   echo "       --linuxrc=<file>        Specifies a user created linuxrc"
   echo "       --disklabel             Include disk label and uuid support in your"
   echo "                               ramdisk"
   echo "       --luks                  Include LUKS support"
   echo "                               --> 'emerge cryptsetup-luks' with USE=-dynamic"
-  echo "    --no-busybox    Do not include busybox in the initramfs."
-  echo "    --unionfs       Include support for unionfs"
-  echo "    --netboot          Create a self-contained env in the initramfs"
-  echo "    --real-root=<foo>  Specify a default for real_root="
+  echo "       --no-busybox    Do not include busybox in the initramfs."
+  echo "       --unionfs       Include support for unionfs"
+  echo "       --netboot       Create a self-contained env in the initramfs"
+  echo "       --real-root=<foo> Specify a default for real_root="
   echo "  Internals"
   echo "       --arch-override=<arch>  Force to arch instead of autodetect"
   echo "       --cachedir=<dir>        Override the default cache location"
@@ -273,6 +274,10 @@ parse_cmdline() {
                        CMD_DMRAID=1
                        print_info 2 "CMD_DMRAID: ${CMD_DMRAID}"
                        ;;
+               --bootloader=*)
+                       CMD_BOOTLOADER=`parse_opt "$*"`
+                       print_info 2 "CMD_BOOTLOADER: ${CMD_BOOTLOADER}"
+                       ;;
                --loglevel=*)
                        CMD_LOGLEVEL=`parse_opt "$*"`
                        LOGLEVEL="${CMD_LOGLEVEL}"
index 02995bc1786097da30dc5ab6fd8f415c5fdaeefb..aea05f2533a2fecd6c96ce89a6c1816ff7ec624b 100644 (file)
@@ -138,6 +138,16 @@ determine_real_args() {
        BLKID_BINCACHE=`arch_replace "${BLKID_BINCACHE}"`
        FUSE_BINCACHE=`arch_replace "${FUSE_BINCACHE}"`
        UNIONFS_FUSE_BINCACHE=`arch_replace "${UNIONFS_FUSE_BINCACHE}"`
+
+       if [ -n "${CMD_BOOTLOADER}" ]
+       then
+               BOOTLOADER="${CMD_BOOTLOADER}"
+               if [ "${CMD_BOOTLOADER}" != "${CMD_BOOTLOADER/:/}" ]
+               then
+                       BOOTFS=`echo "${CMD_BOOTLOADER}" | cut -f2- -d:`
+                       BOOTLOADER=`echo "${CMD_BOOTLOADER}" | cut -f1 -d:`
+               fi
+       fi
        
        if [ "${NO_KERNEL_SOURCES}" != "1" ]
        then
index c0fa9fa051c53dbe1aa210e1a31ab9375b0d87a6..f74846eb53253652282b624143c48a47e072ce4e 100755 (executable)
--- a/genkernel
+++ b/genkernel
@@ -43,6 +43,7 @@ source ${GK_SHARE}/gen_configkernel.sh || gen_die "Could not read ${GK_SHARE}/ge
 source ${GK_SHARE}/gen_initramfs.sh || gen_die "Could not read ${GK_SHARE}/gen_initramfs.sh"
 source ${GK_SHARE}/gen_moddeps.sh || gen_die "Could not read ${GK_SHARE}/gen_moddeps.sh"
 source ${GK_SHARE}/gen_package.sh || gen_die "Could not read ${GK_SHARE}/gen_package.sh"
+source ${GK_SHARE}/gen_bootloader.sh || gen_die "Could not read ${GK_SHARE}/gen_bootloader.sh"
 
 TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$
 
@@ -328,6 +329,7 @@ fi
 
 if [ "${BUILD_KERNEL}" -eq '1' ]
 then
+       set_bootloader
        print_info 1 ''
        print_info 1 "Kernel compiled successfully!"
        print_info 1 ''