20-kernel-update: leave kernel.bin where the kernel set put it
The hook deleted /boot/kernel/kernel.bin once it was on the FAT partition, so the health audit always reported it missing (seen on the gateway after the 26.7.9 upgrade). It now leaves the kernel set's files alone and returns early, without a space check or a log line, when the kernel and device tree on the FAT partition are already the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
aa8c49368d
commit
5e215f5997
3 changed files with 49 additions and 10 deletions
|
|
@ -667,7 +667,11 @@ The kernel is booted by U-Boot from the FAT partition, not from
|
|||
`/boot/kernel`. After a kernel set update, `rc.syshook.d/stop/20-kernel-update`
|
||||
installs the new kernel there at shutdown. It keeps the previous one as
|
||||
`kernel.old`, never leaves `kernel.img` missing, and retries at the next
|
||||
shutdown if it can't finish.
|
||||
shutdown if it can't finish. `/boot/kernel/kernel.bin` stays where the kernel
|
||||
set put it, so the health audit finds the set complete; a shutdown whose
|
||||
kernel and device tree are on the FAT partition already does nothing. (Up to
|
||||
`mono-gateway` 26.7.9_116 the hook deleted it, and the audit reported it
|
||||
missing; `opnsense-update -fk` puts it back.)
|
||||
|
||||
If a new kernel doesn't boot, interrupt U-Boot on the serial console:
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@
|
|||
#
|
||||
# U-Boot loads kernel.img and the device tree straight from the FAT boot
|
||||
# partition (/boot/msdos), not from /boot/kernel. After opnsense-update has
|
||||
# installed a kernel set, this moves the new kernel.bin and device tree onto
|
||||
# the FAT partition before the reboot.
|
||||
# installed a kernel set, this copies the new kernel.bin and device tree onto
|
||||
# the FAT partition before the reboot. They stay in /boot as the kernel set
|
||||
# installed them (the health audit checks the set's files); a shutdown that
|
||||
# finds them on the FAT partition already does nothing.
|
||||
#
|
||||
# kernel.img must stay bootable throughout: nothing on the FAT partition is
|
||||
# touched unless there is room for the new files, the new kernel is copied
|
||||
# and verified before the old one is replaced, the old one is kept as
|
||||
# kernel.old, and it is restored if a step fails. If the update cannot be
|
||||
# done, /boot/kernel/kernel.bin is left in place so the next shutdown retries.
|
||||
# done, the next shutdown tries again.
|
||||
#
|
||||
# GW_ROOT prefixes every path (tests only).
|
||||
#
|
||||
|
|
@ -84,8 +86,13 @@ if [ ! -f "${BOOT}/kernel.img" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Room needed for the new copies; stale .old/.new files are given back first.
|
||||
DTB_TARGET=${BOOT}/dtb/mono-gateway-dk.dtb
|
||||
if cmp -s "${NEW_KERNEL}" "${BOOT}/kernel.img" &&
|
||||
{ [ ! -f "${NEW_DTB}" ] || cmp -s "${NEW_DTB}" "${DTB_TARGET}"; }; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Room needed for the new copies; stale .old/.new files are given back first.
|
||||
NEED=$(( $(size "${NEW_KERNEL}") + $(size "${NEW_DTB}") + MARGIN ))
|
||||
HAVE=$(( $(free_bytes) + $(size "${BOOT}/kernel.old") + $(size "${BOOT}/kernel.new") \
|
||||
+ $(size "${BOOT}/dtb/mono-gateway-dk.old") + $(size "${BOOT}/dtb/mono-gateway-dk.new") ))
|
||||
|
|
@ -110,7 +117,5 @@ if [ -f "${NEW_DTB}" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
rm -f "${NEW_KERNEL}"
|
||||
sync
|
||||
log "installed new kernel and device tree on ${BOOT} (previous kept as kernel.old)"
|
||||
exit 0
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class KernelHookTest(unittest.TestCase):
|
|||
def assertUntouched(self):
|
||||
self.assertEqual(self.content("/boot/msdos/kernel.img"), self.OLD)
|
||||
self.assertEqual(self.content("/boot/msdos/dtb/mono-gateway-dk.dtb"), self.OLD_DTB)
|
||||
self.assertEqual(self.content("/boot/kernel/kernel.bin"), self.NEW, "retry on next shutdown")
|
||||
self.assertEqual(self.content("/boot/kernel/kernel.bin"), self.NEW, "the kernel set's file")
|
||||
self.assertIsNone(self.content("/boot/msdos/kernel.new"))
|
||||
|
||||
def test_update(self):
|
||||
|
|
@ -102,11 +102,16 @@ class KernelHookTest(unittest.TestCase):
|
|||
self.assertEqual(self.content("/boot/msdos/kernel.old"), self.OLD)
|
||||
self.assertEqual(self.content("/boot/msdos/dtb/mono-gateway-dk.dtb"), self.NEW_DTB)
|
||||
self.assertEqual(self.content("/boot/msdos/dtb/mono-gateway-dk.old"), self.OLD_DTB)
|
||||
self.assertIsNone(self.content("/boot/kernel/kernel.bin"))
|
||||
# left as the kernel set installed them: the health audit checks them
|
||||
self.assertEqual(self.content("/boot/kernel/kernel.bin"), self.NEW)
|
||||
self.assertEqual(self.content("/boot/dtb/freescale/mono-gateway-dk.dtb"), self.NEW_DTB)
|
||||
self.assertIsNone(self.content("/boot/msdos/kernel.new"))
|
||||
logged = len(self.fx.calls())
|
||||
r = self.run_hook()
|
||||
self.assertEqual(r.returncode, 0, "second shutdown is a no-op")
|
||||
self.assertEqual(self.content("/boot/msdos/kernel.old"), self.OLD)
|
||||
self.assertEqual(self.content("/boot/msdos/dtb/mono-gateway-dk.old"), self.OLD_DTB)
|
||||
self.assertEqual(len(self.fx.calls()), logged, "nothing logged when nothing changes")
|
||||
|
||||
def test_nothing_to_do(self):
|
||||
os.unlink(self.fx.path("/boot/kernel/kernel.bin"))
|
||||
|
|
@ -123,7 +128,32 @@ class KernelHookTest(unittest.TestCase):
|
|||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.content("/boot/msdos/kernel.img"), self.OLD)
|
||||
self.assertEqual(self.content("/boot/msdos/kernel.old"), b"older")
|
||||
self.assertIsNone(self.content("/boot/kernel/kernel.bin"))
|
||||
self.assertEqual(self.content("/boot/kernel/kernel.bin"), self.OLD)
|
||||
self.assertEqual(self.fx.calls(), [])
|
||||
|
||||
def test_installed_kernel_on_a_full_partition(self):
|
||||
# nothing to install: no space check, no message on every shutdown
|
||||
self.fx.write("/boot/kernel/kernel.bin", self.OLD)
|
||||
self.fx.write("/boot/dtb/freescale/mono-gateway-dk.dtb", self.OLD_DTB)
|
||||
r = self.run_hook(FAKE_FREE_KB="1")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(r.stderr, "")
|
||||
self.assertEqual(self.fx.calls(), [])
|
||||
|
||||
def test_same_kernel_new_device_tree(self):
|
||||
self.fx.write("/boot/kernel/kernel.bin", self.OLD)
|
||||
r = self.run_hook()
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.content("/boot/msdos/kernel.img"), self.OLD)
|
||||
self.assertIsNone(self.content("/boot/msdos/kernel.old"), "the kernel was not replaced")
|
||||
self.assertEqual(self.content("/boot/msdos/dtb/mono-gateway-dk.dtb"), self.NEW_DTB)
|
||||
|
||||
def test_installed_kernel_without_device_tree_in_set(self):
|
||||
self.fx.write("/boot/kernel/kernel.bin", self.OLD)
|
||||
os.unlink(self.fx.path("/boot/dtb/freescale/mono-gateway-dk.dtb"))
|
||||
r = self.run_hook(FAKE_FREE_KB="1")
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertEqual(self.fx.calls(), [])
|
||||
|
||||
def test_fat_not_mounted(self):
|
||||
os.unlink(self.fx.path("/boot/msdos/kernel.img"))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue