1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
2 Date: Sun, 6 Mar 2016 16:09:39 +0100
3 Subject: [PATCH] Fix qemu-user-static replacement
6 fuel_agent/manager.py | 6 ++++++
7 fuel_agent/utils/build.py | 18 ++++++++++++++++++
8 2 files changed, 24 insertions(+)
10 diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py
11 index f613aef..6322a10 100644
12 --- a/fuel_agent/manager.py
13 +++ b/fuel_agent/manager.py
14 @@ -587,6 +587,12 @@ class Manager(object):
15 fu.mount_bind(chroot, '/proc')
16 bu.populate_basic_dev(chroot)
18 + # we need to make sure that qemu-{target_arch}-static binary is
19 + # not replaced inside chroot because we're possibly using it
20 + # through qemu-debootstrap
21 + LOG.debug('Preventing qemu-user-static replacement inside chroot')
22 + bu.prevent_qemu_replacement(chroot, CONF.target_arch)
24 def destroy_chroot(self, chroot):
25 # Umount chroot tree and remove images tmp files
26 if not bu.stop_chrooted_processes(chroot, signal=signal.SIGTERM):
27 diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py
28 index 6f31732..abd762e 100644
29 --- a/fuel_agent/utils/build.py
30 +++ b/fuel_agent/utils/build.py
31 @@ -312,6 +312,24 @@ def populate_basic_dev(chroot):
32 utils.execute('chroot', chroot,
33 'ln', '-s', '/proc/self/fd', '/dev/fd')
35 +def prevent_qemu_replacement(chroot, arch):
36 + """Prevents qemu-user-static replacement inside chroot.
38 + Use dpkg-divert to prevent replacing qemu-user-static binary inside
39 + chroot which is necessary for host-side qemu-debootstrap to work
42 + qemu = 'qemu-aarch64-static'
43 + elif arch == 'amd64':
44 + qemu = 'qemu-x86_64-static'
45 + utils.execute('chroot', chroot,
46 + 'dpkg-divert', '--divert', '/usr/bin/%s.orig' % qemu,
47 + '/usr/bin/%s' % qemu)
48 + utils.execute('chroot', chroot,
49 + 'dpkg-divert', '--divert', '/usr/sbin/update-binfmts.orig',
50 + '--rename', '/usr/sbin/update-binfmts')
51 + utils.execute('chroot', chroot, 'ln', '-sf', '/bin/true',
52 + '/usr/sbin/update-binfmts')
54 def create_sparse_tmp_file(dir, suffix, size=8192):
55 """Creates sparse file.