pmb.chroot.init: mount --bind qemu-user binary (!1861)

Avoid copying the qemu-user binary to each chroot by using a bind mount.
This ensures that we remove it when we shutdown the chroot.
This commit is contained in:
Minecrell 2020-01-20 13:38:50 +01:00 committed by Oliver Smith
parent 81d9bfe3ba
commit d0376ee0fb
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 16 additions and 15 deletions

View File

@ -45,16 +45,29 @@ def copy_resolv_conf(args, suffix="native"):
pmb.helpers.run.root(args, ["touch", chroot])
def setup_qemu_emulation(args, suffix):
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
if not pmb.parse.arch.cpu_emulation_required(args, arch):
return
chroot = args.work + "/chroot_" + suffix
arch_qemu = pmb.parse.arch.alpine_to_qemu(arch)
# mount --bind the qemu-user binary
pmb.chroot.binfmt.register(args, arch)
pmb.helpers.mount.bind_file(args, args.work + "/chroot_native/usr/bin/qemu-" + arch_qemu,
chroot + "/usr/bin/qemu-" + arch_qemu + "-static",
create_folders=True)
def init(args, suffix="native"):
# When already initialized: just prepare the chroot
chroot = args.work + "/chroot_" + suffix
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
emulate = pmb.parse.arch.cpu_emulation_required(args, arch)
pmb.chroot.mount(args, suffix)
setup_qemu_emulation(args, suffix)
if os.path.islink(chroot + "/bin/sh"):
if emulate:
pmb.chroot.binfmt.register(args, arch)
copy_resolv_conf(args, suffix)
pmb.chroot.apk.update_repository_list(args, suffix)
return
@ -62,10 +75,6 @@ def init(args, suffix="native"):
# Require apk-tools-static
pmb.chroot.apk_static.init(args)
# Non-native chroot: set up QEMU with binfmt_misc
if emulate:
pmb.chroot.binfmt.register(args, arch)
logging.info("(" + suffix + ") install alpine-base")
# Initialize cache
@ -80,14 +89,6 @@ def init(args, suffix="native"):
copy_resolv_conf(args, suffix)
pmb.chroot.apk.update_repository_list(args, suffix)
# Non-native chroot: install qemu-user-binary
if emulate:
arch_qemu = pmb.parse.arch.alpine_to_qemu(arch)
pmb.helpers.run.root(args, ["mkdir", "-p", chroot + "/usr/bin"])
pmb.helpers.run.root(args, ["cp", args.work +
"/chroot_native/usr/bin/qemu-" + arch_qemu,
chroot + "/usr/bin/qemu-" + arch_qemu + "-static"])
# Install alpine-base
pmb.helpers.repo.update(args, arch)
pmb.chroot.apk_static.run(args, ["--no-progress", "--root", chroot,