mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2026-01-05 14:31:41 +00:00
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:
@@ -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'):
|
||||
|
||||
Reference in New Issue
Block a user