aboutsummaryrefslogtreecommitdiffstats
path: root/patches/opnfv-fuel/0015-base-image-Explicitly-call-kpartx.patch
blob: 5e567c0f160110aec4a47f5e674a6b1d930a8bd2 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Copyright (c) 2017 Enea AB 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: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Date: Tue, 28 Nov 2017 00:22:45 +0100
Subject: [PATCH] base image: Explicitly call kpartx

qemu-nbd currently available in CentOS 7 does not add partition
mappings automatically for NBD devices, so add explicit `kpartx`
calls.

On rare occassions, mapper bindings created by kpartx take longer
to show up, leading to errors when we try to mount them on.
Bring back the hardcoded delay to bypass such issues.

Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
---
 ci/deploy.sh       | 4 ++--
 mcp/scripts/lib.sh | 9 +++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/ci/deploy.sh b/ci/deploy.sh
index 92319ad..5bd163e 100755
--- a/ci/deploy.sh
+++ b/ci/deploy.sh
@@ -272,10 +272,10 @@ pushd "${DEPLOY_DIR}" > /dev/null
 # Install required packages
 [ -n "$(command -v apt-get)" ] && sudo apt-get install -y \
   git make rsync mkisofs curl virtinst cpu-checker qemu-kvm uuid-runtime \
-  libvirt-bin cloud-guest-utils e2fsprogs
+  libvirt-bin cloud-guest-utils e2fsprogs kpartx
 [ -n "$(command -v yum)" ] && sudo yum install -y --skip-broken \
   git make rsync genisoimage curl virt-install qemu-kvm util-linux \
-  libvirt cloud-utils-growpart e2fsprogs
+  libvirt cloud-utils-growpart e2fsprogs kpartx

 # For baremetal, python is indirectly required for PDF parsing
 if [ "${DEPLOY_TYPE}" = 'baremetal' ]; then
diff --git a/mcp/scripts/lib.sh b/mcp/scripts/lib.sh
index 5a69609..754d4f0 100644
--- a/mcp/scripts/lib.sh
+++ b/mcp/scripts/lib.sh
@@ -49,18 +49,22 @@ function mount_image {
     fi
   done
   OPNFV_LOOP_DEV=$(losetup -f)
+  OPNFV_MAP_DEV=/dev/mapper/$(basename "${OPNFV_NBD_DEV}")p1
   export OPNFV_MNT_DIR OPNFV_LOOP_DEV
   [ -n "${OPNFV_NBD_DEV}" ] && [ -n "${OPNFV_LOOP_DEV}" ] || exit 1
   qemu-img resize "${image_dir}/${image}" 3G
   sudo qemu-nbd --connect="${OPNFV_NBD_DEV}" --aio=native --cache=none \
     "${image_dir}/${image}"
+  sudo kpartx -av "${OPNFV_NBD_DEV}"
   sleep 5 # /dev/nbdNp1 takes some time to come up
   # Hardcode partition index to 1, unlikely to change for Ubuntu UCA image
   if sudo growpart "${OPNFV_NBD_DEV}" 1; then
-    sudo e2fsck -yf "${OPNFV_NBD_DEV}p1" && sudo resize2fs "${OPNFV_NBD_DEV}p1"
+    sudo kpartx -u "${OPNFV_NBD_DEV}"
+    sudo e2fsck -yf "${OPNFV_MAP_DEV}"
+    sudo resize2fs "${OPNFV_MAP_DEV}"
   fi
   # grub-update does not like /dev/nbd*, so use a loop device to work around it
-  sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_NBD_DEV}p1"
+  sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_MAP_DEV}"
   mkdir -p "${OPNFV_MNT_DIR}"
   sudo mount "${OPNFV_LOOP_DEV}" "${OPNFV_MNT_DIR}"
   sudo mount -t proc proc "${OPNFV_MNT_DIR}/proc"
@@ -141,6 +145,7 @@ function cleanup_mounts {
       sudo losetup -d "${OPNFV_LOOP_DEV}"
   fi
   if [ -n "${OPNFV_NBD_DEV}" ]; then
+    sudo kpartx -d "${OPNFV_NBD_DEV}" || true
     sudo qemu-nbd -d "${OPNFV_NBD_DEV}" || true
   fi
 }