forked from public/airgap
1
0
Fork 0

Second pass w/ hybrid grub/syslinux for efi/bios boot

This commit is contained in:
Lance Vick 2024-06-11 14:07:13 -07:00
parent e723c545c9
commit fbdb919b7f
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
2 changed files with 119 additions and 46 deletions

View File

@ -5,7 +5,8 @@ FROM stagex/syslinux AS syslinux
FROM stagex/cpio AS cpio FROM stagex/cpio AS cpio
FROM stagex/linux-airgap AS linux FROM stagex/linux-airgap AS linux
FROM stagex/mtools AS mtools FROM stagex/mtools AS mtools
FROM stagex/dosfstools AS dosfstools FROM stagex/xz AS xz
FROM stagex/grub:local AS grub
FROM scratch AS base FROM scratch AS base
COPY --from=busybox . / COPY --from=busybox . /
@ -14,56 +15,122 @@ COPY --from=xorriso . /
COPY --from=cpio . / COPY --from=cpio . /
COPY --from=mtools . / COPY --from=mtools . /
COPY --from=linux . / COPY --from=linux . /
COPY --from=dosfstools . /
COPY --from=syslinux . / COPY --from=syslinux . /
COPY --from=xz . /
COPY --from=grub . /
FROM base AS build FROM base AS build
COPY --from=linux /bzImage /iso/boot/bzImage
## Kernel
COPY --from=linux /bzImage iso/boot/vmlinuz
## Initramfs
COPY --from=stagex/busybox . initramfs COPY --from=stagex/busybox . initramfs
COPY --chmod=0755 <<-EOF initramfs/init COPY --chmod=0755 <<-EOF initramfs/init
#!/bin/sh #!/bin/sh
/bin/sh /bin/sh
EOF EOF
RUN cd initramfs && find . | cpio -o -H newc | gzip -9 > /iso/boot/init.gz
COPY <<-EOF iso/isolinux/isolinux.cfg
DEFAULT linux
LABEL linux
KERNEL boot/bzImage
APPEND initrd=boot/init.gz
EOF
COPY --from=syslinux /usr/share/syslinux/isolinux.bin iso/isolinux/
COPY --from=syslinux /usr/share/syslinux/ldlinux.c32 iso/isolinux/
RUN <<-EOF RUN <<-EOF
set -eux set -eux
mkdir -p iso/efi cd initramfs
truncate -s $((10796+128+128))k iso/efi/esp.img find . \
mkfs.fat -F 16 -f 1 -M 0xF0 -r 112 -R 1 iso/efi/esp.img | cpio -o -H newc \
mmd -i iso/efi/esp.img ::boot | gzip -9 \
mcopy -i iso/efi/esp.img iso/boot/bzImage ::boot/bzImage > ../iso/boot/initramfs
mcopy -i iso/efi/esp.img iso/boot/init.gz ::boot/init.gz
mmd -i iso/efi/esp.img ::syslinux
mcopy -i iso/efi/esp.img iso/isolinux/isolinux.cfg ::syslinux/syslinux.cfg
mcopy -i iso/efi/esp.img /usr/share/syslinux/efi64/ldlinux.e64 ::syslinux/ldlinux.e64
mmd -i iso/efi/esp.img ::efi
mmd -i iso/efi/esp.img ::efi/boot
mcopy -i iso/efi/esp.img /usr/share/syslinux/efi64/syslinux.efi ::efi/boot/boot64.efi
ls -Rlah iso
EOF EOF
## Grub (EFI Boot)
COPY <<-EOF iso/boot/grub/grub.cfg
menuentry "Linux Airgap" {
linux /boot/vmlinuz
initrd /boot/initramfs
}
EOF
COPY <<-EOF grub_early.cfg
search --no-floppy --set=root --label "Airgap"
set prefix=(\$root)/boot/grub
EOF
RUN <<-EOF
set -eux
mkdir -p iso/efi/boot
grub-mkimage \
--config="grub_early.cfg" \
--prefix="/boot/grub" \
--output="iso/efi/boot/bootx64.efi" \
--format="x86_64-efi" \
--compression="xz" \
all_video \
disk \
part_gpt \
part_msdos \
linux \
normal \
configfile \
search \
search_label \
efi_gop \
fat \
iso9660 \
cat \
echo \
ls \
test \
true \
help \
gzio
EOF
RUN <<-EOF
mformat -i iso/boot/grub/efi.img -C -f 1440 -N 0 ::
mcopy -i iso/boot/grub/efi.img iso/efi
touch -md "@0" iso/boot/grub/efi.img
EOF
## Syslinux (BIOS Boot)
COPY <<-EOF iso/boot/syslinux/syslinux.cfg
TIMEOUT 2
PROMPT -1
DEFAULT Airgap
LABEL Airgap
MENU LABEL Linux Airgap
KERNEL /boot/vmlinuz
INITRD /boot/initramfs
EOF
RUN <<-EOF
mkdir -p iso/boot/syslinux
for file in \
isohdpfx.bin \
isolinux.bin \
ldlinux.c32 \
libutil.c32 \
libcom32.c32 \
mboot.c32; \
do
mv /usr/share/syslinux/$file iso/boot/syslinux/$file || return 1
done
EOF
## Build Hybrid EFI/BIOS ISO
FROM build AS install FROM build AS install
RUN xorriso \ RUN xorrisofs \
-as mkisofs \
-output airgap.iso \ -output airgap.iso \
-eltorito-boot isolinux/isolinux.bin \ -full-iso9660-filenames \
-joliet \
-rational-rock \
-sysid LINUX \
-isohybrid-mbr iso/boot/syslinux/isohdpfx.bin \
-eltorito-boot boot/syslinux/isolinux.bin \
-eltorito-catalog boot/syslinux/boot.cat \
-no-emul-boot \ -no-emul-boot \
-boot-load-size 4 \ -boot-load-size 4 \
-boot-info-table \ -boot-info-table \
-eltorito-alt-boot \ -eltorito-alt-boot \
-eltorito-platform efi \ -e boot/grub/efi.img \
-eltorito-boot efi/esp.img \
-no-emul-boot \ -no-emul-boot \
-eltorito-catalog isolinux/boot.cat \ -isohybrid-gpt-basdat \
iso -follow-links \
#RUN isohybrid airgap.iso iso/
FROM scratch AS package FROM scratch AS package
COPY --from=install /iso /iso
COPY --from=install /airgap.iso / COPY --from=install /airgap.iso /

View File

@ -1,21 +1,27 @@
.DEFAULT_GOAL := .DEFAULT_GOAL :=
.PHONY: default .PHONY: default
default: \ default: \
$(OUT_DIR)/airgap.iso out/airgap.iso
.PHONY: vm .PHONY: vm
vm: vm: out/airgap.iso
$(call toolchain,$(USER)," \ qemu-system-x86_64 \
qemu-system-i386 \ -m 512M \
-M pc \ -machine pc \
-nographic \ -nographic \
-cdrom "$(OUT_DIR)/airgap.iso"; \ -cdrom "out/airgap.iso"
")
$(OUT_DIR)/airgap.iso: \ .PHONY: vm-uefi
$(FETCH_DIR)/buildroot vm-uefi:
qemu-system-x86_64 \
-m 4G \
-machine type=q35 \
-bios /usr/share/ovmf/OVMF.fd \
-cdrom "out/airgap.iso"
out/airgap.iso: Containerfile
docker build \ docker build \
--progress=plain \ --progress=plain \
--output type=oci,tar=false,force-compression=true,name=airgap,dest=airgap \ --output type=local,dest=out \
. \ -f Containerfile \
-f Containerfile .