Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-133820 / 25.10 / Do not generate initrd for debug kernel if it is not enabled #15526

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']:
yocalebo marked this conversation as resolved.
Show resolved Hide resolved
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})