From 8dcac4a20de28f69ec93494cf026845bc4de0add Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 14 Dec 2008 19:18:33 -0600 Subject: [PATCH] Initial commit for re-adding support for --bootloader=grub --- ChangeLog | 4 +++ gen_bootloader.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++ gen_cmdline.sh | 13 ++++--- gen_determineargs.sh | 10 ++++++ genkernel | 2 ++ 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 gen_bootloader.sh diff --git a/ChangeLog b/ChangeLog index 95d7f05..16c7d19 100644 --- 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 +gen_bootloader.sh, + gen_cmdline.sh, gen_determineargs.sh, genkernel: + Initial commit for re-adding support for --bootloader=grub + 14 Dec 2008; Andrew Gaffney 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 index 0000000..d39b6bd --- /dev/null +++ b/gen_bootloader.sh @@ -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 + +} diff --git a/gen_cmdline.sh b/gen_cmdline.sh index 5577df9..954112f 100755 --- a/gen_cmdline.sh +++ b/gen_cmdline.sh @@ -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= 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= 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= Specify a default for real_root=" echo " Internals" echo " --arch-override= Force to arch instead of autodetect" echo " --cachedir= 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}" diff --git a/gen_determineargs.sh b/gen_determineargs.sh index 02995bc..aea05f2 100644 --- a/gen_determineargs.sh +++ b/gen_determineargs.sh @@ -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 diff --git a/genkernel b/genkernel index c0fa9fa..f74846e 100755 --- 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 '' -- 2.26.2