From a3ea4fb2e4ea5e34ed19515d5af513f62cdc09c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Sun, 14 Jul 2019 23:24:43 +0200 Subject: [PATCH] disk image builder --- Makefile | 123 +++++++++++++++++++++++++++------ cfg_syslinux/boot/bootmenu.cfg | 16 +++++ cfg_syslinux/boot/syslia32.cfg | 3 + cfg_syslinux/boot/syslinux.cfg | 3 + cfg_syslinux/boot/syslx64.cfg | 3 + 5 files changed, 127 insertions(+), 21 deletions(-) create mode 100644 cfg_syslinux/boot/bootmenu.cfg create mode 100644 cfg_syslinux/boot/syslia32.cfg create mode 100644 cfg_syslinux/boot/syslinux.cfg create mode 100644 cfg_syslinux/boot/syslx64.cfg diff --git a/Makefile b/Makefile index 65005eb..d2493c5 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,19 @@ DEFAULT: _target -.PHONY: _target _qemu _partition _format _mount _bootstrap _install _sparse _copy _config _syslinux _umount _partcopy _squash _mbr +.PHONY: clean _target _qemu _partition _format _mount _bootstrap _install _sparse _copy _config _syslinux _umount _partcopy _squash _mbr ARCH := amd64 KEYRING := keys/debian-archive-stretch-stable.gpg BOOTSTRAP := http://cdn.debian.net/debian +# Partition Table + Boot Partition + Root Partition = 2048M +BOOT_MB := 126 +ROOT_MB := 1920 + define SOURCES = deb http://cdn.debian.net/debian stretch main endef + PACKAGES := ${PACKAGES} apt btrfs-tools busybox-static bzip2 ca-certificates cron debian-archive-keyring deborphan firmware-linux-free gzip htop ifupdown init iputils-ping irqbalance isc-dhcp-client less make net-tools nmap ntpdate openssh-client psmisc rsync sshfs sudo systemd traceroute unzip vim wget wireless-tools wpasupplicant xz-utils zip ifdef disk @@ -66,7 +71,7 @@ _config: _copy _squash: _config else ifdef raspi -VOLUME := ${image} +VOLUME := ${raspi} PBOOT := rpi_boot.img PROOT := rpi_root.img SYSROOT := rpi_root/ @@ -110,10 +115,22 @@ endif export SOURCES SYSROOT CFGROOT VOLUME PBOOT PROOT SQUASH ARCH KEYRING BOOTSTRAP -${SYSROOT}: - btrfs subvol create "$$SYSROOT" || mkdir -p "$$SYSROOT}" +sys_root/: + btrfs subvol create "$@" || mkdir -p "$@" + chmod 755 "$@" + +cfg_root/: sys_root/ _install + btrfs sub snap "$<" "$@" || mkdir -p "$@" + chmod 755 "$@" + +img_mount/: + mkdir -p "$@" + chmod 755 "$@" + +hdd_mount/: + mkdir -p "$@" chmod 755 "$@" - + _qemu: ${SYSROOT}/usr/bin/qemu-arm-static ${SYSROOT}/usr/bin/qemu-arm-static: /usr/bin/qemu-arm-static ${SYSROOT} mkdir -p "$${SYSROOT}"/usr/bin @@ -151,33 +168,97 @@ _install: ${SYSROOT} _aptkeys _norecommends chroot "$${SYSROOT}" apt-get clean chroot "$${SYSROOT}" rm /usr/local/sbin/invoke-rc.d -_copy: ${SYSROOT} - btrfs sub snap "$${SYSROOT}" "$${CFGROOT}" || \ - cp -a "$${SYSROOT}/." "$${CFGROOT}/" +_copy: ${SYSROOT} ${CFGROOT} + cp -au "$${SYSROOT}/." "$${CFGROOT}/" .PHONY: _main_config _config: _main_config _main_config: ${CFGROOT} cfg_seed/ - cp -a cfg_seed/. "$${CFGROOT}" + cp -au cfg_seed/. "$${CFGROOT}" ${SQUASH}: ${CFGROOT} - -rm "$@" - mksquashfs "$$CFGROOT" "$$SQUASH" -comp xz + -rm "$${SQUASH}" + mksquashfs "$${CFGROOT}" "$${SQUASH}" -comp xz _squash: ${SQUASH} +${VOLUME}: + ! printf '%s\n' "$${VOLUME}" |grep -q '^/dev/' # abort if volume should be real device + dd bs=1M count=0 seek=$$((2 + ${BOOT_MB} + ${ROOT_MB})) of="$${VOLUME}" + +${PBOOT}: + ! printf '%s\n' "$${PBOOT}" |grep -q '^/dev/' # abort if volume should be real device + dd bs=1M count=0 seek=${BOOT_MB} of="$${PBOOT}" + +${PROOT}: + ! printf '%s\n' "$${PROOT}" |grep -q '^/dev/' # abort if volume should be real device + dd bs=1M count=0 seek=${ROOT_MB} of="$${PROOT}" + +_partition: ${VOLUME} + printf 'label: gpt\n\n: start=2MiB, size=%iMiB, type=1, attrs="LegacyBIOSBootable"\n: type=20\n' \ + ${BOOT_MB} | sfdisk "$${VOLUME}" + +_sparse: ${PBOOT} ${PROOT} + +_format: ${PBOOT} ${PROOT} + -umount "$${CFGROOT}/boot" "$${CFGROOT}" + mkfs.fat -F 32 -n boot "$${PBOOT}" + mkfs.ext4 -F -L FSROOT "$${PROOT}" + +.PHONY: _syslinux_efi32 _syslinux_efi64 _syslinux_bios +_syslinux_efi32: ${CFGROOT} + mkdir -p "$${CFGROOT}/boot/EFI/BOOT" + cp /usr/lib/SYSLINUX.EFI/efi32/syslinux.efi "$${CFGROOT}/boot/EFI/BOOT/BOOTIA32.EFI" + mkdir -p "$${CFGROOT}/boot/efi32" + cp $(addprefix /usr/lib/syslinux/modules/efi32/, ldlinux.e32 menu.c32 libutil.c32) "$${CFGROOT}"/boot/efi32/ + +_syslinux_efi64: ${CFGROOT} + mkdir -p "$${CFGROOT}/boot/EFI/BOOT" + cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi "$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI" + mkdir -p "$${CFGROOT}/boot/efi64" + cp $(addprefix /usr/lib/syslinux/modules/efi64/, ldlinux.e64 menu.c32 libutil.c32) "$${CFGROOT}"/boot/efi32/ + +_syslinux_bios: ${CFGROOT} + mkdir -p "$${CFGROOT}/boot/bios" + cp $(addprefix /usr/lib/syslinux/modules/bios/, menu.c32 libutil.c32) "$${CFGROOT}"/boot/bios/ + +_syslinux: ${CFGROOT} _syslinux_efi32 _syslinux_efi64 _syslinux_bios + cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${CFGROOT}/boot/" + cp -ru cfg_syslinux/. "$${CFGROOT}/" + +_mbr: ${VOLUME} + syslinux -t 2097152 -i "$${VOLUME}" + dd conv=notrunc if=/usr/lib/syslinux/mbr/gptmbr.bin of="$${VOLUME}" + +_partcopy: ${VOLUME} ${PROOT} ${PBOOT} + dd bs=1M seek=2 if="$${PBOOT}" of="$${VOLUME}" + dd bs=1M seek=$$((2 + ${BOOT_MB})) if="$${PROOT}" of="$${VOLUME}" + +_mount: ${PBOOT} ${PROOT} ${CFG_ROOT} + mount -t ext4 "$${PROOT}" "$${CFGROOT}" + chmod 755 "$${CFGROOT}" + mkdir -p "$${CFGROOT}/boot" + chmod 755 "$${CFGROOT}/boot" + mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot" + chmod 755 "$${CFGROOT}/boot" + +_umount: ${CFGROOT} + -umount "$${CFGROOT}/boot" + umount "$${CFGROOT}" && rmdir "$${CFGROOT}" + clean: [ "$${SYSROOT#/}" ] && [ "$${CFGROOT#/}" ] || false # (abort receipe) - -mount |grep -qwF "$${SYSROOT}/boot" && umount "$${SYSROOT}/boot" - -mount |grep -qwF "$${SYSROOT}/proc" && umount "$${SYSROOT}/proc" - -mount |grep -qwF "$${SYSROOT}/sys" && umount "$${SYSROOT}/sys" - -mount |grep -qwF "$${SYSROOT}/dev" && umount "$${SYSROOT}/dev" - -mount |grep -qwF "$${SYSROOT}" && umount "$${SYSROOT}" - -mount |grep -qwF "$${CFGROOT}" && umount "$${CFGROOT}" - if [ -d "$${SYSROOT}" ] && ! mount |grep -qwFe "$${SYSROOT}"; then \ - btrfs sub del "$${SYSROOT}" || echo rm -r "$${SYSROOT}"; \ + -umount img_mount/boot + -umount img_mount + -rmdir img_mount + -umount hdd_mount/boot + -umount hdd_mount + -rmdir hdd_mount + if [ -d "sys_root/" ] && ! mount |grep -qwFe "sys_root/"; then \ + btrfs sub del "sys_root/" || echo rm -r "sys_root/"; \ fi - if [ -d "$${CFGROOT}" ] && ! mount |grep -qwFe "$${CFGROOT}"; then \ - btrfs sub del "$${CFGROOT}" || echo rm -r "$${CFGROOT}"; \ + if [ -d "cfg_root/" ] && ! mount |grep -qwFe "cfg_root/"; then \ + btrfs sub del "cfg_root/" || echo rm -r "cfg_root/"; \ fi -rm "$${SQUASH}" + -[ -f "$${VOLUME}" ] && rm "$${VOLUME}" diff --git a/cfg_syslinux/boot/bootmenu.cfg b/cfg_syslinux/boot/bootmenu.cfg new file mode 100644 index 0000000..dbebfeb --- /dev/null +++ b/cfg_syslinux/boot/bootmenu.cfg @@ -0,0 +1,16 @@ +UI menu.c32 + +DEFAULT stretch +TIMEOUT 30 + +LABEL stretch + MENU LABEL Debian Stretch + KERNEL /vmlinuz + INITRD /initrd.img + APPEND root=LABEL=FSROOT + +LABEL stretch_rescue + MENU LABEL Debian Stretch Rescue + KERNEL /vmlinuz + INITRD /initrd.img + APPEND root=LABEL=FSROOT init=/bin/sh diff --git a/cfg_syslinux/boot/syslia32.cfg b/cfg_syslinux/boot/syslia32.cfg new file mode 100644 index 0000000..84e692e --- /dev/null +++ b/cfg_syslinux/boot/syslia32.cfg @@ -0,0 +1,3 @@ +PATH /efi32 +INCLUDE /bootmenu.cfg +MENU TITLE Syslinux EFI-32 diff --git a/cfg_syslinux/boot/syslinux.cfg b/cfg_syslinux/boot/syslinux.cfg new file mode 100644 index 0000000..b6397a5 --- /dev/null +++ b/cfg_syslinux/boot/syslinux.cfg @@ -0,0 +1,3 @@ +PATH bios +INCLUDE bootmenu.cfg +MENU TITLE Syslinux BIOS diff --git a/cfg_syslinux/boot/syslx64.cfg b/cfg_syslinux/boot/syslx64.cfg new file mode 100644 index 0000000..88f0ad3 --- /dev/null +++ b/cfg_syslinux/boot/syslx64.cfg @@ -0,0 +1,3 @@ +PATH /efi64 +INCLUDE /bootmenu.cfg +MENU TITLE Syslinux EFI-64 -- 2.39.2