Skip to content

Commit

Permalink
squash init_late/init_cleanup, ensure init_final items run before swi…
Browse files Browse the repository at this point in the history
…tch_root

Signed-off-by: Zen <[email protected]>
  • Loading branch information
desultory committed Jan 26, 2025
1 parent 0fa7638 commit 38cdecd
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 0 additions & 2 deletions docs/dev_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ By default, the following init hooks are available:
* `init_pre` - Where the base initramfs environment is set up; basic mounts are initialized and the kernel cmdline is read.
* `init_debug` - Where a shell is started if `start_shell` is enabled in the debug module.
* `init_main` - Most important initramfs activities should take place here.
* `init_late` - Space for late initramfs actions, such as activating LVM volumes.
* `init_mount` - Where the root filesystem mount takes place
* `init_cleanup` - Currently unused, where cleanup before `switch_root` should take place.
* `init_final` - Where `switch_root` is executed.

> These hooks are defined under the `init_types` list in the `InitramfsGenerator` object.
Expand Down
9 changes: 8 additions & 1 deletion src/ugrd/base/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "desultory"
__version__ = "6.4.0"
__version__ = "6.5.0"

from pathlib import Path

Expand Down Expand Up @@ -65,6 +65,13 @@ def set_shebang(self) -> None:
self.logger.info("Setting shebang to: %s", colorize(self["shebang"], "cyan", bright=True))


def set_init_final_order(self) -> None:
"""Adds a "before" do_switch_root order to everything in the init_final hook, excep do_switch_root."""
for hook in self["imports"]["init_final"]:
if hook.__name__ != "do_switch_root":
self["import_order"] = {"before": {hook.__name__: "do_switch_root"}}


def export_switch_root_target(self) -> None:
"""Adds SWITCH_ROOT_TARGET to exports.
Uses switch_root_target if set, otherwise uses the rootfs."""
Expand Down
3 changes: 3 additions & 0 deletions src/ugrd/base/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ autodetect_init = true
[imports.build_tasks]
"ugrd.base.base" = [ "set_shebang", "export_switch_root_target" ]

[imports.build_final]
"ugrd.base.base" = [ "set_init_final_order" ]

[imports.init_pre]
"ugrd.base.base" = [ "set_loglevel" ]

Expand Down
3 changes: 1 addition & 2 deletions src/ugrd/fs/ext4.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
modules = [ "ugrd.fs.mounts" ]
kmod_init = [ "ext4" ]


[imports.init_cleanup]
[imports.init_final]
"ugrd.fs.ext4" = [ "ext4_fsck" ]

[conditional_dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/ugrd/fs/mounts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ late_fstab = "/etc/fstab.late"
[imports.functions]
"ugrd.fs.mounts" = [ "mount_root" ]

[imports.init_cleanup]
[imports.init_final]
"ugrd.fs.mounts" = [ "umount_fstab" ]

[import_order.after]
Expand Down
2 changes: 0 additions & 2 deletions src/ugrd/initramfs_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def __init__(self, config="/etc/ugrd/config.toml", *args, **kwargs):
self.init_types = [
"init_debug",
"init_main",
"init_late",
"init_mount",
"init_cleanup",
]

# Passed kwargs must be imported early, so they will be processed against the base configuration
Expand Down

0 comments on commit 38cdecd

Please sign in to comment.