Add output types for BIOS and EFI ISOs

Note that the EFI ISO is not yet automatically sized, and the
kernel command lines are currently hard coded in the builders.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack
2017-03-03 18:44:47 -08:00
parent 3b838896b0
commit e35c4c9b37
7 changed files with 142 additions and 43 deletions

View File

@@ -0,0 +1,15 @@
FROM alpine:3.5
RUN \
apk update && apk upgrade && \
apk add --no-cache \
libarchive-tools \
binutils \
gummiboot \
mtools \
xorriso \
&& true
COPY . .
CMD [ "/make-efi" ]

View File

@@ -0,0 +1,29 @@
.PHONY: tag push
BASE=alpine:3.5
IMAGE=mkimage-iso-efi
default: push
hash: Dockerfile make-efi
DOCKER_CONTENT_TRUST=1 docker pull $(BASE)
tar cf - $^ | docker build --no-cache -t $(IMAGE):build -
docker run --rm --entrypoint /bin/sh $(IMAGE):build -c 'cat $^ /lib/apk/db/installed | sha1sum' | sed 's/ .*//' > $@
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:

73
tools/mkimage-iso-efi/make-efi Executable file
View File

@@ -0,0 +1,73 @@
#!/bin/sh
set -e
mkdir -p /tmp/efi
cd /tmp/efi
# input is a tarball of vmlinuz64 and initrd.img on stdin
# output is an iso on stdout
# extract. BSD tar auto recognises compression, unlike GNU tar
# only if stdin is a tty, if so need files volume mounted...
[ -t 0 ] || bsdtar xzf -
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
# Docker for Windows specific options, should be moved
WINDOWS_OPTIONS="mobyplatform=windows vsyscall=emulate page_poison=1 panic=1 rootdelay=300 noautodetect"
# Create a EFI boot file with kernel and initrd. From:
# https://github.com/haraldh/mkrescue-uefi/blob/master/mkrescue-uefi.sh
cp /usr/lib/gummiboot/linuxx64.efi.stub .
echo "earlyprintk=ttyS0,115200 console=ttyS0,115200 $WINDOWS_OPTIONS" > cmdline.txt
objcopy \
--add-section .osrel=/etc/os-release --change-section-vma .osrel=0x20000 \
--add-section .cmdline=./cmdline.txt --change-section-vma .cmdline=0x30000 \
--add-section .linux=./vmlinuz64 --change-section-vma .linux=0x40000 \
--add-section .initrd=initrd.img --change-section-vma .initrd=0x3000000 \
./linuxx64.efi.stub \
mobylinux.efi
# create a ISO with a EFI boot partition
mkdir -p iso
dd if=/dev/zero of=iso/efi.raw bs=1024 count=78000
mkfs.vfat iso/efi.raw
echo "mtools_skip_check=1" >> /etc/mtools.conf && \
mmd -i iso/efi.raw ::/EFI
mmd -i iso/efi.raw ::/EFI/BOOT
mcopy -i iso/efi.raw mobylinux.efi ::/EFI/BOOT/BOOTX64.EFI
xorriso -as mkisofs \
-R -f -e efi.raw -no-emul-boot -o mobylinux-efi.iso iso
cat mobylinux-efi.iso
# How to build a VHDX. Commented out because we are currently not using it
# Don't delete: It took too long to figure out how to do this...
# # create a disk image (150MB)
# # This is a little odd, as we run this as part of the default command.
# # Can't run this during the build step as it requires privilege.
# # The Magic numbers in losetup are startsector (2048) times 512 and
# # (endsector - startsector) * 512
# CMD cd /tmp/efi && \
# dd if=/dev/zero of=disk.raw bs=1024 count=51200 && \
# sgdisk -N 1 -t 1:ef00 disk.raw && \
# losetup -o 1048576 --sizelimit 51362816 /dev/loop/1 disk.raw && \
# mkfs.vfat /dev/loop/1 && \
# echo "drive c: file=\"/dev/loop/1\" mtools_skip_check=1" > /etc/mtools.conf && \
# mmd c:/EFI && \
# mmd c:/EFI/BOOT && \
# mcopy mobylinux.efi c:/EFI/BOOT/BOOTX64.EFI && \
# losetup -d /dev/loop/1 && \
# qemu-img convert -O vhdx disk.raw mobylinux-boot.vhdx && \
# cp /tmp/efi/mobylinux.efi /tmp/efi/mobylinuxefi.iso /tmp/efi/mobylinux-boot.vhdx /mnt/