aboutsummaryrefslogtreecommitdiff
path: root/leg-cloud-image
diff options
context:
space:
mode:
authorFathi Boudra <fathi.boudra@linaro.org>2016-11-26 12:58:02 +0200
committerFathi Boudra <fathi.boudra@linaro.org>2016-11-26 11:33:37 +0000
commitbff59d78b8f23088c0eafccce747b677175c1918 (patch)
tree0c15522d52e8290b27a34523811775624c1f98b9 /leg-cloud-image
parent271461a4f945559250694373fd367c37b83abdd0 (diff)
downloadconfigs-bff59d78b8f23088c0eafccce747b677175c1918.tar.gz
leg-cloud-image: use qemu-nbd/kpartx to extract kernel/initramfs from image
virt-copy-out runs qemu and requires a kernel for supermin. It's a bit overkill for just extracting kernel/initramfs like in our use case. Mounting a local qcow2 image is also faster. Change-Id: I236b9800dd49f26893052b132e776441684da1c3 Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
Diffstat (limited to 'leg-cloud-image')
-rwxr-xr-xleg-cloud-image/centos/builders.sh17
-rwxr-xr-xleg-cloud-image/debian/builders.sh17
2 files changed, 26 insertions, 8 deletions
diff --git a/leg-cloud-image/centos/builders.sh b/leg-cloud-image/centos/builders.sh
index b4374a684..a2aa8164a 100755
--- a/leg-cloud-image/centos/builders.sh
+++ b/leg-cloud-image/centos/builders.sh
@@ -1,9 +1,10 @@
#!/bin/bash
export image_name=centos7-cloud-image
+export mountpoint=$(mktemp -d /tmp/${image_name}.XXXXXX)
sudo apt-get -q=2 update
-sudo apt-get -q=2 install -y --no-install-recommends qemu-utils virtinst libguestfs-tools libvirt-bin
+sudo apt-get -q=2 install -y --no-install-recommends qemu-utils virtinst libvirt-bin
default_gw=$(ip route show default 0.0.0.0/0 | cut -d' ' -f3)
sudo sed -i "/^uri_default/d" /etc/libvirt/libvirt.conf
@@ -24,6 +25,10 @@ cleanup_exit()
sudo virsh vol-delete --pool default ${image_name}.qcow2 || true
sudo virsh destroy ${image_name} || true
sudo virsh undefine ${image_name} || true
+ sudo umount ${mountpoint} || true
+ sudo kpartx -dv /dev/nbd0 || true
+ sudo qemu-nbd --disconnect /dev/nbd0 || true
+ sudo rm -rf ${mountpoint} || true
sudo rm -f ${image_name}.qcow2
}
@@ -54,9 +59,13 @@ mkdir out
mv centos7-aarch64.ks out/
# virsh vol-download is slow - copy from a mounted volume
sudo cp -a /var/lib/libvirt/images/${image_name}.qcow2 .
-sudo qemu-img convert -c -O qcow2 ${image_name}.qcow2 out/${image_name}.qcow2
# extract kernel and initramfs from image
# --unversioned-names may be handy to get vmlinuz/initrd.img names if needed
-sudo LIBGUESTFS_BACKEND=direct virt-copy-out -a ${image_name}.qcow2 /boot/ .
-sudo cp -a boot/*-reference.*.aarch64* out/
+sudo qemu-nbd --connect=/dev/nbd0 ${image_name}.qcow2
+for device in $(sudo kpartx -avs /dev/nbd0 | cut -d' ' -f3); do
+ partition=$(echo ${device} | cut -d'p' -f2)
+ [ "${partition}" = "2" ] && sudo mount /dev/mapper/${device} ${mountpoint}
+done
+cp -a ${mountpoint}/boot/*-reference.*.aarch64* out/
+sudo qemu-img convert -c -O qcow2 ${image_name}.qcow2 out/${image_name}.qcow2
sudo chown -R buildslave:buildslave out
diff --git a/leg-cloud-image/debian/builders.sh b/leg-cloud-image/debian/builders.sh
index 9efacd136..1d579de75 100755
--- a/leg-cloud-image/debian/builders.sh
+++ b/leg-cloud-image/debian/builders.sh
@@ -1,9 +1,10 @@
#!/bin/bash
export image_name=debian-cloud-image
+export mountpoint=$(mktemp -d /tmp/${image_name}.XXXXXX)
sudo apt-get -q=2 update
-sudo apt-get -q=2 install -y --no-install-recommends qemu-utils virtinst libguestfs-tools libvirt-bin
+sudo apt-get -q=2 install -y --no-install-recommends qemu-utils virtinst libvirt-bin
default_gw=$(ip route show default 0.0.0.0/0 | cut -d' ' -f3)
sudo sed -i "/^uri_default/d" /etc/libvirt/libvirt.conf
@@ -24,6 +25,10 @@ cleanup_exit()
sudo virsh vol-delete --pool default ${image_name}.qcow2 || true
sudo virsh destroy ${image_name} || true
sudo virsh undefine ${image_name} || true
+ sudo umount ${mountpoint} || true
+ sudo kpartx -dv /dev/nbd0 || true
+ sudo qemu-nbd --disconnect /dev/nbd0 || true
+ sudo rm -rf ${mountpoint} || true
sudo rm -f ${image_name}.qcow2
}
@@ -54,9 +59,13 @@ mkdir out
mv preseed.cfg out/debian-jessie-arm64-preseed.cfg
# virsh vol-download is slow - copy from a mounted volume
sudo cp -a /var/lib/libvirt/images/${image_name}.qcow2 .
-sudo qemu-img convert -c -O qcow2 ${image_name}.qcow2 out/${image_name}.qcow2
# extract kernel and initramfs from image
# --unversioned-names may be handy to get vmlinuz/initrd.img names if needed
-sudo LIBGUESTFS_BACKEND=direct virt-copy-out -a ${image_name}.qcow2 /boot/ .
-sudo cp -a boot/*-arm64 out/
+sudo qemu-nbd --connect=/dev/nbd0 ${image_name}.qcow2
+for device in $(sudo kpartx -avs /dev/nbd0 | cut -d' ' -f3); do
+ partition=$(echo ${device} | cut -d'p' -f2)
+ [ "${partition}" = "2" ] && sudo mount /dev/mapper/${device} ${mountpoint}
+done
+cp -a ${mountpoint}/boot/*-arm64 out/
+sudo qemu-img convert -c -O qcow2 ${image_name}.qcow2 out/${image_name}.qcow2
sudo chown -R buildslave:buildslave out