Files
linuxkit/tools/mkimage-gce/make-gce
Riyaz Faizullabhoy 0c545c0c53 Split base/ into base/ and tools/
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
2017-01-31 09:52:30 -08:00

55 lines
1.2 KiB
Bash
Executable File

#!/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 compressed tarball of a raw disk image 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)"
[ "$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
# should be externally provided as GCE specific
GCE_CONFIG="earlyprintk=ttyS0,115200 console=ttyS0,115200 mobyplatform=gcp vsyscall=emulate"
CFG="DEFAULT linux
LABEL linux
KERNEL /vmlinuz64
INITRD /initrd.img
APPEND $GCE_CONFIG $*
"
printf "$CFG" > syslinux.cfg
cd ..
tar cf files.tar -C files .
virt-make-fs --size=1G --type=ext4 --partition files.tar disk.raw
guestfish -a disk.raw -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
tar cf - disk.raw | gzip -9