linuxkit/tools/mkimage-dynamic-vhd/make-dynamic-vhd
Rolf Neugebauer c582907b19 tools: Fix guestfs invocation (vmdk and dynamic-vhd)
Looks like bc791e60e7 ("Update docs and test cases to work with
latest format versions") accidentally replaced 'qcow2' with
'qcow2-bios' for two of the output formats. Fix it.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
2018-01-25 19:40:27 +00:00

60 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
set -e
mkdir -p /tmp/image
cd /tmp/image
# input is a tarball of kernel and initrd.img on stdin
# output is a vmdk on stdout
mkdir -p files
cd files
# extract. As guestfs base is currently Debian, no compression support
# only if stdin is a tty, if so need files volume mounted...
[ -t 0 ] || tar xf -
INITRD="$(find . -name '*.img')"
KERNEL="$(find . -name kernel -or -name '*bzImage')"
CMDLINE="$*"
[ "$KERNEL" = "./kernel" ] || mv "$KERNEL" vmlinuz64
[ "$INITRD" = "./initrd.img" ] || mv "$INITRD" initrd.img
# clean up subdirectories
find . -mindepth 1 -maxdepth 1 -type d | xargs rm -rf
CFG="DEFAULT linux
LABEL linux
KERNEL /kernel
INITRD /initrd.img
APPEND ${CMDLINE}
"
printf "$CFG" > syslinux.cfg
cd ..
tar cf files.tar -C files .
# Disk is created in qcow format.
virt-make-fs --size=25G --type=ext4 --partition files.tar --format=qcow2 disk.qcow
guestfish -a disk.qcow -m /dev/sda1 <<EOF
upload /usr/lib/SYSLINUX/mbr.bin /mbr.bin
copy-file-to-device /mbr.bin /dev/sda size:440
rm /mbr.bin
extlinux /
part-set-bootable /dev/sda 1 true
EOF
# Can't convert directly to VHD, as it's not supported by qemu-img. First, compress qcow image to vmdk format.
qemu-img convert -f qcow2 -O vmdk -o adapter_type=lsilogic,subformat=streamOptimized,compat6 -c disk.qcow disk.vmdk 1>&2
# Then create dynamic VHD
qemu-img convert -f vmdk -O vpc -o subformat=dynamic disk.vmdk disk.vhd 1>&2
cat disk.vhd