Skip to content

vm-less and daemon-less ELBE build without mknod - #487

Open
koalo wants to merge 9 commits into
Linutronix:masterfrom
koalo:devel/koalo/container-nomknod
Open

koalo wants to merge 9 commits into
Linutronix:masterfrom
koalo:devel/koalo/container-nomknod

Conversation

@koalo

@koalo koalo commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This supersedes #482 by removing the manual mknod procedures with passing udev and /dev directly into the container for the rootful case.

Also reordered the commits as discussed:

  1. ELBE without initvm (rootful)

fc80da4
54c6257
da13574

  1. Container for ELBE without initvm (rootful)

d532e23
9843820
d7f66a3
707b6c6

  1. Test for 2)

ea2994e
ec47114
b5b9d22

  1. ELBE without initvm (rootless)

No additional commits, but requires to manually unshare if not done via container.

  1. Test XML that allows to build rootless

0095a8d

  1. Container for ELBE without initvm (rootless)

43a09d5
41e12bf
76aa59e
79d2fd0

  1. Test for 6)

d4cabf0

@t-8ch t-8ch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I focused on step 1) for now.
You could also drop the other steps for now and we do one after the other.

Comment thread elbepack/commands/build.py Resolved
Comment thread elbepack/commands/build.py Resolved
Comment thread elbepack/localbuildaction.py Resolved
Comment thread elbepack/localbuildaction.py Resolved
Comment thread elbepack/localbuildaction.py Resolved
Comment thread elbepack/asyncworker.py Resolved
Comment thread elbepack/localbuildaction.py Resolved
Comment thread elbepack/repomanager.py Resolved
Comment thread elbepack/repomanager.py Resolved
Comment thread elbepack/paths.py Resolved
@koalo
koalo force-pushed the devel/koalo/container-nomknod branch 2 times, most recently from 3b2caf8 to 90dc4e3 Compare September 8, 2026 15:39
Comment thread elbepack/repomanager.py
for lic in repo_conf.splitlines():
if lic.startswith('SignWith'):
self.keyid = lic.split()[1]
conf_dist = self.volume.joinpath('conf', 'distributions')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end we want to have a repository/SBOM for the build environment, even if that wasn't an initvm.
We can probably skip it for now, but will need some solution before making this a stable feature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought of that, but wasn't sure how/if to approach it properly, because I am not so sure if copying the exact same approach from initvm is actually useful for the container use case.

Sure, SBOM generation for the container environment should be done. But for that I guess we should first look how we want to approach SBOM generation for ELBE in the first place (as you mentioned debsbom before).

For the packages, do you think it is worth to assemble the Debian packages from the container standalone like we do for initvm? Wouldn't it be more convenient to just archive the whole container including all the configuration / scripting / ...

@t-8ch t-8ch Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more convenient to just archive the whole container including all the configuration / scripting /

We'll need a machine-readable description of it, not only the raw artifacts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a machine-readable description of it, not only the raw artifacts.

Yes, definitely! I meant the "archived container" just as replacement for the binary artifacts of the initvm CD, not as replacement for the SBOM.

Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/tests/test_rootcheck.py Resolved
Comment thread elbepack/tests/test_rootcheck.py Resolved
Comment thread elbepack/tests/test_rootcheck.py Resolved
Comment thread elbepack/tests/test_rootcheck.py Resolved
Comment thread elbepack/tests/test_xml_initvm.py Resolved
@koalo
koalo force-pushed the devel/koalo/container-nomknod branch 3 times, most recently from 3ad19f5 to 0cbcbdb Compare September 30, 2026 13:42
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/shellhelper.py Resolved
Comment thread elbepack/shellhelper.py Resolved
Comment thread elbepack/tests/test_rootcheck.py Resolved
Comment thread docs/elbe-build.rst Resolved
Comment thread conftest.py Resolved
Comment thread elbepack/tests/test_xml_container.py Resolved
Comment thread elbepack/imgutils.py Resolved
@koalo
koalo force-pushed the devel/koalo/container-nomknod branch from 0cbcbdb to b415f97 Compare October 1, 2026 08:59
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/initvmaction.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread elbepack/localbuildaction.py Resolved
@koalo
koalo force-pushed the devel/koalo/container-nomknod branch 4 times, most recently from 95af6b2 to 37ead4c Compare October 5, 2026 06:23
Comment thread elbepack/fstab.py Resolved
Comment thread elbepack/shellhelper.py Resolved
Comment thread elbepack/buildsubmitaction.py Resolved
Comment thread contrib/containerfile/Containerfile Resolved
Comment thread docs/article-container.rst Resolved
Comment thread elbepack/tests/test_xml_container.py Resolved
Comment thread elbepack/tests/test_xml_container.py Resolved
Comment thread contrib/containerfile/entrypoint.sh Resolved
Comment thread conftest.py
' RAM. Use --basetemp=<dir> or set TMPDIR to select another'
' location.',
)
os.environ['TMPDIR'] = str(var_tmp)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I am aware that I asked for this, it is quite complicated...
Maybe we test for the free space instead? That could be done easily in pure python.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. If you really want it, I can of course implement it. The change for that would be small (see below). But I am not really sure if just checking for the amount of free space is the correct approach. I see two problems with that

  1. It introduces an arbitrary constant. How could we know how much space we really need?
  2. Even if there is enough space in the RAM for the full build, it still leads to excessive RAM usage, leaving fewer RAM for the build as well as parallel processes. My initial issue that triggered the idea to move to /var/tmp was actually not that the build was failing, but that my browser that I had open in parallel got unusable slow. We can then of course keep some buffer, but again, how much buffer is sufficient?
--- a/conftest.py
+++ b/conftest.py
@@ -2,10 +2,12 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 # SPDX-FileCopyrightText: 2024 Linutronix GmbH
 
 import os
-import subprocess
+import shutil
 import tempfile
 from pathlib import Path
 
 import pytest
 
+# Minimum free space required in the temp dir for large build artifacts.
+MIN_TMP_FREE = 20 * 1024**3
 
 # https://stackoverflow.com/a/61193490
 def pytest_addoption(parser):
@@ -22,12 +24,6 @@
     )
 
 
-def _is_ram_backed(path):
-    fstype = subprocess.run(
-        ['stat', '-f', '-c', '%T', path],
-        capture_output=True, text=True, check=False,
-    ).stdout.strip()
-    return fstype in ('tmpfs', 'ramfs')
-
-
 def pytest_configure(config):
     config.addinivalue_line('markers', 'slow: mark test as slow to run')
@@ -46,19 +42,22 @@
         os.environ.setdefault('PYTHONWARNINGS', ' '.join(warnings))
 
-    # Avoid filling up the RAM with large build artifacts: unless the user
-    # chose a location, move away from the default temp dir if it is RAM-backed.
+    # Avoid filling up the temp dir (often RAM-backed) with large build
+    # artifacts: unless the user chose a location, move away from the default
+    # temp dir if it has too little free space.
     if 'TMPDIR' not in os.environ and not config.option.basetemp:
-        if _is_ram_backed(Path(tempfile.gettempdir())):
+        if shutil.disk_usage(tempfile.gettempdir()).free < MIN_TMP_FREE:
             var_tmp = Path('/var/tmp')
-            if not var_tmp.is_dir() or not os.access(var_tmp, os.W_OK | os.X_OK):
+            if (
+                not var_tmp.is_dir()
+                or not os.access(var_tmp, os.W_OK | os.X_OK)
+                or shutil.disk_usage(var_tmp).free < MIN_TMP_FREE
+            ):
                 raise pytest.UsageError(
-                    f'{tempfile.gettempdir()} is RAM-backed and {var_tmp} is not a'
-                    ' writable directory. Large build artifacts would fill up the'
-                    ' RAM. Use --basetemp=<dir> or set TMPDIR to select another'
-                    ' location.',
+                    f'{tempfile.gettempdir()} has less than'
+                    f' {MIN_TMP_FREE // 1024**3} GiB free and {var_tmp} is not a'
+                    ' writable directory with enough free space. Use'
+                    ' --basetemp=<dir> or set TMPDIR to select another location.',
                 )
             os.environ['TMPDIR'] = str(var_tmp)
             # tempfile has cached the old location by now, so reset
             tempfile.tempdir = None

Comment thread elbepack/localbuildaction.py Outdated

class LocalProjectBackend(ProjectBackend):
def __init__(self, cache_dir, outdir):
self.pm = ProjectManager(cache_dir)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The database is still stored in /var/cache/elbe. Can we move it into the cache_dir parameter here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored the whole handling around the cache dir. This was also needed for native builds (because it otherwise resulted in too long socket paths with the gpg agent).

@koalo
koalo force-pushed the devel/koalo/container-nomknod branch 5 times, most recently from 4d50acb to 2596a54 Compare October 16, 2026 13:50
Comment thread elbepack/virtapt.py
def __init__(self, xml):

self.xml = xml
self._saved_config = {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you mention in the commit message why we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased this branch onto master and tried to explain this commit better

elbepack: virtapt: restore global apt config on delete
    
VirtApt modifies the process-global apt_pkg.config (Dir::*, APT::*) to point
into its temporary directory.
    
Until now, the modification by VirtApt (as consequence of the elbe
check_updates command) and a build never occured in the same process.
But if we want to support fully native builds and tests (i.e. without
containers and without VM), these apt_pkg.config settings are no longer
strictly isolated process-wise, so they could leak over.
    
Therefore, revert the settings after VirtApt is done by remembering the
original values and restoring them in delete().
    
Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>

@koalo
koalo force-pushed the devel/koalo/container-nomknod branch from 2596a54 to eff1fe3 Compare November 2, 2026 08:38
@koalo

koalo commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@t-8ch Also needed to add 1dacc79 to make the GitHub CI run successful, because it changed to Ubuntu 26.04 in the meantime.

/tmp is usually RAM-backed, so when putting build artifacts there, it
will fill up very quickly and exhaust the RAM. Therefore, use /var/tmp
per default. On Debian systems /var/tmp will still follow a retention
policy, so any potential leftovers will be removed after 30 days
(in the default configuration).

On systems where /tmp is not RAM-backed, still use it.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
Add a build_driver fixture that hides how the XML files under test are
built, so we can in future support multiple different drivers like
initvm and container based.

Use absolute paths since native builds run in-process and the build
changes the working directory of the pytest process (e.g. asyncworker
chdir('/')). Relative XML paths used by later tests then fail to load.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
Split the test_xml to only contain code that is not directly related to
the initvm. This will enable us in the next step to add further tests
that will use the container-based approach.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
Build a simple image without a bootloader to demonstrate
an ELBE build that does not require elevated privileges.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
…without udev

Setup UUID as needed e.g. for grub, because that is usually also done by udev.
So without udev, we need a replacement for that functionality.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
Run the XML build tests by calling elbe build directly on the host
instead of going through an initvm, using the build_driver abstraction.
Tests that need root privileges are skipped when not run as root.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
With the recent additions, it is no longer necessary to spawn an initvm
to build ELBE images. Therefore, provide a container that enables this
use case and replace the existing legacy containerfile with it.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
Provide a test driver to run the same tests as for the initvm
and native for the container-based build as well.

Detect whether the XML under test actually needs a rootful
container by checking xml_needs_rootful(). When it does not,
run the container rootless via --userns auto instead of
requiring elevated privileges, and only skip the test when a
rootful container is required and the tests are not run as root.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
Ubuntu 26.04 uses uutils coreutils by default, which installs chroot to
/usr/bin instead of /usr/sbin like GNU coreutils on Debian. The hardcoded
/usr/sbin/chroot then fails with FileNotFoundError, e.g. in the doctest
of shellhelper.chroot() in the GitHub CI.

Call chroot by name instead. In shellhelper.chroot() the PATH of the
target is used for the lookup, which contains both directories. For
'elbe chroot', add the sbin directories using get_env_with_sbin() like
it is done for other tools living in sbin.

Signed-off-by: Florian Kauer <florian.kauer@linutronix.de>
@koalo
koalo force-pushed the devel/koalo/container-nomknod branch from 1dacc79 to b786833 Compare November 24, 2026 07:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants