Create a gist now

Instantly share code, notes, and snippets.

A little script to generate a debian netboot image and automatically integrate the latest firmware bundle.Requires pax (apt-get install pax) and a working PXE setup. Change the variable BOOTDIR to suit your needs. Still in development, would recommend double checking to make sure it won't do anything harmful to your setup.
#!/bin/sh
# https://github.com/Dimtree
# V2 (This one actually works!)
# (I put the preseed.cfg file in /firmware. Don't ask.)
BOOTDIR=/var/tftp
PRESEED=./preseed.cfg
TMP=$(mktemp -d)
[ $# -eq 0 ] && { echo "Usage: $0 arch" ; echo 'Try "i386" or "amd64"' ; exit 1; }
echo "Setting arch to "$1"..."
ARCH=$1
wget -qO $TMP/netboot.tar.gz http://ftp.us.debian.org/debian/dists/stable/main/installer-$ARCH/current/images/netboot/netboot.tar.gz
rm -r $BOOTDIR/*
tar xzp -C $BOOTDIR -f $TMP/netboot.tar.gz
mkdir -p $TMP/firmware
wget -qO $TMP/firmware.tar.gz http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/stable/current/firmware.tar.gz
tar -zxp -C $TMP/firmware -f $TMP/firmware.tar.gz
echo "default /debian-installer/$ARCH/linux" > $BOOTDIR/pxelinux.cfg/default
if [ -f $PRESEED ]
then
echo "Preseed file found at $PRESEED"
cp $PRESEED $TMP/firmware
echo "append initrd=/debian-installer/$ARCH/initrd.gz locale=en_US keymap=us auto preseed/file=/firmware/preseed.cfg --">> $BOOTDIR/pxelinux.cfg/default
else
echo "No preseed file found at $PRESEED"
echo "append initrd=/debian-installer/$ARCH/initrd.gz --">> $BOOTDIR/pxelinux.cfg/default
fi
cd $TMP; pax -x sv4cpio -s'%firmware%/firmware%' -w firmware | gzip -c > $TMP/firmware.cpio.gz
[ -f $BOOTDIR/debian-installer/$ARCH/initrd.gz.orig ] || cp -p $BOOTDIR/debian-installer/$ARCH/initrd.gz $BOOTDIR/debian-installer/$ARCH/initrd.gz.orig
cat $BOOTDIR/debian-installer/$ARCH/initrd.gz.orig $TMP/firmware.cpio.gz > $BOOTDIR/debian-installer/$ARCH/initrd.gz
rm -r $TMP
chown tftp:tftp $BOOTDIR
chmod -R 755 $BOOTDIR
@Dimtree
Owner
  • Will now automatically include ./preseed.cfg, and update kernel parameters accordingly.
  • Will now actually use a single temp dir (yay!)
  • Made it cleaner and quieter

TODO: move the preseed.cfg somewhere other than the firmware directory.
TODO: option to change mirrors, releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment