While installing a rpm to update kernel on a deployed target, it will update the boot area and the boot menu with the kernel as the priority but allow you to fall back to the original kernel as well.
- In pre-install script, it backs up original kernel to avoid confliction with new one. - In post-install script, it updates the new kernel as the boot priority. [YOCTO #4104] Signed-off-by: Hongxu Jia <[email protected]> --- meta/classes/kernel.bbclass | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass index e039dfc..f0dd679 100644 --- a/meta/classes/kernel.bbclass +++ b/meta/classes/kernel.bbclass @@ -263,7 +263,72 @@ ALLOW_EMPTY_kernel-image = "1" ALLOW_EMPTY_kernel-modules = "1" DESCRIPTION_kernel-modules = "Kernel modules meta package" +pkg_preinst_kernel-image () { + if [ -z "$D" ]; then + # Parsing confliction + [ -f /boot/grub/menu.list ] && grubcfg="/boot/grub/menu.list" + [ -f /boot/grub/grub.cfg ] && grubcfg="/boot/grub/grub.cfg" + if [ -n "$grubcfg" ]; then + # Dereference symlink to avoid confliction with new kernel name. + if grep -q "/${KERNEL_IMAGETYPE} root=" $grubcfg; then + kimage=`realpath /boot/${KERNEL_IMAGETYPE}`; + sed -i "s#${KERNEL_IMAGETYPE} root=#${kimage##*/} root=#" $grubcfg + fi + + # Rename old kernel if it conflicts with new kernel name. + if grep -q "/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} root=" $grubcfg; then + timestamp=`date +%s` + kimage="/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-$timestamp-back" + sed -i "s#${KERNEL_IMAGETYPE}-${KERNEL_VERSION} root=#${kimage##*/} root=#" $grubcfg + mv /boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} $kimage + fi + fi + fi +} + pkg_postinst_kernel-image () { + get_new_grub_cfg() { + title="Update ${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-${PV}" + if [ -f /boot/grub/grub.cfg ]; then + rootfs=`grep " *linux [^ ].* root=" /boot/grub/grub.cfg -m 1 | \ + sed "s# *linux [^ ].* root=# linux /${KERNEL_IMAGETYPE}-${KERNEL_VERSION} root=#"` + + echo "menuentry \"$title\" {" + echo " set root=(hd0,1)" + echo "$rootfs" + echo "}" + elif [ -f /boot/grub/menu.list ] ; then + rootfs=`grep "kernel [^ ].* root=" /boot/grub/menu.list -m 1 | \ + sed "s#kernel [^ ].* root=#kernel /${KERNEL_IMAGETYPE}-${KERNEL_VERSION} root=#"` + + echo "default 0" + echo "timeout 30" + echo "title $title" + echo "root (hd0,0)" + echo "$rootfs" + fi + } + + get_old_grub_cfg() { + if [ -f /boot/grub/grub.cfg ]; then + cat /boot/grub/grub.cfg + elif [ -f /boot/grub/menu.list ] ; then + cat /boot/grub/menu.list | sed -e '/^default/d' -e '/^timeout/d' + fi + } + + if [ -z "$D" ]; then + [ -f /boot/grub/menu.list ] && grubcfg="/boot/grub/menu.list" + [ -f /boot/grub/grub.cfg ] && grubcfg="/boot/grub/grub.cfg" + if [ -n "$grubcfg" ]; then + grubcfgtmp="$grubcfg.tmp" + get_new_grub_cfg > $grubcfgtmp + get_old_grub_cfg >> $grubcfgtmp + mv $grubcfgtmp $grubcfg + echo "Caution! Update kernel may affect kernel-module!" + fi + fi + update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then mkdir -p $D/lib/modules/${KERNEL_VERSION} -- 1.8.1.2 _______________________________________________ Openembedded-core mailing list [email protected] http://lists.openembedded.org/mailman/listinfo/openembedded-core
