Updated armband
[armband.git] / patches / opnfv-fuel / 0031-post-scripts-Enable-systemd-binfmt-for-first-boot.patch
1 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
2 Date: Thu, 9 Jun 2016 19:46:56 +0200
3 Subject: [PATCH] post-scripts: Enable systemd-binfmt for first boot.
4
5 IMPORTANT:
6 This commit introduces the following file on Fuel Master,
7 containing the list of arch supported for target nodes:
8 </etc/fuel_openstack_arch>.
9
10 This file is created AFTER pre.d OPNFV scripts are ran, also by
11 bootstrap_admin_node.sh, BEFORE the post.d scripts are executed.
12 NOTE: Arch format is the same used by dpkg (e.g.: "amd64 arm64")
13
14 Based on the number of foreign architectures we should support
15 (the list of archs in /etc/fuel_openstack_arch minus native arch),
16 we determine whether cross-builds are expected, in which case
17 binfmt support should be functional during first Fuel Master boot.
18
19 Since systemd-binfmt service has a series of preconditions for
20 starting, which are tested early during first boot, some of them
21 are NOT YET true (e.g. no binfmt handlers are present before
22 qemu-user-static package is installed), so the service is not
23 automatically started. Of course, this only affects the first boot.
24
25 Finally, this commit adds an OPNFV post-install script in
26 /opt/opnfv/bootstrap/post.d, which starts systemd-binfmt service.
27 ---
28  build/bootstrap_admin_node.sh.patch                | 15 ++++++++++
29  .../post-scripts/80_prepare_cross_builds.sh        | 32 ++++++++++++++++++++++
30  2 files changed, 47 insertions(+)
31  create mode 100755 build/f_isoroot/f_bootstrap/post-scripts/80_prepare_cross_builds.sh
32
33 diff --git a/build/bootstrap_admin_node.sh.patch b/build/bootstrap_admin_node.sh.patch
34 index b1ea90b..7f16d0b 100644
35 --- a/build/bootstrap_admin_node.sh.patch
36 +++ b/build/bootstrap_admin_node.sh.patch
37 @@ -24,5 +24,18 @@
38   nodes over PXE, they will be discovered and become available for installing \
39   OpenStack on them"
40 +@@ -239,6 +239,12 @@
41 + # /etc/fuel_openstack_version is provided by 'fuel-openstack-metadata' package
42 + OPENSTACK_VERSION=$(cat /etc/fuel_openstack_version)
43 +
44 ++# FIXME(armband): This part might be moved to an earlier stage later
45 ++# /etc/fuel_openstack_arch is constructed based on local mirror metadata
46 ++grep -oP "^Architectures: \K.*$" \
47 ++    ${wwwdir}/${OPENSTACK_VERSION}/ubuntu/x86_64/dists/mos${FUEL_RELEASE}/Release > \
48 ++    /etc/fuel_openstack_arch
49 ++
50 + # We do not ship debian-installer kernel and initrd on ISO.
51 + # But we still need to be able to create ubuntu cobbler distro
52 + # which requires kernel and initrd to be available. So, we
53  @@ -339,8 +339,22 @@ fuelmenu --save-only --iface=$ADMIN_INTERFACE || fail
54   set +x
55   echo "Done!"
56 diff --git a/build/f_isoroot/f_bootstrap/post-scripts/80_prepare_cross_builds.sh b/build/f_isoroot/f_bootstrap/post-scripts/80_prepare_cross_builds.sh
57 new file mode 100755
58 index 0000000..d33d1d1
59 --- /dev/null
60 +++ b/build/f_isoroot/f_bootstrap/post-scripts/80_prepare_cross_builds.sh
61 @@ -0,0 +1,32 @@
62 +#/bin/sh
63 +##############################################################################
64 +# Copyright (c) 2016 Enea AB and others.
65 +# Alexandru.Avadanii@enea.com
66 +# All rights reserved. This program and the accompanying materials
67 +# are made available under the terms of the Apache License, Version 2.0
68 +# which accompanies this distribution, and is available at
69 +# http://www.apache.org/licenses/LICENSE-2.0
70 +##############################################################################
71 +
72 +echo "Preparing for cross-building bootstrap/target images"
73 +
74 +# Fmt handlers are set up by qemu-user-static (after systemd-binfmt
75 +# prerequisites are checked during first boot of Fuel Master node).
76 +
77 +# Cross-building support provides dpkg, as a fuel-agent dependency
78 +if which dpkg > /dev/null 2>&1; then
79 +  # /etc/fuel_openstack_arch is created by bootstrap_admin_node.sh
80 +  FOREIGN_ARCH_CNT=$(sed -e "s/$(dpkg --print-architecture)//" \
81 +    /etc/fuel_openstack_arch | wc -w)
82 +  if [ ${FOREIGN_ARCH_CNT} -gt 0 ]; then
83 +    # If no fmt handlers are configured, the service is not started,
84 +    # so request it explicitly (only necessary for the first boot).
85 +    systemctl start systemd-binfmt
86 +    if [ $? -ne 0 ]; then
87 +      echo "Error starting systemd-binfmt!"
88 +      exit 1
89 +    fi
90 +  fi
91 +fi
92 +
93 +echo "Done preparing cross-building"