diff options
| author | Hongxu Jia <hongxu.jia@windriver.com> | 2013-10-18 10:45:35 +0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-10-26 15:59:16 +0100 |
| commit | ecf98b4288870be7ab62c3b040896b7877b50b35 (patch) | |
| tree | 5a9e9365c0bc61b2551a002ccaf838725a7de1e9 | |
| parent | 6f5031561194f295cbf4c7aeb40e3996c4dbaa83 (diff) | |
| download | poky-ecf98b4288870be7ab62c3b040896b7877b50b35.tar.gz | |
kernel-grub.bbclass: add a method to install/update for bzImage
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.
[YOCTO #4104]
(From OE-Core rev: 8d872e7712a62fa4313a1114a92907c29beffa2e)
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/classes/kernel-grub.bbclass | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/meta/classes/kernel-grub.bbclass b/meta/classes/kernel-grub.bbclass new file mode 100644 index 0000000000..70564f010a --- /dev/null +++ b/meta/classes/kernel-grub.bbclass | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | # | ||
| 2 | # While installing a rpm to update kernel on a deployed target, it will update | ||
| 3 | # the boot area and the boot menu with the kernel as the priority but allow | ||
| 4 | # you to fall back to the original kernel as well. | ||
| 5 | # | ||
| 6 | # - In kernel-image's preinstall scriptlet, it backs up original kernel to avoid | ||
| 7 | # probable confliction with the new one. | ||
| 8 | # | ||
| 9 | # - In kernel-image's postinstall scriptlet, it modifies grub's config file to | ||
| 10 | # updates the new kernel as the boot priority. | ||
| 11 | # | ||
| 12 | |||
| 13 | pkg_preinst_kernel-image_append () { | ||
| 14 | # Parsing confliction | ||
| 15 | [ -f "$D/boot/grub/menu.list" ] && grubcfg="$D/boot/grub/menu.list" | ||
| 16 | [ -f "$D/boot/grub/grub.cfg" ] && grubcfg="$D/boot/grub/grub.cfg" | ||
| 17 | if [ -n "$grubcfg" ]; then | ||
| 18 | # Dereference symlink to avoid confliction with new kernel name. | ||
| 19 | if grep -q "/${KERNEL_IMAGETYPE} \+root=" $grubcfg; then | ||
| 20 | if [ -L "$D/boot/${KERNEL_IMAGETYPE}" ]; then | ||
| 21 | kimage=`realpath $D/boot/${KERNEL_IMAGETYPE} 2>/dev/null` | ||
| 22 | if [ -f "$D$kimage" ]; then | ||
| 23 | sed -i "s:${KERNEL_IMAGETYPE} \+root=:${kimage##*/} root=:" $grubcfg | ||
| 24 | fi | ||
| 25 | fi | ||
| 26 | fi | ||
| 27 | |||
| 28 | # Rename old kernel if it conflicts with new kernel name. | ||
| 29 | if grep -q "/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} \+root=" $grubcfg; then | ||
| 30 | if [ -f "$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}" ]; then | ||
| 31 | timestamp=`date +%s` | ||
| 32 | kimage="$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-$timestamp-back" | ||
| 33 | sed -i "s:${KERNEL_IMAGETYPE}-${KERNEL_VERSION} \+root=:${kimage##*/} root=:" $grubcfg | ||
| 34 | mv "$D/boot/${KERNEL_IMAGETYPE}-${KERNEL_VERSION}" "$kimage" | ||
| 35 | fi | ||
| 36 | fi | ||
| 37 | fi | ||
| 38 | } | ||
| 39 | |||
| 40 | pkg_postinst_kernel-image_prepend () { | ||
| 41 | get_new_grub_cfg() { | ||
| 42 | grubcfg="$1" | ||
| 43 | title="Update ${KERNEL_IMAGETYPE}-${KERNEL_VERSION}-${PV}" | ||
| 44 | if [ "${grubcfg##*/}" = "grub.cfg" ]; then | ||
| 45 | rootfs=`grep " *linux \+[^ ]\+ \+root=" $grubcfg -m 1 | \ | ||
| 46 | sed "s# *linux \+[^ ]\+ \+root=# linux /${KERNEL_IMAGETYPE}-${KERNEL_VERSION} root=#"` | ||
| 47 | |||
| 48 | echo "menuentry \"$title\" {" | ||
| 49 | echo " set root=(hd0,1)" | ||
| 50 | echo "$rootfs" | ||
| 51 | echo "}" | ||
| 52 | elif [ "${grubcfg##*/}" = "menu.list" ]; then | ||
| 53 | rootfs=`grep "kernel \+[^ ]\+ \+root=" $grubcfg -m 1 | \ | ||
| 54 | sed "s#kernel \+[^ ]\+ \+root=#kernel /${KERNEL_IMAGETYPE}-${KERNEL_VERSION} root=#"` | ||
| 55 | |||
| 56 | echo "default 0" | ||
| 57 | echo "timeout 30" | ||
| 58 | echo "title $title" | ||
| 59 | echo "root (hd0,0)" | ||
| 60 | echo "$rootfs" | ||
| 61 | fi | ||
| 62 | } | ||
| 63 | |||
| 64 | get_old_grub_cfg() { | ||
| 65 | grubcfg="$1" | ||
| 66 | if [ "${grubcfg##*/}" = "grub.cfg" ]; then | ||
| 67 | cat "$grubcfg" | ||
| 68 | elif [ "${grubcfg##*/}" = "menu.list" ]; then | ||
| 69 | cat "$grubcfg" | sed -e '/^default/d' -e '/^timeout/d' | ||
| 70 | fi | ||
| 71 | } | ||
| 72 | |||
| 73 | if [ -f "$D/boot/grub/grub.cfg" ]; then | ||
| 74 | grubcfg="$D/boot/grub/grub.cfg" | ||
| 75 | old_image=`grep ' *linux \+[^ ]\+ \+root=' -m 1 "$grubcfg" | awk '{print $2}'` | ||
| 76 | elif [ -f "$D/boot/grub/menu.list" ]; then | ||
| 77 | grubcfg="$D/boot/grub/menu.list" | ||
| 78 | old_image=`grep '^kernel \+[^ ]\+ \+root=' -m 1 "$grubcfg" | awk '{print $2}'` | ||
| 79 | fi | ||
| 80 | |||
| 81 | # Don't update grubcfg at first install while old bzImage doesn't exist. | ||
| 82 | if [ -f "$D/boot/$old_image" ]; then | ||
| 83 | grubcfgtmp="$grubcfg.tmp" | ||
| 84 | get_new_grub_cfg "$grubcfg" > $grubcfgtmp | ||
| 85 | get_old_grub_cfg "$grubcfg" >> $grubcfgtmp | ||
| 86 | mv $grubcfgtmp $grubcfg | ||
| 87 | echo "Caution! Update kernel may affect kernel-module!" | ||
| 88 | fi | ||
| 89 | } | ||
| 90 | |||
