From 0f699a130ceab451996f70759107e010014f901b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 3 Feb 2016 15:38:15 +0100 Subject: [PATCH 1/1] grub-custom-initramfs Signed-off-by: Christian Hesse --- 10_archlinux | 194 -------------------------------------------- PKGBUILD | 14 ++-- grub-custom-initramfs.patch | 69 ++++++++++++++++ grub-intel-ucode.patch | 26 ------ grub.default | 5 ++ 5 files changed, 81 insertions(+), 227 deletions(-) delete mode 100755 10_archlinux create mode 100644 grub-custom-initramfs.patch delete mode 100644 grub-intel-ucode.patch diff --git a/10_archlinux b/10_archlinux deleted file mode 100755 index f86578a..0000000 --- a/10_archlinux +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env bash - -## -## grub-mkconfig helper script specific to Arch Linux -## Contributed by "Keshav Amburay" -## Updated on 08 February 2014 -## -## Script based on do_grub_config() function in Arch Linux Archboot ISO Installer/Setup script -## Some parts taken from /etc/grub.d/10_linux script shipped by GRUB(2) upstream -## -## This script can be freely distributed and/or modified -## under the terms of the GNU General Public License as published by -## the Free Software Foundation, either version 3 of the License, or -## (at your option) any later version. -## -## This script is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## - -_FUNC_GRUB_FILE_PRESENT() { - - [[ -z "${GRUB_PLATFORM}" ]] && GRUB_PLATFORM="x86" - - if [[ "${GRUB_PLATFORM}" == "x86" ]]; then - check="--is-x86-linux32" - elif [[ "${GRUB_PLATFORM}" == "i386-xen-pae" ]]; then - check="--is-i386-xen-pae-domu" - elif [[ "${GRUB_PLATFORM}" == "x86_64-xen" ]]; then - check="--is-x86_64-xen-domu" - else - check="--is-${GRUB_PLATFORM}-linux" - fi - - case "${GRUB_PLATFORM}" in - x86) - list="$(for i in "${GRUB_ROOT}"/boot/vmlinuz-linux* ; do - if grub_file_is_not_garbage "${i}" && "${grub_file}" ${check} "${i}" ; then echo -n "${i} " ; fi - done)" ;; - *) - list="$(for i in "${GRUB_ROOT}"/boot/vmlinuz-linux* ; do - if grub_file_is_not_garbage "${i}" && "${grub_file}" ${check} "${i}" ; then echo -n "${i} " ; fi - done)" ;; - esac -} - -set -e - -prefix="/usr" -exec_prefix="${prefix}" -datarootdir="/usr/share" -datadir="${datarootdir}" -sysconfdir="/etc" - -. "${datarootdir}/grub/grub-mkconfig_lib" - -. "${sysconfdir}/default/grub" - -export TEXTDOMAIN="grub" -export TEXTDOMAINDIR="${datarootdir}/locale" - -CLASS="--class arch-linux --class arch --class gnu-linux --class gnu --class os" - -[[ "${grub_file}" != "" ]] && _FUNC_GRUB_FILE_PRESENT - -BOOT_PART_FS_UUID="$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null)" -BOOT_PART_HINTS_STRING="$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null || true)" -BOOT_PART_FS="$(${grub_probe} --target="fs" "/boot" 2>/dev/null)" - -ROOT_PART_GRUB_DEVICE="$(${grub_probe} --target=device / || true)" -ROOT_PART_FS="$(${grub_probe} --device ${ROOT_PART_GRUB_DEVICE} --target=fs 2> /dev/null || echo "unknown")" - -if [[ "${GRUB_LINUX_ROOT_DEVICE}" == "" ]]; then - - case "${ROOT_PART_FS}" in - btrfs) - rootsubvol="$(make_system_path_relative_to_its_root /)" - rootsubvol="${rootsubvol#/}" - if [[ "${rootsubvol}" != "" ]]; then - GRUB_LINUX_ROOT_DEVICE="subvol=${rootsubvol}" - fi - ;; - zfs) - rpool="$(${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true)" - bootfs="$(make_system_path_relative_to_its_root / | sed -e "s,@$,,")" - GRUB_LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" - ;; - esac - - if [[ "${GRUB_DEVICE_UUID}" == "" ]] || \ - [[ "${GRUB_DISABLE_LINUX_UUID}" == "true" ]] || \ - [[ ! -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" ]] || \ - uses_abstraction "${GRUB_DEVICE}" lvm ; then - GRUB_LINUX_ROOT_DEVICE="${GRUB_DEVICE}" - else - GRUB_LINUX_ROOT_DEVICE="UUID=${GRUB_DEVICE_UUID}" - fi -fi - -[[ "${GRUB_LINUX_PARAMS}" == "" ]] && GRUB_LINUX_PARAMS="${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" - -for _KERNEL_ in ${list} ; do - - echo "Found linux image: ${_KERNEL_}" >&2 - - basename="$(basename "${_KERNEL_}")" - dirname="$(dirname "${_KERNEL_}")" - REAL_DIR="$(make_system_path_relative_to_its_root "${dirname}")" - - _KERNEL_FILE_="$(echo ${_KERNEL_} | sed 's,/boot/,,g')" - _KERNEL_PKG_="pkg-$(echo ${_KERNEL_FILE_} | sed 's,vmlinuz-,,g')" - - _INITRAMFS_="${_KERNEL_FILE_/vmlinuz-/initramfs-}.img" - - if [[ -e "/boot/${_INITRAMFS_}" ]]; then - - echo "Found initramfs image: /boot/${_INITRAMFS_}" >&2 - -cat << EOF - -menuentry "Arch Linux ${_KERNEL_PKG_} kernel" ${CLASS} { - $(save_default_entry) - if [ x\$feature_all_video_module = xy ]; then - insmod all_video - fi - set gfxpayload=keep - insmod ${BOOT_PART_FS} - if [ x\$feature_platform_search_hint = xy ]; then - search --no-floppy --fs-uuid --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID} - else - search --no-floppy --fs-uuid --set=root ${BOOT_PART_FS_UUID} - fi - echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel ...' - linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS} - echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel initramfs ...' - initrd ${REAL_DIR}/${_INITRAMFS_} -} - -EOF - fi - - _INITRAMFS_FALLBACK_="${_KERNEL_FILE_/vmlinuz-/initramfs-}-fallback.img" - - if [[ -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then - - echo "Found fallback initramfs image: /boot/${_INITRAMFS_FALLBACK_}" >&2 - -cat << EOF - -menuentry "Arch Linux ${_KERNEL_PKG_} kernel (fallback initramfs)" ${CLASS} { - $(save_default_entry) - if [ x\$feature_all_video_module = xy ]; then - insmod all_video - fi - set gfxpayload=keep - insmod ${BOOT_PART_FS} - if [ x\$feature_platform_search_hint = xy ]; then - search --no-floppy --fs-uuid --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID} - else - search --no-floppy --fs-uuid --set=root ${BOOT_PART_FS_UUID} - fi - echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel ...' - linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS} - echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel fallback initramfs ...' - initrd ${REAL_DIR}/${_INITRAMFS_FALLBACK_} -} - -EOF - fi - - if [[ ! -e "/boot/${_INITRAMFS_}" ]] && [[ ! -e "/boot/${_INITRAMFS_FALLBACK_}" ]]; then -cat << EOF - -menuentry "Arch Linux ${_KERNEL_PKG_} kernel (no initramfs)" ${CLASS} { - $(save_default_entry) - if [ x\$feature_all_video_module = xy ]; then - insmod all_video - fi - set gfxpayload=keep - insmod ${BOOT_PART_FS} - if [ x\$feature_platform_search_hint = xy ]; then - search --no-floppy --fs-uuid --set=root ${BOOT_PART_HINTS_STRING} ${BOOT_PART_FS_UUID} - else - search --no-floppy --fs-uuid --set=root ${BOOT_PART_FS_UUID} - fi - echo 'Loading Arch Linux ${_KERNEL_PKG_} kernel ...' - linux ${REAL_DIR}/${_KERNEL_FILE_} root=${GRUB_LINUX_ROOT_DEVICE} rw ${GRUB_LINUX_PARAMS} -} - -EOF - fi - -done diff --git a/PKGBUILD b/PKGBUILD index 8ba47a3..69143b5 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -59,8 +59,8 @@ source=("grub-${_pkgver}::git+git://git.sv.gnu.org/grub.git#tag=${_GRUB_GIT_TAG} "http://ftp.gnu.org/gnu/unifont/unifont-${_UNIFONT_VER}/unifont-${_UNIFONT_VER}.bdf.gz.sig" '0001-Fix-security-issue-when-reading-username-and-passwor.patch' 'grub-10_linux-detect-archlinux-initramfs.patch' - 'grub-intel-ucode.patch' 'grub-add-GRUB_COLOR_variables.patch' + 'grub-custom-initramfs.patch' '60_memtest86+' 'grub.default' 'grub.cfg') @@ -71,10 +71,10 @@ md5sums=('SKIP' 'SKIP' '9589ec46a04f9bb4d5da987340a4a324' '945527e0de8d384166a4cf23439ae9ee' - 'a678629bc82c4e70c48d28242036d1d7' 'e506ae4a9f9f7d1b765febfa84e10d48' + 'fbc8648332e40c4b14ac2f9f1d3c456e' 'be55eabc102f2c60b38ed35c203686d6' - 'a03ffd56324520393bf574cefccb893d' + 'e6ef8703ed649a2bd2c470f3c9500c3d' 'c8b9511586d57d6f2524ae7898397a46') validpgpkeys=('95D2E9AB8740D8046387FD151A09227B1F435A33') #Paul Hardy @@ -90,14 +90,14 @@ prepare() { # CVE-2015-8370 patch -Np1 -i ../0001-Fix-security-issue-when-reading-username-and-passwor.patch - msg "Patch to load Intel microcode" - patch -Np1 -i "${srcdir}/grub-intel-ucode.patch" - echo - msg "Patch to detect of Arch Linux initramfs images by grub-mkconfig" patch -Np1 -i "${srcdir}/grub-10_linux-detect-archlinux-initramfs.patch" echo + msg "Patch to load custom initramfs images" + patch -Np1 -i "${srcdir}/grub-custom-initramfs.patch" + echo + msg "Patch to enable GRUB_COLOR_* variables in grub-mkconfig" ## Based on http://lists.gnu.org/archive/html/grub-devel/2012-02/msg00021.html patch -Np1 -i "${srcdir}/grub-add-GRUB_COLOR_variables.patch" diff --git a/grub-custom-initramfs.patch b/grub-custom-initramfs.patch new file mode 100644 index 0000000..db04746 --- /dev/null +++ b/grub-custom-initramfs.patch @@ -0,0 +1,69 @@ +diff --git a/util/grub-mkconfig.in b/util/grub-mkconfig.in +index ca040dd..c839115 100644 +--- a/util/grub-mkconfig.in ++++ b/util/grub-mkconfig.in +@@ -208,6 +208,7 @@ export GRUB_DEFAULT \ + GRUB_CMDLINE_NETBSD \ + GRUB_CMDLINE_NETBSD_DEFAULT \ + GRUB_CMDLINE_GNUMACH \ ++ GRUB_CUSTOM_INITRD \ + GRUB_TERMINAL_INPUT \ + GRUB_TERMINAL_OUTPUT \ + GRUB_SERIAL_COMMAND \ +diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in +index 7d4086b..73cd12b 100644 +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -136,10 +136,12 @@ EOF + if test -n "${initrd}" ; then + # TRANSLATORS: ramdisk isn't identifier. Should be translated. + message="$(gettext_printf "Loading initial ramdisk ...")" +- sed "s/^/$submenu_indentation/" << EOF +- echo '$(echo "$message" | grub_quote)' +- initrd ${rel_dirname}/${initrd} +-EOF ++ printf ' %s\n' "echo '$(echo "$message" | grub_quote)'" | sed "s/^/$submenu_indentation/" ++ printf ' %s ' 'initrd' | sed "s/^/$submenu_indentation/" ++ for I in "${initrd[@]}"; do ++ printf ' %s/%s' "${rel_dirname}" "${I}" ++ done ++ printf '\n' + fi + sed "s/^/$submenu_indentation/" << EOF + } +@@ -186,7 +188,7 @@ while [ "x$list" != "x" ] ; do + alt_version=`echo $version | sed -e "s,\.old$,,g"` + linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" + +- initrd= ++ initrd=(${GRUB_CUSTOM_INITRD}) + for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ + "initrd-${version}" "initramfs-${version}.img" \ + "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ +@@ -196,7 +198,7 @@ while [ "x$list" != "x" ] ; do + "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ + "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do + if test -e "${dirname}/${i}" ; then +- initrd="$i" ++ initrd+=("$i") + break + fi + done +@@ -215,7 +217,7 @@ while [ "x$list" != "x" ] ; do + fi + + if test -n "${initrd}" ; then +- gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2 ++ gettext_printf "Found initramfs image(s) in %s: %s\n" "${dirname}" "${initrd[*]}" >&2 + elif test -z "${initramfs}" ; then + # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's + # no initrd or builtin initramfs, it can't work here. +@@ -243,7 +245,7 @@ while [ "x$list" != "x" ] ; do + initrd="initramfs-${version}-fallback.img" + + if test -n "${initrd}" ; then +- gettext_printf "Found fallback initramfs image: %s\n" "${dirname}/${initrd}" >&2 ++ gettext_printf "Found fallback initramfs image(s) in %s: %s\n" "${dirname}" "${initrd[*]}" >&2 + fi + + linux_entry "${OS}" "${version}" fallback \ diff --git a/grub-intel-ucode.patch b/grub-intel-ucode.patch deleted file mode 100644 index de6bd28..0000000 --- a/grub-intel-ucode.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in -index d2e2a8f..f67e50f 100644 ---- a/util/grub.d/10_linux.in -+++ b/util/grub.d/10_linux.in -@@ -65,6 +65,12 @@ case x"$GRUB_FS" in - ;; - esac - -+intel_ucode= -+if test -e "/boot/intel-ucode.img" ; then -+ gettext_printf "Found Intel Microcode image\n" >&2 -+ intel_ucode="$(make_system_path_relative_to_its_root /boot/intel-ucode.img)" -+fi -+ - title_correction_code= - - linux_entry () -@@ -136,7 +142,7 @@ EOF - message="$(gettext_printf "Loading initial ramdisk ...")" - sed "s/^/$submenu_indentation/" << EOF - echo '$(echo "$message" | grub_quote)' -- initrd ${rel_dirname}/${initrd} -+ initrd ${intel_ucode} ${rel_dirname}/${initrd} - EOF - fi - sed "s/^/$submenu_indentation/" << EOF diff --git a/grub.default b/grub.default index fdd1fc3..38a039d 100644 --- a/grub.default +++ b/grub.default @@ -4,6 +4,11 @@ GRUB_DISTRIBUTOR="Arch" GRUB_CMDLINE_LINUX_DEFAULT="quiet" GRUB_CMDLINE_LINUX="" +# Add custom initramfs images +# This is a space separated list of custom initramfs images located in /boot +# and loaded before default initramfs +#GRUB_CUSTOM_INITRD="intel-ucode.img" + # Preload both GPT and MBR modules so that they are not missed GRUB_PRELOAD_MODULES="part_gpt part_msdos" -- 2.7.0