DEFAULT: _target
.PHONY: clean .FORCE
-.PHONY: _qemu _bootstrap _install _copy _config _syslinux _squash
+.PHONY: _qemu _bootstrap _install _copy _config _bootloader _squash
.PHONY: _target _partition _format _mount _sparse _umount _partcopy _mbr
ARCH := amd64
BOOTSTRAP := http://cdn.debian.net/debian
# Partition Table (2M) + Boot Partition (126M)+ Root Partition + Slack Space (1M) = 2048M
-BOOT_MB := 126
-ROOT_MB := 1919
+BOOT_MB := 62
+ROOT_MB := 959
define SOURCES =
deb http://cdn.debian.net/debian stretch main
_bootstrap: _mount
_install: _bootstrap _mount
_config: _install _mount
-_syslinux: _mount
-_umount: _mount _config _syslinux
-_mbr: _umount _syslinux
+_bootloader: _mount
+_umount: _mount _config _bootloader
+_mbr: _umount _bootloader
else ifdef image
VOLUME := ${image}
_mount: _format
_copy: _install _mount
_config: _copy _mount
-_syslinux: _mount
-_umount: _mount _config _syslinux
+_bootloader: _mount
+_umount: _mount _config _bootloader
_partition:
_partcopy: _partition _umount
-_mbr: _partcopy _syslinux
+_mbr: _partcopy _bootloader
else ifdef squash
SQUASH := ${squash}
${VOLUME}: .FORCE
! printf '%s\n' "$${VOLUME}" |grep -q '^/dev/' # abort if volume should be real device
+ dd count=0 of="$${VOLUME}" # truncate
dd bs=1M count=0 seek=$$((3 + ${BOOT_MB} + ${ROOT_MB})) of="$${VOLUME}"
${PBOOT}: .FORCE
! printf '%s\n' "$${PBOOT}" |grep -q '^/dev/' # abort if volume should be real device
+ dd count=0 of="$${PBOOT}" # truncate
dd bs=1M count=0 seek=${BOOT_MB} of="$${PBOOT}"
${PROOT}: .FORCE
! printf '%s\n' "$${PROOT}" |grep -q '^/dev/' # abort if volume should be real device
+ dd count=0 of="$${PROOT}" # truncate
dd bs=1M count=0 seek=${ROOT_MB} of="$${PROOT}"
_partition: ${VOLUME}
mkfs.ext4 -F -L FSROOT "$${PROOT}"
.PHONY: _syslinux_efi32 _syslinux_efi64 _syslinux_bios
+.PHONY: _grub_efi32 _grub_efi64
+
_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/
cp /usr/lib/syslinux/modules/efi32/ldlinux.e32 "$${CFGROOT}/boot/EFI/BOOT/" # workaround
+ printf 'PATH /efi32\nINCLUDE /bootmenu.cfg\nMENU TITLE Syslinux EFI-32\n' >"$${CFGROOT}/boot/syslia32.cfg"
_syslinux_efi64: ${CFGROOT}
mkdir -p "$${CFGROOT}/boot/EFI/BOOT"
mkdir -p "$${CFGROOT}/boot/efi64"
cp $(addprefix /usr/lib/syslinux/modules/efi64/, ldlinux.e64 menu.c32 libutil.c32) "$${CFGROOT}"/boot/efi64/
cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 "$${CFGROOT}/boot/EFI/BOOT/" # workaround
-
+ printf 'PATH /efi64\nINCLUDE /bootmenu.cfg\nMENU TITLE Syslinux EFI-64\n' >"$${CFGROOT}/boot/syslx64.cfg"
_syslinux_bios: ${CFGROOT}
mkdir -p "$${CFGROOT}/boot/bios"
cp $(addprefix /usr/lib/syslinux/modules/bios/, menu.c32 libutil.c32) "$${CFGROOT}"/boot/bios/
+ printf 'PATH bios\nINCLUDE bootmenu.cfg\nMENU TITLE Syslinux BIOS\n' >"$${CFGROOT}/boot/syslinux.cfg"
-_syslinux: ${CFGROOT} _syslinux_efi32 _syslinux_efi64 _syslinux_bios
- cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${CFGROOT}/boot/"
- cp -ru cfg_syslinux/. "$${CFGROOT}/"
- # cp "$${CFGROOT}/boot/syslx64.cfg" "$${CFGROOT}/boot/EFI/BOOT/syslinux.cfg" # workaround
+_grub_efi32: ${CFGROOT}
+ mkdir -p "$${CFGROOT}/boot/EFI/BOOT"
+ grub-mkimage -p / -O i386-efi fat part_gpt normal linux all_video >"$${CFGROOT}/boot/EFI/BOOT/BOOTIA32.EFI"
-_mbr: ${VOLUME}
+_grub_efi64: ${CFGROOT}
+ mkdir -p "$${CFGROOT}/boot/EFI/BOOT"
+ grub-mkimage -p / -O x86_64-efi fat part_gpt normal linux all_video >"$${CFGROOT}/boot/EFI/BOOT/BOOTX64.EFI"
+
+_bootloader: ${CFGROOT} _grub_efi32 _grub_efi64 _syslinux_bios #_syslinux_efi32 _syslinux_efi64
+ # cp -L "$${CFGROOT}/vmlinuz" "$${CFGROOT}/initrd.img" "$${CFGROOT}/boot/"
+ # cp -r cfg_syslinux/. "$${CFGROOT}/"
+ printf 'UI menu.c32\nDEFAULT stretch\nTIMEOUT 30\n' >"$${CFGROOT}/boot/bootmenu.cfg"
+ printf 'set timeout=3\ndefault=stretch\n\n' >"$${CFGROOT}/boot/grub.cfg"
+ k="$$(printf ' %s' "$${CFGROOT}/boot/"vmlinuz-*)"; k="$${k##*/}"; \
+ i="$$(printf ' %s' "$${CFGROOT}/boot/"initrd.img-*)"; i="$${i##*/}"; \
+ printf '\nLABEL stretch\n MENU LABEL Debian Stretch\n KERNEL /%s\n INITRD /%s\n APPEND root=LABEL=FSROOT\n' \
+ "$$k" "$$i" >>"$${CFGROOT}/boot/bootmenu.cfg"; \
+ printf '\nLABEL rescue\n MENU LABEL Rescue\n KERNEL /%s\n INITRD /%s\n APPEND root=LABEL=FSROOT init=/bin/sh\n' \
+ "$$k" "$$i" >>"$${CFGROOT}/boot/bootmenu.cfg"; \
+ printf "menuentry 'Debian Stretch' --id 'stretch' {\n linux '/%s' root=LABEL=FSROOT\n initrd '/%s'\n}\n" \
+ "$$k" "$$i" >>"$${CFGROOT}/boot/grub.cfg"; \
+ printf "menuentry 'Rescue' --id 'rescue' {\n linux '/%s' root=LABEL=FSROOT init=/bin/sh\n initrd '/%s'\n}\n" \
+ "$$k" "$$i" >>"$${CFGROOT}/boot/grub.cfg"
+
+.PHONY: _syslinux_mbr _grub_mbr
+
+_syslinux_mbr: ${VOLUME}
syslinux -t 2097152 -i "$${VOLUME}"
dd conv=notrunc if=/usr/lib/syslinux/mbr/gptmbr.bin of="$${VOLUME}"
+_grub_mbr: ${VOLUME}
+ # grub-mkimage -p / -O i386-pc fat part_gpt normal linux all_video |dd conv=notrunc of="$${VOLUME}"
+
+_mbr: _syslinux_mbr # _grub_mbr
+
_partcopy: ${VOLUME} ${PROOT} ${PBOOT}
dd conv=notrunc,sparse bs=1M seek=2 if="$${PBOOT}" of="$${VOLUME}"
dd conv=notrunc,sparse bs=1M seek=$$((2 + ${BOOT_MB})) if="$${PROOT}" of="$${VOLUME}"