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
_squash: _config
else ifdef raspi
-VOLUME := ${image}
+VOLUME := ${raspi}
PBOOT := rpi_boot.img
PROOT := rpi_root.img
SYSROOT := rpi_root/
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
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}"