genkernel: Add --kconfig to set specific kernel config options
[genkernel.git] / gen_bootloader.sh
index ee13ae6e827754f8c751dc18000fc58f76c67e66..5848bd24220c8aeefe6c0b254a3221afde19dda3 100755 (executable)
@@ -1,8 +1,13 @@
+# $Id$
+
 set_bootloader() {
        case "${BOOTLOADER}" in
                grub)
                        set_bootloader_grub
                        ;;
+               grub2)
+                       set_bootloader_grub2
+                       ;;
                *)
                        print_warning "Bootloader ${BOOTLOADER} is not currently supported"
                        ;;
@@ -26,6 +31,29 @@ set_bootloader_grub_read_device_map() {
        echo "${TEMP}/grub.map"
 }
 
+set_bootloader_grub2() {
+       local GRUB_CONF
+       for candidate in \
+                       "${BOOTDIR}/grub2/grub.cfg" \
+                       "${BOOTDIR}/grub/grub.cfg" \
+                       ; do
+               if [[ -e "${candidate}" ]]; then
+                       GRUB_CONF=${candidate}
+                       break
+               fi
+       done
+
+       if [[ -z "${GRUB_CONF}" ]]; then
+               print_error 1 "Error! Grub2 configuration file does not exist, please ensure grub2 is correctly setup first."
+               return 0
+       fi
+
+       print_info 1 "You can customize Grub2 parameters in /etc/default/grub."
+       print_info 1 "Running grub2-mkconfig to create ${GRUB_CONF}..."
+       grub2-mkconfig -o "${GRUB_CONF}"
+       [ "${BUILD_RAMDISK}" -ne 0 ] && sed -i 's/ro single/ro debug/' "${GRUB_CONF}"
+}
+
 set_bootloader_grub() {
        local GRUB_CONF="${BOOTDIR}/grub/grub.conf"
 
@@ -58,14 +86,12 @@ set_bootloader_grub() {
                        echo "root (${GRUB_BOOT_DISK},${GRUB_BOOT_PARTITION})" >> ${GRUB_CONF}
                        echo >> ${GRUB_CONF}
 
-                       # Add grub configuration to 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' ]
+                       echo -e "\tkernel /kernel-${KNAME}-${ARCH}-${KV} root=${GRUB_ROOTFS}" >> ${GRUB_CONF}
+                       if [ "${BUILD_INITRD}" = '1' ]
                        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}
@@ -96,8 +122,8 @@ set_bootloader_grub_duplicate_default_replace_kernel_initrd() {
 
 set_bootloader_grub_check_for_existing_entry() {
        local GRUB_CONF=$1
-       if grep -q "^[[:space:]]*kernel[[:space:]=]*.*/kernel-${KNAME}-${ARCH}-${KV}\>" "${GRUB_CONF}" &&
-               grep -q "^[[:space:]]*initrd[[:space:]=]*.*/initramfs-${KNAME}-${ARCH}-${KV}\>" "${GRUB_CONF}"
+       if grep -q "^[[:space:]]*kernel[[:space:]=]*.*/kernel-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}" &&
+               grep -q "^[[:space:]]*initrd[[:space:]=]*.*/initramfs-${KNAME}-${ARCH}-${KV}\([[:space:]]\|$\)" "${GRUB_CONF}"
        then
                return 0
        fi
@@ -107,7 +133,7 @@ set_bootloader_grub_check_for_existing_entry() {
 set_bootloader_grub_duplicate_default() {
        local GRUB_CONF=$1
        local GRUB_CONF_TMP="${GRUB_CONF}.tmp"
-       
+
        line_count=$(wc -l < "${GRUB_CONF}")
        line_nums="$(grep -n "^title" "${GRUB_CONF}" | cut -d: -f1)"
        if [ -z "${line_nums}" ]; then