Add VHD and GCE output formats

- VHD is uncompressed VHD. Currently hard coded at 1GB, which may need to change. Use `format: vhd`
- GCE is the GCE compressed tarred raw image. Use `format: gce-img` - reserving `gce` for actually
  uploading the image.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack
2017-03-10 15:05:28 +00:00
parent c7d1438128
commit 718d45bdf5
8 changed files with 135 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
FROM mobylinux/guestfs:8719f0f33b3cf9d59a62be64a42220978ac96486@sha256:c7229f01c1a54270d2bc3597c30121628c18db211ed32fb7202823b6eaa4f853
FROM mobylinux/guestfs:69698aca5bfcb8c4d3a3bbe6d8656be155bf8cd6@sha256:703a7372ada5b3db64a11bc8c60eec06659a1052d9296fa0c556ed3faf75c182
COPY . .
CMD [ "/make-gce" ]
ENTRYPOINT [ "/make-gce" ]

View File

@@ -6,7 +6,7 @@ default: push
hash: Dockerfile make-gce
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --rm $(IMAGE):build sh -c "(cat $^; apt list --installed 2>/dev/null) | sha1sum" | sed 's/ .*//' > hash
docker run --entrypoint sh --rm $(IMAGE):build -c "(cat $^; apt list --installed 2>/dev/null) | sha1sum" | sed 's/ .*//' > hash
push: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \

View File

@@ -18,6 +18,7 @@ cd files
INITRD="$(find . -name '*.img')"
KERNEL="$(find . -name vmlinuz64 -or -name bzImage)"
CMDLINE="$*"
[ "$KERNEL" = "./vmlinuz64" ] || mv "$KERNEL" vmlinuz64
[ "$INITRD" = "./initrd.img" ] || mv "$INITRD" initrd.img
@@ -32,7 +33,7 @@ CFG="DEFAULT linux
LABEL linux
KERNEL /vmlinuz64
INITRD /initrd.img
APPEND $GCE_CONFIG $*
APPEND ${CMDLINE}
"
printf "$CFG" > syslinux.cfg

View File

@@ -0,0 +1,5 @@
FROM mobylinux/guestfs:69698aca5bfcb8c4d3a3bbe6d8656be155bf8cd6@sha256:703a7372ada5b3db64a11bc8c60eec06659a1052d9296fa0c556ed3faf75c182
COPY . .
ENTRYPOINT [ "/make-vhd" ]

View File

@@ -0,0 +1,27 @@
.PHONY: tag push
IMAGE=mkimage-vhd
default: push
hash: Dockerfile make-vhd
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --entrypoint sh --rm $(IMAGE):build -c "(cat $^; apt list --installed 2>/dev/null) | sha1sum" | sed 's/ .*//' > hash
push: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
(docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash) && \
docker push mobylinux/$(IMAGE):$(shell cat hash))
docker rmi $(IMAGE):build
rm -f hash
tag: hash
docker pull mobylinux/$(IMAGE):$(shell cat hash) || \
docker tag $(IMAGE):build mobylinux/$(IMAGE):$(shell cat hash)
docker rmi $(IMAGE):build
rm -f hash
clean:
rm -f hash
.DELETE_ON_ERROR:

55
tools/mkimage-vhd/make-vhd Executable file
View File

@@ -0,0 +1,55 @@
#!/bin/sh
set -e
mkdir -p /tmp/image
cd /tmp/image
# input is a tarball of vmlinuz64 and initrd.img on stdin
# output is a vhd 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 vmlinuz64 -or -name '*bzImage')"
CMDLINE="$*"
[ "$KERNEL" = "./vmlinuz64" ] || 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 /vmlinuz64
INITRD /initrd.img
APPEND ${CMDLINE}
"
printf "$CFG" > syslinux.cfg
cd ..
tar cf files.tar -C files .
# no direct vhd support
virt-make-fs --size=1G --type=ext4 --partition files.tar disk.img
guestfish -a disk.img -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
qemu-img convert -f raw -O vpc -o subformat=fixed,force_size disk.img disk.vhd 1>&2
cat disk.vhd