← Back to team overview

curtin-dev team mailing list archive

[Merge] ~dbungert/curtin:curthooks-kern-reconfigure into curtin:master

 

Dan Bungert has proposed merging ~dbungert/curtin:curthooks-kern-reconfigure into curtin:master.

Commit message:
curthooks: reconfigure kernel after initrd generated

Kernel postinstall scripts do several helpful things that we don't want
to duplicate code for here in curthooks.  Run those scripts.

Done with LP: #2101831 in mind but expected to be more broadly useful.



Requested reviews:
  Server Team CI bot (server-team-bot): continuous-integration
  curtin developers (curtin-dev)
Related bugs:
  Bug #2101831 in subiquity (Ubuntu): "25.04 installation does not come up after post-install reboot on s390x"
  https://bugs.launchpad.net/ubuntu/+source/subiquity/+bug/2101831

For more details, see:
https://code.launchpad.net/~dbungert/curtin/+git/curtin/+merge/482849
-- 
Your team curtin developers is requested to review the proposed merge of ~dbungert/curtin:curthooks-kern-reconfigure into curtin:master.
diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
index 381d59e..efd4d93 100644
--- a/curtin/commands/curthooks.py
+++ b/curtin/commands/curthooks.py
@@ -1693,6 +1693,16 @@ def configure_kernel_crash_dumps(cfg, target: pathlib.Path) -> None:
         kernel_crash_dumps.manual_disable(target)
 
 
+def reconfigure_kernel(target: pathlib.Path) -> None:
+    with util.ChrootableTarget(target) as in_chroot:
+        # re-run kernel postinstall hooks
+        for kernel in distro.dpkg_query_list_kernels(target):
+            in_chroot.subp(
+                ['dpkg-reconfigure', '--frontend=noninteractive', kernel],
+                target=target
+            )
+
+
 def handle_cloudconfig(cfg, base_dir=None):
     """write cloud-init configuration files into base_dir.
 
@@ -2102,6 +2112,13 @@ def builtin_curthooks(cfg, target, state):
             redhat_update_initramfs(target, cfg)
 
     with events.ReportEventStack(
+            name=stack_prefix + '/kernel-postinstall',
+            reporting_enabled=True, level="INFO",
+            description=""):
+        if osfamily == DISTROS.debian:
+            reconfigure_kernel(target)
+
+    with events.ReportEventStack(
             name=stack_prefix + '/configuring-bootloader',
             reporting_enabled=True, level="INFO",
             description="configuring target system bootloader"):
diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
index c26846d..f1bccdb 100644
--- a/tests/unittests/test_curthooks.py
+++ b/tests/unittests/test_curthooks.py
@@ -2744,4 +2744,29 @@ class TestDoAptConfig(CiTestCase):
             curthooks.do_apt_config({"debconf_selections": "foo"}, target="/")
         m_handle_apt.assert_called_once()
 
+
+class TestDpkgReconfigure(CiTestCase):
+    def setUp(self):
+        super(TestDpkgReconfigure, self).setUp()
+        self.target = self.tmp_dir()
+        self.add_patch('curtin.util.subp', 'm_subp')
+        self.add_patch(
+            'curtin.commands.curthooks.distro.dpkg_query_list_kernels',
+            'm_list_kernels'
+        )
+
+    def test_two_kernels(self):
+        kernel_a = self.random_string()
+        kernel_b = self.random_string()
+        self.m_list_kernels.return_value = [kernel_a, kernel_b]
+        curthooks.reconfigure_kernel(self.target)
+        self.m_subp.assert_any_call(
+            ['dpkg-reconfigure', '--frontend=noninteractive', kernel_a],
+            target=self.target,
+        )
+        self.m_subp.assert_any_call(
+            ['dpkg-reconfigure', '--frontend=noninteractive', kernel_b],
+            target=self.target,
+        )
+
 # vi: ts=4 expandtab syntax=python

Follow ups