summaryrefslogtreecommitdiffstats
path: root/patches/fuel-agent/cross-bootstrap/0003-Fix-qemu-user-static-replacement.patch
blob: dd406c6b22913dab4016d9cc0ece3435015414d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Copyright (c) 2017 Enea AB, Cavium and others.
:
: All rights reserved. This program and the accompanying materials
: are made available under the terms of the Apache License, Version 2.0
: which accompanies this distribution, and is available at
: http://www.apache.org/licenses/LICENSE-2.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
From: Stanislaw Kardach <stanislaw.kardach@cavium.com>
Date: Sun, 6 Mar 2016 16:09:39 +0100
Subject: [PATCH] Fix qemu-user-static replacement

---
 fuel_agent/manager.py     |  6 ++++++
 fuel_agent/utils/build.py | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/fuel_agent/manager.py b/fuel_agent/manager.py
index ba1ab78..637c99a 100644
--- a/fuel_agent/manager.py
+++ b/fuel_agent/manager.py
@@ -760,6 +760,12 @@ class Manager(object):
         fu.mount_bind(chroot, '/proc')
         bu.populate_basic_dev(chroot)

+        # we need to make sure that qemu-{target_arch}-static binary is
+        # not replaced inside chroot because we're possibly using it
+        # through qemu-debootstrap
+        LOG.debug('Preventing qemu-user-static replacement inside chroot')
+        bu.prevent_qemu_replacement(chroot, CONF.target_arch)
+
     def destroy_chroot(self, chroot):
         # Umount chroot tree and remove images tmp files
         if not bu.stop_chrooted_processes(chroot, signal=signal.SIGTERM):
diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py
index 74cbfd8..1bc0a5f 100644
--- a/fuel_agent/utils/build.py
+++ b/fuel_agent/utils/build.py
@@ -320,6 +320,24 @@ def populate_basic_dev(chroot):
     utils.execute('chroot', chroot,
                   'ln', '-s', '/proc/self/fd', '/dev/fd')

+def prevent_qemu_replacement(chroot, arch):
+    """Prevents qemu-user-static replacement inside chroot.
+
+    Use dpkg-divert to prevent replacing qemu-user-static binary inside
+    chroot which is necessary for host-side qemu-debootstrap to work
+    properly."""
+    if arch == 'arm64':
+        qemu = 'qemu-aarch64-static'
+    elif arch == 'amd64':
+        qemu = 'qemu-x86_64-static'
+    utils.execute('chroot', chroot,
+                  'dpkg-divert', '--divert', '/usr/bin/%s.orig' % qemu,
+                  '/usr/bin/%s' % qemu)
+    utils.execute('chroot', chroot,
+                  'dpkg-divert', '--divert', '/usr/sbin/update-binfmts.orig',
+                  '--rename', '/usr/sbin/update-binfmts')
+    utils.execute('chroot', chroot, 'ln', '-sf', '/bin/true',
+                  '/usr/sbin/update-binfmts')

 def create_sparse_tmp_file(dir, suffix, size=8192):
     """Creates sparse file.