From b1321a3823685ad664fd9ac7197e51f4db3e3760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Sun, 4 Oct 2020 19:52:58 +0200 Subject: [PATCH] Initial debian-build-netboot.sh script --- debian-build-netboot.sh | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 debian-build-netboot.sh diff --git a/debian-build-netboot.sh b/debian-build-netboot.sh new file mode 100755 index 0000000..2241b4a --- /dev/null +++ b/debian-build-netboot.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +set -e +set -x + +if [ $# -ne 1 ]; then + echo "Usage: debian-build-netboot.sh DEBIAN_RELEASE" + exit 1 +fi + +output_dir=debian-netboot +release=$1 +date=$(date +%F) +basename="$release-$date" +chroot_dir="$output_dir/$basename" + +# Cleanup output directory. +rm -rf $output_dir +mkdir -p "$chroot_dir" + +# Install base system. +debootstrap "$release" "$chroot_dir" +echo "unconfigured-host" > "$chroot_dir/etc/hostname" + +# Add non-free repository for firmware-bnx2 network card firmware. +echo "deb http://deb.debian.org/debian/ $release main contrib non-free" > "$chroot_dir/etc/apt/sources.list" +chroot "$chroot_dir" apt-get update +chroot "$chroot_dir" apt-get install -y firmware-bnx2 + +# SSH server, DNS updates from RAs. +chroot "$chroot_dir" apt-get install -y openssh-server rdnssd + +# Install and extract kernel. +chroot "$chroot_dir" apt-get install -y linux-image-amd64 +cp "$chroot_dir"/boot/vmlinuz-* "$output_dir/kernel-$basename" + +# Deploy SSH keys. +mkdir -p "$chroot_dir/root/.ssh" +for user in tfloure; do + curl "https://meta.recycled.cloud/~$user.keys" >> "$chroot_dir/root/.ssh/authorized_keys" +done + +# Make sure there is /init in the initramfs to avoid kernel panic. +# initramfs is designed to be PRE regular os, so /init usually hands over to +# /sbin/init... which are the same in our case. +ln -fs /sbin/init "$chroot_dir/init" + +# Display IP addresses on login screen. +echo '* * * * * root ip -6 -o addr show | grep -E -v " lo " > /etc/issue' > "$chroot_dir/etc/cron.d/ipv6addr" + +# Build initramfs from generated installation. +(cd "$chroot_dir"; find . | cpio -H newc -o | gzip -9 > "../initramfs-$basename")