blob: 061a46b5c372f2fc2e045330c1293c844318a2bc [file] [log] [blame]
#!/bin/sh
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
PKG=$1
if [ -z "${PKG}" ]; then
echo "Usage: $0 cos-kernel-A.B.C-arch.txz"
exit 1
fi
VERSION=$(tar tvfJ "${PKG}" boot/ | grep /config- | sed s/.*config-//)
if [ -z "${VERSION}" ]; then
echo "Could not find kernel version from /boot/config-*"
echo "Check if package is valid"
exit 1
fi
echo "Kernel version: ${VERSION}"
mount -o rw,remount / || true
if mount | grep "on / " | grep -q ro, ; then
echo "Could not remount rootfs as read-write"
exit 1
fi
echo "Remounted rootfs as read-write"
if [ -d "/lib/modules/${VERSION}" ]; then
rm -rf "/lib/modules/${VERSION}"
echo "Modules for ${VERSION} removed"
fi
tar -C / -x -J -f "${PKG}"
ln -sf "vmlinuz-${VERSION}" /boot/vmlinuz
echo "rootfs updated"
ESPMOUNT=$(mktemp -d)
mount /dev/disk/by-label/EFI-SYSTEM "${ESPMOUNT}"
BOOT_IMAGE="${ESPMOUNT}/$(sed 's/.*BOOT_IMAGE=\([^ ]*\) .*/\1/' /proc/cmdline)"
echo "Updating boot image ${BOOT_IMAGE}"
if [ ! -f "${BOOT_IMAGE}" ]; then
echo "Boot image '${BOOT_IMAGE}' is not a regular file"
umount "${ESPMOUNT}"
exit 1
fi
rm -f "${BOOT_IMAGE}"
cp -f "/boot/vmlinuz-${VERSION}" "${BOOT_IMAGE}"
umount "${ESPMOUNT}"
rm -rf "${ESPMOUNT}"
echo "EFI system partition updated"
mount -o ro,remount / || true
echo "Remounted rootfs as read-only"
echo "Reboot the system to activate new kernel"