base image: Explicitly call kpartx 47/47947/1
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Mon, 27 Nov 2017 23:22:45 +0000 (00:22 +0100)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Tue, 28 Nov 2017 00:07:26 +0000 (01:07 +0100)
qemu-nbd currently available in CentOS 7 does not add partition
mappings automatically for NBD devices, so add explicit `kpartx`
calls.

Change-Id: Ifa79c89b82024602b782c449dbf4de10899e03b5
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
ci/deploy.sh
mcp/scripts/lib.sh

index e2e4a1c..ec8e4f5 100755 (executable)
@@ -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
index 8dd92e1..96f1891 100644 (file)
@@ -49,18 +49,21 @@ 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}"
-  sleep 5 # /dev/nbdNp1 takes some time to come up
+  sudo kpartx -av "${OPNFV_NBD_DEV}"
   # 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 +144,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
 }