[lib] nbd: Explicitly map partitions 83/67283/2
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Mon, 18 Mar 2019 15:11:50 +0000 (16:11 +0100)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Mon, 18 Mar 2019 15:44:52 +0000 (16:44 +0100)
Certain kernels (e.g. 4.4.0-101+ in Ubuntu) no longer automatically
ack the partition table update after `kpartx -a /dev/nbdX`, see [1].

To avoid another dependency on `parted` packages, use `partx` from
`util-linux`, which is already installed as a dependency of e2fsprogs.

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1743026

Change-Id: Ibd993fe210c1a11814e89a66759568d4d117d613
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
mcp/scripts/lib_jump_deploy.sh

index 5efbfa6..ade1a74 100644 (file)
@@ -121,13 +121,16 @@ function __mount_image {
   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
+  sudo partx -uvn 1:1 "${OPNFV_NBD_DEV}"
   if sudo growpart "${OPNFV_NBD_DEV}" 1; then
     sudo kpartx -u "${OPNFV_NBD_DEV}"
     sudo e2fsck -pf "${OPNFV_MAP_DEV}"
     sudo resize2fs "${OPNFV_MAP_DEV}"
+  else
+    sleep 5 # /dev/nbdNp1 takes some time to come up
   fi
+  sudo partx -d "${OPNFV_NBD_DEV}"
   # grub-update does not like /dev/nbd*, so use a loop device to work around it
   sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_MAP_DEV}"
   mkdir -p "${OPNFV_MNT_DIR}"
@@ -497,6 +500,7 @@ function cleanup_mounts {
       sudo losetup -d "${OPNFV_LOOP_DEV}"
   fi
   if [ -n "${OPNFV_NBD_DEV}" ]; then
+    sudo partx -d "${OPNFV_NBD_DEV}" || true
     sudo kpartx -d "${OPNFV_NBD_DEV}" || true
     sudo qemu-nbd -d "${OPNFV_NBD_DEV}" || true
   fi