Improve support for genkernel in 10_linux
Gentoo Linux maintains its own kernel builder and initramfs generation utility called "genkernel".
It looks like some attempt was made to make 10_linux compatible with initiramfs images created by genkernel. However, this support is currently broken. There are two problems.
Firstly, genkernel initramfs images are named like so:
initramfs-genkernel-$ARCH-$version
10_linux currently looks for this:
initramfs-genkernel-$version
The simplest solution here would be to use a wildcard beteen genkernel and $version.
Secondly, genkernel looks for the "real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.
I have attached a rough patch that resolves these issues. I would appreciate any feedback you can give me. My goal is to move this upstream so that I will not have to rebase it in the future.
=== modified file 'util/grub.d/10_linux.in'
grub.d/10_linux.in +17 -5
@@ -135,7 +135,7 @@ message="$(gettext_printf "Loading Linux %s ..." ${version})" sed "s/^/$submenu_indentation/" << EOF echo '$message' - linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} + linux ${rel_dirname}/${basename} ${rootcmd}=${linux_root_device_thisversion} ro ${args} EOF if test -n "${initrd}" ; then # TRANSLATORS: ramdisk isn't identifier. Should be translated.
@@ -181,19 +181,31 @@ alt_version=`echo $version | sed -e "s,\.old$,,g"` linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" + rootcmd=root initrd= + pushd "${dirname}" > /dev/null 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" \ - "initrd-${alt_version}" "initramfs-${alt_version}.img" \ - "initramfs-genkernel-${version}" \ - "initramfs-genkernel-${alt_version}"; do - if test -e "${dirname}/${i}" ; then + "initrd-${alt_version}" "initramfs-${alt_version}.img"; do + if test -e "${i}" ; then initrd="$i" break fi done + if [ "x$initrd" = x ]; then + for i in "initramfs-genkernel"*"-${version}" \ + "initramfs-genkernel"*"-${alt_version}"; do + if test -e "${i}"; then + initrd="$i" + rootcmd=real_root + break + fi + done + fi + popd > /dev/null + config= for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do if test -e "${i}" ; then
Quoted 4 lines · Mike Gilbert
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.
It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "real_root" is unset. This part of my previous patch is therefore pointless.
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
=== modified file 'ChangeLog'
ChangeLog +4 -0
@@ -1,3 +1,7 @@ +2012-04-10 Mike Gilbert <[email protected]> + + * util/grub.d/10_linux.in: Fix detection of genkernel initramfs. + 2012-04-07 Vladimir Serbinenko <[email protected]> * grub-core/normal/charset.c (grub_ucs4_to_utf8): Return number of
=== modified file 'util/grub.d/10_linux.in'
grub.d/10_linux.in +5 -3
@@ -182,17 +182,19 @@ linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" initrd= + pushd "${dirname}" > /dev/null 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" \ "initrd-${alt_version}" "initramfs-${alt_version}.img" \ - "initramfs-genkernel-${version}" \ - "initramfs-genkernel-${alt_version}"; do - if test -e "${dirname}/${i}" ; then + "initramfs-genkernel"*"-${version}" \ + "initramfs-genkernel"*"-${alt_version}"; do + if test -e "${i}" ; then initrd="$i" break fi done + popd > /dev/null config= for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
Quoted 5 lines · Mike Gilbert
Quoted 4 lines · Mike Gilbert
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.
Quoted 7 lines
It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.
Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=uname -m
case "${ARCH}" in
i?86) ARCH="x86" ;; mips|mips64) ARCH="mips" ;; arm*) ARCH=arm ;; *) ;;
esac
I'm thinking it would be a good idea to rename ARCH to something like GENKERNEL_ARCH. We should also let the user override this in /etc/default/grub.
Does that sound ok?
Quoted 33 lines · Mike Gilbert
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=
uname -m
case "${ARCH}" ini?86) ARCH="x86" ;; mips|mips64) ARCH="mips" ;; arm*) ARCH=arm ;; *) ;;
Quoted 7 lines
esac
I'm thinking it would be a good idea to rename ARCH to something like
GENKERNEL_ARCH. We should also let the user override this in/etc/default/grub.Does that sound ok?
I have modified my patch to implement what I describe above.
=== modified file 'ChangeLog'
ChangeLog +4 -0
@@ -1,3 +1,7 @@ +2012-04-11 Mike Gilbert <[email protected]> + + * util/grub.d/10_linux.in: Fix detection of genkernel initramfs. + 2012-04-07 Vladimir Serbinenko <[email protected]> * grub-core/normal/charset.c (grub_ucs4_to_utf8): Return number of
=== modified file 'util/grub.d/10_linux.in'
grub.d/10_linux.in +13 -3
@@ -150,7 +150,8 @@ EOF } -case x`uname -m` in +machine=`uname -m` +case "x$machine" in xi?86 | xx86_64) list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
@@ -161,6 +162,15 @@ done` ;; esac +if test "x${GENKERNEL_ARCH-unset}" = xunset; then + case "$machine" in + i?86) GENKERNEL_ARCH="x86" ;; + mips|mips64) GENKERNEL_ARCH="mips" ;; + arm*) GENKERNEL_ARCH="arm" ;; + *) GENKERNEL_ARCH="$machine" ;; + esac +fi + prepare_boot_cache= prepare_root_cache= boot_device_id=
@@ -186,8 +196,8 @@ "initrd-${version}" "initramfs-${version}.img" \ "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ "initrd-${alt_version}" "initramfs-${alt_version}.img" \ - "initramfs-genkernel-${version}" \ - "initramfs-genkernel-${alt_version}"; do + "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ + "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do if test -e "${dirname}/${i}" ; then initrd="$i" break
Quoted 35 lines · Mike Gilbert
Quoted 34 lines · Mike Gilbert
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=
uname -m
case "${ARCH}" ini?86) ARCH="x86" ;; mips|mips64) ARCH="mips" ;; arm*) ARCH=arm ;; *) ;;esac
Quoted 7 lines
Quoted 5 lines
I'm thinking it would be a good idea to rename ARCH to something like
GENKERNEL_ARCH. We should also let the user override this in/etc/default/grub.Does that sound ok?
I have modified my patch to implement what I describe above.
What is the reason to make it configurable? There shouldn't be any need to configure something that is autodetected
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2012/4/18 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 40 lines · Mike Gilbert
Quoted 39 lines · Mike Gilbert
Quoted 38 lines
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=
uname -m
case "${ARCH}" in
i?86)
ARCH="x86"
;;
mips|mips64)
ARCH="mips"
;;
arm*)
ARCH=arm
;;
*)
;;
esacI'm thinking it would be a good idea to rename ARCH to something like
GENKERNEL_ARCH. We should also let the user override this in/etc/default/grub.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does that sound ok?
I have modified my patch to implement what I describe above.
What is the reason to make it configurable? There shouldn't be any need to configure something that is autodetected
genkernel allows the user to cross-compile their kernel and/or initramfs, in which case uname -m would not provide the correct value.
I don't have a clear picture in my mind of how that would work with grub, but I figure it would be better to err on the side of flexibility.
Quoted 47 lines · Mike Gilbert
2012/4/18 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 40 lines · Mike Gilbert
Quoted 39 lines · Mike Gilbert
Quoted 38 lines
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=
uname -m
case "${ARCH}" ini?86) ARCH="x86" ;; mips|mips64) ARCH="mips" ;; arm*) ARCH=arm ;; *) ;;esac
I'm thinking it would be a good idea to rename ARCH to something like
GENKERNEL_ARCH. We should also let the user override this in/etc/default/grub.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does that sound ok?
I have modified my patch to implement what I describe above.
What is the reason to make it configurable? There shouldn't be any need to configure something that is autodetected
Quoted 6 lines
genkernel allows the user to cross-compile their kernel and/or initramfs, in which case uname -m would not provide the correct value.
I don't have a clear picture in my mind of how that would work with grub, but I figure it would be better to err on the side of flexibility.
grub-mkconfig doesn't support cross-configuration and arch name is just one of the problems. Unless we have a designed system for this case it's useless to add stray bits which don't work anyway.
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
2012/4/18 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 51 lines · Mike Gilbert
Quoted 50 lines
2012/4/18 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 40 lines · Mike Gilbert
Quoted 39 lines · Mike Gilbert
Quoted 38 lines
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=
uname -m
case "${ARCH}" in
i?86)
ARCH="x86"
;;
mips|mips64)
ARCH="mips"
;;
arm*)
ARCH=arm
;;
*)
;;
esacI'm thinking it would be a good idea to rename ARCH to something like
GENKERNEL_ARCH. We should also let the user override this in/etc/default/grub.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does that sound ok?
I have modified my patch to implement what I describe above.
What is the reason to make it configurable? There shouldn't be any need to configure something that is autodetected
genkernel allows the user to cross-compile their kernel and/or initramfs, in which case uname -m would not provide the correct value.
Quoted 7 lines
Quoted 3 lines
I don't have a clear picture in my mind of how that would work with grub, but I figure it would be better to err on the side of flexibility.
grub-mkconfig doesn't support cross-configuration and arch name is just one of the problems. Unless we have a designed system for this case it's useless to add stray bits which don't work anyway.
Alright, not a bit deal. Do you need a new patch from me?
Quoted 52 lines · Mike Gilbert
2012/4/18 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 51 lines · Mike Gilbert
Quoted 50 lines
2012/4/18 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 40 lines · Mike Gilbert
Quoted 39 lines · Mike Gilbert
Quoted 38 lines
2012/4/11 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:
Quoted 10 lines · Mike Gilbert
Quoted 9 lines · Mike Gilbert
Quoted 4 lines
Secondly, genkernel looks for the "
real_root" kernel command line option to determine the root filesystem. This is a holdover from the days when we used true initrd images and we needed to use root=/dev/ram0.It was brought to my attention that genkernel's initramfs code will in fact utilize "root" if "
real_root" is unset. This part of my previous patch is therefore pointless.Quoted 6 lines
Quoted 3 lines
I have attached a revised patch containing only the changes necessary to detect a genkernel initramfs image.
pushd/popd isn't POSIX so we can't use it in our scripts. Also I don't feel like glob expansion is the right thing to use here. Why not infer the architecture from uname ?
That should also work. Here's the logic that genkernel uses to populate ARCH:
ARCH=
uname -m
case "${ARCH}" ini?86) ARCH="x86" ;; mips|mips64) ARCH="mips" ;; arm*) ARCH=arm ;; *) ;;esac
I'm thinking it would be a good idea to rename ARCH to something like
GENKERNEL_ARCH. We should also let the user override this in/etc/default/grub.Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does that sound ok?
I have modified my patch to implement what I describe above.
What is the reason to make it configurable? There shouldn't be any need to configure something that is autodetected
genkernel allows the user to cross-compile their kernel and/or initramfs, in which case uname -m would not provide the correct value.
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
I don't have a clear picture in my mind of how that would work with grub, but I figure it would be better to err on the side of flexibility.
grub-mkconfig doesn't support cross-configuration and arch name is just one of the problems. Unless we have a designed system for this case it's useless to add stray bits which don't work anyway.
Alright, not a bit deal. Do you need a new patch from me?
I've fixed it myself. Also I've kept the incorrect names for backwards compatibility and since they create no problem
Quoted 4 lines
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko