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

feature request: support custom content inside upgrade initramfs #1247

Open
verdverm opened this issue May 30, 2024 · 6 comments
Open

feature request: support custom content inside upgrade initramfs #1247

verdverm opened this issue May 30, 2024 · 6 comments
Labels
documentation Docs/comments with no functional change enhancement New feature or request Requires Leapp PR The patch has to be merged/tested with Leapp PR

Comments

@verdverm
Copy link

In the process of our efforts to support luks on c7->r8, we found that adding a custom overlay to be very helpful and require minimal changes. For the actual implementation, I would expect that this would be enabled and included via an ENV var.

LEAPP_CUSTOM_INITRAMFS_OVERLAY=<path> would turn this on and set src to CopyFile

diff --git a/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/files/generate-initram.sh b/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/files/generate-initram.sh
index 9648234c..205f8071 100755
--- a/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/files/generate-initram.sh
+++ b/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/files/generate-initram.sh
@@ -107,6 +107,7 @@ build() {
         --no-hostonly \
         --kver "$KERNEL_VERSION" \
         --kernel-image "vmlinuz-upgrade.$KERNEL_ARCH" \
+        --include /custom-overlay /
         "initramfs-upgrade.${KERNEL_ARCH}.img"
     popd || {
         echo "ERROR: Failed to change directory using 'popd'.";
diff --git a/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py b/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py
index 5a686a47..b1dccd92 100644
--- a/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py
+++ b/repos/system_upgrade/common/actors/initramfs/upgradeinitramfsgenerator/libraries/upgradeinitramfsgenerator.py
@@ -10,6 +10,7 @@ from leapp.models import RequiredUpgradeInitramPackages  # deprecated
 from leapp.models import UpgradeDracutModule  # deprecated
 from leapp.models import (
     BootContent,
+    CopyFile,
     TargetOSInstallationImage,
     TargetUserSpaceInfo,
     TargetUserSpaceUpgradeTasks,
@@ -229,6 +230,7 @@ def prepare_userspace_for_initram(context):
     # install all required rpms first, so files installed/copied later
     # will not be overwritten during the dnf transaction
     _install_initram_deps(packages)
+    files.append(CopyFile(src="/root/overlay", dst="/custom-overlay"))
     _copy_files(context, files)
@pirat89
Copy link
Member

pirat89 commented May 30, 2024

hi, thanks for sharing. well, it's a little bit mystery what is exactly the content of /custom-overlay in this context. Can you describe better how it helped you to resolve the problem?. Adding something like that would require also some documentation (like what to put inside, etc.) and if it should resolve somehow upgrades with LUKS, it would require also some detection that the directory contains expected data I would guess. adding just this, saying "you can set this envar to handle LUKS" is not something what would be helpful to people. I honestly do not know whether it's special terminology around LUKS when speaking about /custom-overlay. I hear about such a dir for the first time, so I expect that you did something more to make it useful for you.

however, adding additional custom files/dirs inside the initramfs is one of things that people can actually do without the need to modify our code, using custom actors. People can just create their custom actor to customize the initramfs content producing UpgradeInitramfsTasks and TargetUserSpaceUpgradeTasks messages (see definitions of these classes in models dir; I tried to describe them in details). The custom actor could look like this (I haven't tried the code, it's possible I did some mistakes when I wrote it now):

from leapp.actors import Actor
from leapp.models import (
    CopyFile,
    TargetUserSpaceUpgradeTasks,
    UpgradeInitramfsTasks
)
from leapp.tags import FactsPhaseTag, IPUWorkflowTag

class CustomizeUpgradeInitramfs(Actor):
    name = 'customize_upgrade_initramfs'
    consumes = ()
    produces = (TargetUserSpaceUpgradeTasks, UpgradeInitramfsTasks)
    tags = (IPUWorkflowTag, FactsPhaseTag)

    def process(self):
        # ... any other code to conditionalize produce of msgs below ... then
        self.produce(TargetUserSpaceUpgradeTasks(copy_files=[CopyFile(src="/root/overlay", dst="/custom-overlay")]))
        self.produce(UpgradeInitramfsTasks(include_files=['/custom-overlay'']))

OTOH, we expect to create/document templates for custom actors in future. Do you consider such type of template to be helpful? For now, this seems to me like an example we could use for the template. We hope to have restructuralized documentation during summer.

When you are trying to do some customisations, I suggest you to check defined models that contain Task / Tasks substring:

grep -r "Model" models | grep Task

these models are specially created to simplify or make possibly various actions (and customisations) during the upgrade.

@pirat89
Copy link
Member

pirat89 commented May 30, 2024

@verdverm ah, now I read your comment in #1239 (reply in thread) which is explaining little bit more how the directory helped you. Regarding that, I guess that would be helpful to have something like UpgradeKernelCmdlineArgTasks - analogy to TargetKernelCmdlineArgTasks.

@verdverm
Copy link
Author

verdverm commented May 30, 2024

for some context, we are modifying the leapp files after installing the leapp packages

  • we don't know what/how to modify to get things working, so this is an easy and fast iteration cycle
  • applying a few patches is much lower effort than figuring out how to develop / package / install custom actors right now

The idea for the overlay is that a user can specify an arbitrary directory to overlay. It provides flexibility to the situation and doesn't require developing and shipping a custom actor. The ENV var would be super simple from our pov

@verdverm
Copy link
Author

verdverm commented May 30, 2024

If there is a way / tutorial on how to drop some files into an existing leapp install that would effectively do the same thing, that would be helpful and ideally better align with how to modify leapp appropriately

@pirat89 pirat89 changed the title feature request: support custom overlay into initramfs feature request: support custom content inside upgrade initramfs Jun 1, 2024
@pirat89 pirat89 added the enhancement New feature or request label Jun 1, 2024
@pirat89
Copy link
Member

pirat89 commented Jun 1, 2024

Thanks for the feedback. Well I see here two things we can do:

  • provide documentation how to customize this using custom actors
  • once the frameworks supports configurations for actors, make it possible to configure to configure this by a configuration file so no code is needed at all

I expect we can put it into the documentation this summer. We expect to implement support for configuration files in framework during this summer also, so I expect this case could be potentially covered till Feb.

I am not in favor of another envar so much honestl, as I have the feel that number of envars possible to use in this project is becoming large and the usability would be limitted. So I prefer to stay just with options I mentioned.

@abadger headsup ^ candidate for configuration
@matejmatuska headsup ^ candidate for template

@pirat89 pirat89 added documentation Docs/comments with no functional change Requires Leapp PR The patch has to be merged/tested with Leapp PR labels Jun 1, 2024
@verdverm
Copy link
Author

verdverm commented Jun 1, 2024

A configuration file would be even better!

I'd be happy to check out the template concept if you have some early docs / examples.

I sort of have a thing for templates, generally speaking... https://github.com/hofstadter-io/hof :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Docs/comments with no functional change enhancement New feature or request Requires Leapp PR The patch has to be merged/tested with Leapp PR
Projects
None yet
Development

No branches or pull requests

2 participants