onlrfs: use pivot_root instead of chroot when configuring packages

some packages need to see root filesystem mount point which isn't
visible in chroot env

Signed-off-by: Wataru Ishida <ishida@nel-america.com>
This commit is contained in:
Wataru Ishida
2019-08-30 11:08:12 -07:00
parent e9b01aa03e
commit 7ca1546162

View File

@@ -34,6 +34,30 @@ def onlu_execute_sudo(*args, **kwargs):
kwargs['sudo'] = True
return onlu.execute(*args, **kwargs)
def onlu_execute_pivot_root(pivot, cmd, **kwargs):
script = "/tmp/pivot_root.sh"
with open(script, "w") as f:
os.chmod(script, 0700)
f.write("""#!/bin/bash -eux
rm -rf /tmp/newroot && mkdir /tmp/newroot
rm -rf $1/oldroot && mkdir $1/oldroot
mount --bind $1 /tmp/newroot
cd /tmp/newroot
pivot_root . oldroot
hash -r # clear cache of commands
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
$2
""")
ret = onlu_execute_sudo('unshare -pfm {} {} {}'.format(script, pivot, cmd), **kwargs)
os.unlink(script)
return ret
class OnlRfsError(Exception):
"""General Error Exception"""
def __init__(self, value):
@@ -426,13 +450,12 @@ rm -f /usr/sbin/policy-rc.d
""")
logger.info("dpkg-configure filesystem...")
onlu_execute_pivot_root(dir_, '/tmp/configure.sh',
ex=OnlRfsError("Post Configuration failed."))
onlu_execute_sudo("unshare -pf --mount-proc chroot %s /tmp/configure.sh" % dir_,
ex=OnlRfsError("Post Configuration failed."))
os.unlink(script)
def configure(self, dir_):
if not os.getenv('NO_DPKG_CONFIGURE'):