Steps to create a kickstart server on Ubuntu 14.04

This is a good step-by-step guide

TL;DR; use isohybrid after repacking the custom iso

To make this usb, I used a virtual machine with Ubuntu 14.04 installed. The goal here is to make a bootable usb that doesn’t require selection of things like keyboard layout, language, etc. We want an automatic install of an Ubuntu server.

We need to get the ubuntu image that we’re going to be customizing for our installation.

wget http://releases.ubuntu.com/14.04/ubuntu-14.04.2-server-amd64.iso

We’re going to need a place to mount the unpacked iso file.

sudo mkdir -p /mnt/iso

After we have created a mount point for it, now we have to mount it. This will expose the files that are held inside the iso. Unfortunately, the files will be read-only

. sudo mount -o loop ubuntu-14.04.2-server-amd64.iso /mnt/iso

In order to modify the files, we need to copy them to a directory where we can modify them, so we’ll create the directory and then copy the files to it.

sudo mkdir -p /opt/ubuntuiso
sudo cp -rT /mnt/iso /opt/ubuntuiso

Our new working directory will be /opt/ubuntuiso

cd /opt/ubuntuiso

In order to avoid being prompted for language selection in the installation process, we need to tell it what language we’re going to use. In this case, en is being used because I speak english.

echo en | sudo tee isolinux/lang

Now we are actually going to build the kickstart file with a program called system-config-kickstart. So we make sure it’s installed and then run it.

sudo apt-get install system-config-kickstart
system-config-kickstart

Then save the file from the GUI in /opt/ubuntuiso/. This should save a file called ks.cfg. My ks.cfg looks like the following

#Generated by Kickstart Configurator
#platform=AMD64 or Intel EM64T
#System language
lang en_US
#Language modules to install
langsupport en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone America/Denver
#Root password
rootpw --disabled
#Initial user
user ubuntu --fullname "ubuntu" --iscrypted --password $1$MQ0zGB4W$pwjX8nolgr2RJch2Omamt.
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use CDROM installation media
cdrom
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype ext2 --size 100 --asprimary
part swap --recommended
part / --fstype ext4 --size 1 --grow
#System authorization infomation
auth --useshadow --enablemd5
#Network information
network --bootproto=dhcp --device=eth0
#Firewall configuration
firewall --disabled
#Do not configure the X Window System
skipx
%post
#!/bin/bash
exec < /dev/tty6 > /dev/tty6
chvt 6
echo 'Acquire::http { Proxy "http://10.2.4.27"; };' > /etc/apt/apt.conf.d/02proxy
apt-get update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get install -y git ansible openssh-server vim
chvt 1

There is a little bit of hijacking done in the postscript (everything after %post). The line beginning with exec and the following line (chvt 6) are forcing the installer show the output from the commands that are run after that. The reason for this is that the loading bar will not move during the installation, and it can appear as though the installer has hung. The following line that does the proxy is for the apt-cache on our local network. The final line (chvt 1) reverts the output to the main installer.

Now we need to add the preseed file so that we can avoid other questions.

echo 'd-i partman/confirm_write_new_label boolean true d-i partman/choose_partition \ select Finish partitioning and write changes to disk d-i partman/confirm boolean true' | sudo tee ks.preseed

Now we need to tell the installer about the files that we just saved, so we need to modify isolinux/txt.cfg. First we need to make the file writable.

sudo chmod +w isolinux/txt.cfg

Then we need to replace the append line of the following section

label install
menu label ^Install Ubuntu Server
kernel /install/vmlinuz
append file=/cdrom/preseed/ubuntu-server.seed vga=788 initrd=/install/initrd.gz quiet --

Replace the append line with

append file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed --

Save and exit the file. We also need to make sure that we put the file back in its original state, so remove the write permissions.

sudo chmod -w isolinux/txt.cfg

Now create the new iso file that we will use to create the bootable usb.

sudo mkisofs -D -r -V "ATTENDLESS_UBUNTU" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o /opt/autoinstall.iso /opt/ubuntuiso

In order to finalize the bootable iso for a usb, we need to hybridize it.

sudo isohybrid /opt/autoinstall.iso

After hybridizing it, we can push it to the usb drive. The usb drive in my virtual machine shows up in /dev/sdb, but you need to use the correct label, so replace X accordingly Make sure that the usb drive is unmounted.

sudo umount /dev/sdX

And finally push the iso onto the usb drive. (Please note **this destroys data on the target device - make sure you know what you are doing)

sudo dd if=/opt/autoinstall.iso of=/dev/sdX

Now your usb drive should be ready for installation!