BuildRoot: don't use nspawn's --volatile mode
We want the same functionality, but we now impleent it ourselves. In addition to bind-mounting in /usr into the target container (which is all nspawn does), we also add /bin, /sbin, /lib and /lib64, if they exist and are not symlinks (presuambly into /usr). This means we can work on distros who have not implemented the usr-move, like Ubuntu Bionic (used by Travis). Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
52e2374bb6
commit
659ce42c83
1 changed files with 21 additions and 14 deletions
|
|
@ -73,21 +73,28 @@ class BuildRoot:
|
||||||
def __init__(self, path="/run/osbuild"):
|
def __init__(self, path="/run/osbuild"):
|
||||||
self.root = tempfile.mkdtemp(prefix="osbuild-buildroot-", dir=path)
|
self.root = tempfile.mkdtemp(prefix="osbuild-buildroot-", dir=path)
|
||||||
self.api = tempfile.mkdtemp(prefix="osbuild-api-", dir=path)
|
self.api = tempfile.mkdtemp(prefix="osbuild-api-", dir=path)
|
||||||
self.mounted = False
|
self.mounts = []
|
||||||
try:
|
for p in ["usr", "bin", "sbin", "lib", "lib64"]:
|
||||||
subprocess.run(["mount", "-o", "bind,ro", "/", self.root], check=True)
|
source = os.path.join("/", p)
|
||||||
self.mounted = True
|
target = os.path.join(self.root, p)
|
||||||
except subprocess.CalledProcessError:
|
if not os.path.isdir(source) or os.path.islink(source):
|
||||||
self.unmount()
|
continue # only bind-mount real dirs
|
||||||
raise
|
os.mkdir(target)
|
||||||
|
try:
|
||||||
|
subprocess.run(["mount", "-o", "bind,ro", source, target], check=True)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
self.unmount()
|
||||||
|
raise
|
||||||
|
self.mounts.append(target)
|
||||||
|
|
||||||
def unmount(self):
|
def unmount(self):
|
||||||
if not self.root:
|
for path in self.mounts:
|
||||||
return
|
subprocess.run(["umount", "--lazy", path], check=True)
|
||||||
if self.mounted:
|
os.rmdir(path)
|
||||||
subprocess.run(["umount", "--lazy", self.root], check=True)
|
self.mounts = []
|
||||||
os.rmdir(self.root)
|
if self.root:
|
||||||
self.root = None
|
shutil.rmtree(self.root)
|
||||||
|
self.root = None
|
||||||
if self.api:
|
if self.api:
|
||||||
shutil.rmtree(self.api)
|
shutil.rmtree(self.api)
|
||||||
self.api = None
|
self.api = None
|
||||||
|
|
@ -97,13 +104,13 @@ class BuildRoot:
|
||||||
|
|
||||||
Its arguments mean the same as those for subprocess.run().
|
Its arguments mean the same as those for subprocess.run().
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return subprocess.run([
|
return subprocess.run([
|
||||||
"systemd-nspawn",
|
"systemd-nspawn",
|
||||||
"--quiet",
|
"--quiet",
|
||||||
"--register=no",
|
"--register=no",
|
||||||
"--as-pid2",
|
"--as-pid2",
|
||||||
"--link-journal=no",
|
"--link-journal=no",
|
||||||
"--volatile=yes",
|
|
||||||
"--property=DeviceAllow=block-loop rw",
|
"--property=DeviceAllow=block-loop rw",
|
||||||
f"--directory={self.root}",
|
f"--directory={self.root}",
|
||||||
*[f"--bind={b}" for b in (binds or [])],
|
*[f"--bind={b}" for b in (binds or [])],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue