Skip to content

Instantly share code, notes, and snippets.

@hemebond
Last active January 24, 2016 08:02
Show Gist options
  • Save hemebond/5c242125b098feaa5360 to your computer and use it in GitHub Desktop.
Save hemebond/5c242125b098feaa5360 to your computer and use it in GitHub Desktop.
#! /bin/bash
#
# Original at http://hempeldesigngroup.com/embedded/stories/debian-squeeze-pxe-netboot-for-virtualbox/
#
# -----------------------------------------------------------------------------
# makePxeInstaller.sh - Make a netbootable directory that has all the IDE
# and sata drivers needed for a VirtualBox install
#
# Works in the current directory
# -----------------------------------------------------------------------------
echo "Executing makePxeInstaller"
# Set up variables so that the script is easier to update
FWDEST=$PWD
#FWTMP=$HOME/tmp/d-i_firmware
FWTMP=/tmp/d-i_firmware
DEB_DISTS=http://httpredir.debian.org/debian/dists
DIST=jessie
ARCH=amd64
IMAGES=$DEB_DISTS/$DIST/main/installer-$ARCH/current/images
NETBOOT_TAR_GZ=$IMAGES/netboot/netboot.tar.gz
HD_INITRD_GZ=$IMAGES/hd-media/initrd.gz
# Comment these lines out if you do NOT want to clear out existing files
rm -rf $FWTMP/netboot
rm -rf $FWDEST/netboot
# -----------------------------------------------------------------------------
# Check if we already copied the installer, symlink if we have it
if [ -d $FWDEST/netboot ]; then
echo " symlinking the netboot directory..."
#ln -sf $FWDEST/netboot $HOME/.VirtualBox/TFTP
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Check if we already built the installer, copy and symlink if we have it
if [ -d $FWTMP/netboot ]; then
echo " Copying and symlinking the netboot directory..."
cp -R $FWTMP/netboot $FWDEST
#ln -sf $FWDEST/netboot $HOME/.VirtualBox/TFTP
echo "Done"
exit
fi
# -----------------------------------------------------------------------------
# Otherwise get ready to do a complete build
#
# Make a temp dir for the installer gz files and then go there
echo " Making download directory..."
mkdir -p $FWTMP/download
cd $FWTMP/download
# Check to see if the destination files already exist before downloading
# them
echo " Downloading netboot.tar.gz if we don't have it already..."
[ -f netboot.tar.gz ] || wget $NETBOOT_TAR_GZ
echo " Downloading hdboot intrd.gz if we don't have it already..."
[ -f initrd.gz ] || wget $HD_INITRD_GZ
# Make a directory for the extracted netboot files and extract them
echo " Extracting netboot.tar.gz..."
mkdir -p $FWTMP/netboot
cd $FWTMP/netboot
pax -rz -f $FWTMP/download/netboot.tar.gz
# Make a directory for the extracted intrd files and extract them
echo " Extracting netboot initrd.gz..."
mkdir -p $FWTMP/initrd
cd $FWTMP/initrd
pax -rz -f $FWTMP/netboot/debian-installer/$ARCH/initrd.gz
# Copy the missing ata and ide drivers from the hdboot image to the netboot image
echo " Copying ide and ata drivers from hdboot initrd.gz..."
pax -rz -f $FWTMP/download/initrd.gz lib/modules/*/kernel/drivers/ata/*
#pax -rz -f $FWTMP/download/initrd.gz lib/modules/*/kernel/drivers/ide/*
# Find all the files in the netboot initrd directory and rebuild netboot initrd.gz
echo " Rebuilding netboot initrd.gz..."
pax -wz -x sv4cpio -f $FWTMP/netboot/debian-installer/$ARCH/initrd.gz .
# Remove the initrd directory - no longer needed
echo " Cleaning up the initrd dircetory..."
cd $FWTMP
rm -r $FWTMP/initrd
# Copy the results to the where we ran the script from
echo " Copying and symlinking the netboot dircetory..."
cp -R $FWTMP/netboot $FWDEST
#ln -sf $FWDEST/netboot $HOME/.VirtualBox/TFTP
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment