Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Saul Wold <sgw@linux.intel.com>
To: Hongxu Jia <hongxu.jia@windriver.com>
Cc: openembedded-core@lists.openembedded.org
Subject: Re: [PATCH 1/1] kernel-grub.bbclass: a method to install/update for bzImage
Date: Wed, 16 Oct 2013 10:54:15 -0700	[thread overview]
Message-ID: <525ED2C7.7080107@linux.intel.com> (raw)
In-Reply-To: <3972d66ce581c06b12d537cddd57df794b8f841b.1379488759.git.hongxu.jia@windriver.com>

On 09/18/2013 12:26 AM, Hongxu Jia wrote:
> 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.
>
Will this work for deb or ipk?

Sau!

> - In kernel-image's preinstall scriptlet, it backs up original kernel to avoid
>    probable confliction with the new one.
> - In kernel-image's postinstall scriptlet, it modify grub's config file to
>    updates the new kernel as the boot priority.
>
> [YOCTO #4104]
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>   meta/classes/kernel-grub.bbclass | 79 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 79 insertions(+)
>   create mode 100644 meta/classes/kernel-grub.bbclass
>
> diff --git a/meta/classes/kernel-grub.bbclass b/meta/classes/kernel-grub.bbclass
> new file mode 100644
> index 0000000..21fcabe
> --- /dev/null
> +++ b/meta/classes/kernel-grub.bbclass
> @@ -0,0 +1,79 @@
> +#
> +# 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 kernel-image's preinstall scriptlet, it backs up original kernel to avoid
> +#   probable confliction with the new one.
> +#
> +# - In kernel-image's postinstall scriptlet, it modify grub's config file to
> +#   updates the new kernel as the boot priority.
> +#
> +
> +pkg_preinst_kernel-image_append () {
> +	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_prepend () {
> +	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
> +}
> +
>


  reply	other threads:[~2013-10-16 17:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-18  7:26 [PATCH V2 0/1] kernel-grub.bbclass: a method to install/update for bzImage Hongxu Jia
2013-09-18  7:26 ` [PATCH 1/1] " Hongxu Jia
2013-10-16 17:54   ` Saul Wold [this message]
2013-10-18  2:34     ` Hongxu Jia
2013-10-10  2:30 ` [PATCH V2 0/1] " Hongxu Jia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=525ED2C7.7080107@linux.intel.com \
    --to=sgw@linux.intel.com \
    --cc=hongxu.jia@windriver.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox