Skip to content

Commit

Permalink
stages(dracut): mount dracut required filesystems.
Browse files Browse the repository at this point in the history
mount dracut required filesystems to avoid errors like:
"/proc/ is not mounted. This is not a supported mode
of operation. Please fix your invocation environment to
mount /proc/ and /sys/ properly. Proceeding anyway."

Signed-off-by: Miguel Martín <mmartinv@redhat.com>
  • Loading branch information
mmartinv committed Dec 5, 2023
1 parent eb02d8e commit d39cb2a
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions stages/org.osbuild.dracut
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ page and schema for this stage.
NB: needs chroot for now as well as `strip` for stripping the initrfams.
"""

import os
import subprocess
import sys

import osbuild.api
from osbuild.util.mnt import MountGuard

SCHEMA = """
"required": ["kernel"],
Expand Down Expand Up @@ -201,15 +203,35 @@ def main(tree, options):

opts += extra

for kver in kernels:
print(f"Building initramfs for {kver}", file=sys.stderr)

subprocess.run(["/usr/sbin/chroot", tree,
"/usr/bin/dracut",
"--no-hostonly",
"--kver", kver]
+ opts,
check=True)
mounts = [
{"path": "/dev", "bind": True, "ro": False, "mode": 0o755},
{"path": "/proc", "bind": True, "ro": True, "mode": 0o555},
{"path": "/sys", "bind": True, "ro": True, "mode": 0o555},
]
with MountGuard() as mounter:
for mount in mounts:
ro = mount["ro"]
bind = mount["bind"]
src = mount["path"]
mode = mount["mode"]
dest = os.path.join(tree, src.lstrip("/"))
os.makedirs(dest, exist_ok=True)
os.chmod(dest, mount.get("mode", mode))
mounter.mount(src, dest, bind=bind, ro=ro)

os.symlink("/proc/self/fd", f"{tree}/dev/fd")

for kver in kernels:
print(f"Building initramfs for {kver}", file=sys.stderr)

subprocess.run(["/usr/sbin/chroot", tree,
"/usr/bin/dracut",
"--no-hostonly",
"--kver", kver]
+ opts,
check=True)

os.unlink(f"{tree}/dev/fd")

return 0

Expand Down

0 comments on commit d39cb2a

Please sign in to comment.