Skip to content

bwrap: Fall back to direct invocation on namespace creation failure#2209

Closed
cdellacqua wants to merge 1 commit into
bootc-dev:mainfrom
cdellacqua:bwrap-fallback
Closed

bwrap: Fall back to direct invocation on namespace creation failure#2209
cdellacqua wants to merge 1 commit into
bootc-dev:mainfrom
cdellacqua:bwrap-fallback

Conversation

@cdellacqua
Copy link
Copy Markdown
Contributor

Under QEMU user-mode emulation the host kernel can return EINVAL from clone(CLONE_NEWUSER) on bwrap's sandbox setup, and bwrap aborts before spawning the child. This trips bootc install on cross-architecture builds (see issue #2111), where bwrap is used to make bootupctl run from the target image, not the buildroot.

Workaround until the upstream qemu-user/kernel/bwrap interaction is resolved: detect the "Creating new namespace failed" prefix on bwrap's stderr and re-run the target program directly. A eprintln! fires on every fallback so the behaviour is visible in logs. Both bootupctl sites in bootloader opt in: the --filesystem capability probe and backend install.

Assisted-by: Claude Code (Opus 4.7 1M)

@bootc-bot bootc-bot Bot requested a review from cgwalters May 22, 2026 15:24
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a fallback mechanism for bwrap commands to handle cases where namespace creation fails, such as under QEMU user-mode emulation. It introduces BwrapCmdWithFallback, which monitors stderr for a specific error marker and transparently executes a direct fallback command if necessary. Review feedback suggests optimizing the error detection logic by performing a byte-level search on stderr to avoid unnecessary string allocations and improving code clarity by binding the stderr handle to a local variable.

Comment thread crates/utils/src/bwrap.rs Outdated
Comment thread crates/utils/src/bwrap.rs Outdated
Under QEMU user-mode emulation the host kernel can return EINVAL
from clone(CLONE_NEWUSER) on bwrap's sandbox setup, and bwrap
aborts before spawning the child. This trips bootc install on
cross-architecture builds (see issue bootc-dev#2111), where bwrap is
used to make bootupctl run from the target image, not the
buildroot.

Workaround until the upstream qemu-user/kernel/bwrap interaction
is resolved: detect the "Creating new namespace failed" prefix on
bwrap's stderr and re-run the target program directly. A
`eprintln!` fires on every fallback so the behaviour is
visible in logs. Both bootupctl sites in bootloader opt in: the
`--filesystem` capability probe and `backend install`.

Assisted-by: Claude Code (Opus 4.7 1M)
Signed-off-by: cdellacqua <carlo.dellacqua97@gmail.com>
@cgwalters
Copy link
Copy Markdown
Collaborator

I get the pain here, but it's not viable in the general case.

What we can do here is special case just when bootc install to-filesystem is being run from a container (i.e. the source root == target) and then we know direct invocation == container.

However, another fallback path that would likely be quite viable here is to just do a "simple container" where we just set up some mount points directly and chroot. In bash it's something like this https://gitlab.com/fedora/bootc/base-images-experimental/-/blob/main/build/dnf-installroot

@cdellacqua
Copy link
Copy Markdown
Contributor Author

Thanks! Implemented the chroot approach in #2210 and confirmed it fixes the original qemu-user case on real hardware (building a bootc image for an aarch64 Raspberry Pi 4 from an amd64 laptop).

Closing as superseded.

@cdellacqua cdellacqua closed this May 23, 2026
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