Skip to content

Commit

Permalink
Do not generate initrd for debug kernel if it is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Jan 30, 2025
1 parent c8ee757 commit fd9f242
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/freenas/usr/local/bin/truenas-initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,26 @@ def update_zfs_module_config(root, readonly_rootfs, database):
try:
database = args.database or os.path.join(root, FREENAS_DATABASE[1:])

if update_required := any((
args.force,
adv_config = query_config_table("system_advanced", database, "adv_")
debug_kernel = adv_config["debugkernel"]

update_required = any((
update_zfs_default(root, readonly_rootfs),
update_pci_initramfs_config(root, readonly_rootfs, database),
update_zfs_module_config(root, readonly_rootfs, database),
)):
readonly_rootfs.make_writeable()
subprocess.run(["chroot", root, "update-initramfs", "-k", "all", "-u"], check=True)
))

for kernel in os.listdir(f"{root}/boot"):
if not kernel.startswith("vmlinuz-"):
continue

kernel_name = kernel.removeprefix("vmlinuz-")
if "debug" in kernel_name and not debug_kernel:
continue

if args.force or update_required or not os.path.exists(f"{root}/boot/initrd.img-{kernel_name}"):
readonly_rootfs.make_writeable()
subprocess.run(["chroot", root, "update-initramfs", "-k", kernel_name, "-u"], check=True)
except Exception:
logger.error("Failed to update initramfs", exc_info=True)
exit(2)
Expand Down
3 changes: 3 additions & 0 deletions src/middlewared/middlewared/plugins/system_advanced/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ async def do_update(self, data):

await self.middleware.call('system.advanced.configure_tty', original_data, config_data, generate_grub)

if config_data['debugkernel']:
await self.middleware.call('boot.update_initramfs')

if consolemsg is not None:
await self.middleware.call('system.general.update', {'ui_consolemsg': consolemsg})

Expand Down
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/system_general/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ async def do_update(self, data):
)

if config['kbdmap'] != new_config['kbdmap']:
await self.set_kbdlayout(new_config['kbdmap'])
await self.set_kbdlayout()

if config['timezone'] != new_config['timezone']:
await self.middleware.call('zettarepl.update_config', {'timezone': new_config['timezone']})
Expand Down Expand Up @@ -299,7 +299,7 @@ async def do_update(self, data):
return await self.config()

@private
async def set_kbdlayout(self, kbdmap='us'):
async def set_kbdlayout(self):
await self.middleware.call('etc.generate', 'keyboard')
await run(['setupcon'], check=False)
await self.middleware.call('boot.update_initramfs', {'force': True})
Expand Down
17 changes: 17 additions & 0 deletions tests/api2/test_system_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ def test_(key, value, grep_file, sshd_config_cmd, validation_error):
with pytest.raises(ValidationErrors) as ve:
call('system.advanced.update', {key: value})
assert ve.value.errors == [ValidationError(key, validation_error)]


def test_debugkernel_initrd():
assert not call("system.advanced.config")["debugkernel"]

initrds = [initrd for initrd in ssh("ls -1 /boot").split() if "initrd" in initrd]
assert len(initrds) == 1
assert "debug" not in initrds[0]

try:
call("system.advanced.update", {"debugkernel": True})

initrds = [initrd for initrd in ssh("ls -1 /boot").split() if "initrd" in initrd]
assert len(initrds) == 2
assert any("debug" in initrd for initrd in initrds)
finally:
call("system.advanced.update", {"debugkernel": False})

0 comments on commit fd9f242

Please sign in to comment.