Ubuntu Bootable USB with Kickstart

tldr; 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.

Many of these commands must be done as root, so we’ll start by dropping into root and going to the home folder (cd will take us to the home folder by default).

$ sudo su
# cd

Now 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.

# 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

# 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.

# mkdir -p /opt/ubuntuiso
# 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 >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.

# 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
#System timezone
timezone America/Denver
#Root password
rootpw --disabled
#Initial user
user ubuntu --fullname "ubuntu" --iscrypted --password $1$MQ0zGB4W$pwjX8nolgr2RJch2Omamt.
#Reboot after installation
#Use text mode install
#Install OS instead of upgrade
#Use CDROM installation media
#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
exec < /dev/tty6 > /dev/tty6
chvt 6
echo 'Acquire::http { Proxy ""; };' > /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 quesitons.

# 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' > 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.

# 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.

# chmod -w isolinux/txt.cfg

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

# 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.

# 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. Make sure that the usb drive is unmounted.

# umount /dev/sdb

And finally push the iso onto the usb drive.

# dd if=/opt/autoinstall.iso of=/dev/sdb

Now your usb drive should be ready for installation!

Credit to Elazar Leibovich for providing an awesome answer on stackoverflow

Ubuntu Bootable USB with Kickstart

Numerological facts of 2015

Did you wake up on January 1, 2015, and wonder what 2015 is about? Me too. And it turns out that MMXV has some fun patterns hiding in it.The first thing that I found out about 2015 is that it is a Lucas-Carmichael number, which according to Wikipedia means that it “is a positive composite integer n such that if p is a prime factor of n, then p + 1 is a factor of n + 1″. Concretely, the prime factors of 2015 are 13, 5, 31; so n=2015 and p=13, 5, 31. That means that 14, 6, 32 are all factors of 2016.

Well, now what? 2015 isn’t prime – we have to wait till 2017 for another one of those. It can’t be written as the sum of three squares – but it can be written as a sum of four squares. Maybe it’s interesting that the closest twin primes are 1997 and 1999? I was worried too until I saw that 2015 can be written as 2^11 – 33 which itself can be rewritten as 2^11 – 2^5 – 1. What if we switched bases? In binary, 2015 is written 11111011111. I don’t know about you, but I love palindromes (did you notice the prime factors palindrome?). What about other basses? In base 4, it would be written as 133133; base 8: 3737; base 64: 3131. Aha! Glorious pattern!

Unfortunately 2015 written base 16 and base 32 doesn’t contain much pattern. But just for fun, let’s see what it looks like in base 16: 7df. Any colorists around? That’s a rather blue looking number to me. Maybe it would help if I rewrote it as #7df. And for one final trick, let’s write the IEEE floating point representation of 2015. 000…07c9f40 those last 3 bytes make a rather green color.


If you can think of other interesting facts about 2015, please let us know! I hope you have a very blue-green, palindromic year!
Numerological facts of 2015

Install Scientific Python, iPython, NLTK and Notebook on a Macbook

Recently we needed to set up several Macbook systems for scientific Python. The excellent install post at Lowin Data Company is the latest successor to ‘This is the Green Room‘ for Mac Lion. This is our Mountain Lion 10.8.4 update to catch up changes while keeping it brief. Here we go:

Step 1

Confirm you have an Apple ID (required)
Open the App Store, find and install Xcode (free of charge)

Screen Shot 2013-07-29 at 4.56.18 PM

Step 2

Start XCode and bring up Preferences:
(NOTE: If Xcode asks to Update Devices immediately after start, accept this update)

Screen Shot 2013-07-29 at 5.03.59 PM

Step 3

Now install the Command Line Tools, top line of the panel:

Screen Shot 2013-07-29 at 4.55.40 PM

Step 4

Open Terminal app and run the following commands:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
echo "export PATH=/usr/local/bin:$PATH" | sed 's!:/usr/local/bin$!!gp'| cat >>  ~/.bash_profile
# homebrew is now installed, look to their website for more instructions
brew install python --with-brewed-openssl
# python is now installed with pip and Setuptools
. ~/.bash_profile
# everything is ready to go and environment is set, install the target programs
pip install virtualenv
pip install numpy
brew install gfortran
pip install scipy
brew install freetype
brew install libpng
pip install matplotlib
brew install libyaml
pip install pyyaml
pip install nltk

Step 5

Now run ipython to confirm NLTK is installed, and to download the NLTK corpus files:

In [1]: import nltk
In [2]: nltk.download()

(Search screen for a newly opened panel to download collections. Choose ‘all-corpora’ and click ‘Download’ – same for ‘book’ – this is a lengthy download, go get coffee)

To get back to the Python prompt, exit the download panel. And let’s test that NLTK is really installed:

In [3]: from nltk.corpus import brown
In [4]: brown.words()
Out[4]: ['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ...]

Step 6

Now install an optional but very useful tool, iPython Notebook, to record and share your work as convenient .pynb “Notebook” files.

pip install tornado
brew install zmq
pip install pyzmq
pip install pygments

Step 7

Let’s test to see the Notebook works. Look for a browser to start up with a Notebook web page served locally.
(NOTE: You will not be able to view this web page from another system. The iPython Notebook defaults to local access only, as it is not secure by default. Kinda weird if you ask me, as it would be great to share with collaborators.)

ipython notebook --plyab=inline


I hope I didn’t have a dependency already installed and forgot to list it. If you find something, say so and I’ll update this post.

Install Scientific Python, iPython, NLTK and Notebook on a Macbook