Automatic Installation of Ubuntu Karmic

Mar 29, 2010  

I’ll show you how to setup a PXE/netboot server and use the preseed feature of Debian Installer to automatically install your Ubuntu server.

The workflow of the netboor process is:

  • Your client boot with the network interface in PXE mode
  • The network interface issue a DHCP request
  • The DHCP server gives it an IP and also the filename of the PXE bootloader (pxelinux.0)
  • The network interface download the PXE bootloader throught tftp
  • The PXE bootloader boot and try to download it’s config file (defaults to pxelinux.cfg/default)
  • The config file tells pxelinux to download the linux kernel and its initrd
  • The linux kernel boots and start the install

The first step is to install and configure a tftp server to transfer all files (pxelinux, pxelinux config file, linux kernel and initrd)

apt-get install tftpd-hpa

Then we edit the config file: /etc/default/tftpd-hpa

RUN_DAEMON="yes"
OPTIONS="-4 -l -v -s /var/lib/tftpboot"

You can now start your tftp server /etc/init.d/tftpd-hpa start. Make sure that the directory defined in the config file exists and that the server is properly running.

The second step is to setup a DHCP server, we’ll use dnsmasq as it is really easy to setup:

apt-get install dnsmasq

Then we edit the config file: /etc/dnsmasq.conf

dhcp-host=08:00:27:3B:0A:E2,192.168.42.42

dhcp-boot=pxelinux.0
dhcp-range=192.168.42.5,192.168.42.99,12h
dhcp-option=3,192.168.42.1

You should make sure that the ip (192.168.42.X) range match the ip of your network interface.
The dhcp-host directive is used to assign a static ip address to a specific mac address.

The third step is to fetch the necessary files from http://archive.ubuntu.com/ubuntu/dists/karmic/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64/ (you can change the architecture and Ubuntu release).

You need to put the following files in /var/lib/tftpboot: pxelinux.0, linux and initrd.gz .
In the tftpboot directory, create a folder pxelinux.cfg
In this directory, you can either create a file named from the mac address of the client (eg: 01-08-00-27-3b-0a-e2) or you can name it default but it’s quite dangerous as it would match any host and would reinstall it upon reboot.
The content of the file should be (don’t forget to restart dnsmasq after the modification to the configuration file):

default server

label server
kernel linux
append initrd=initrd.gz auto url=http://192.168.42.1/preseed.cfg vga=normal debian-installer/locale=en_US console-setup/layoutcode=fr netcfg/choose_interface=eth0 netcfg/get_hostname=

Now the last step is to install any webserver to serve the file preseed.cfg references in the previous file, this file will contain all the answers to debian installer questions, so it should be fully automatic.

d-i mirror/country string manual
d-i mirror/http/hostname string us.archive.ubuntu.com
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string

d-i time/zone string Europe/Paris

d-i clock-setup/utc boolean true

d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-auto/device_remove_lvm boolean true

d-i partman-auto/expert_recipe string                         \
      boot-root ::                                            \
              40 50 100 ext3                                  \
                      $primary{ } $bootable{ }                \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext3 }    \
                      mountpoint{ /boot }                     \
              .                                               \
              500 10000 1000000000 ext4                       \
                      method{ format } format{ }              \
                      use_filesystem{ } filesystem{ ext4 }    \
                      mountpoint{ / }                         \
              .                                               \
              64 512 300% linux-swap                          \
                      method{ swap } format{ }                \
              .

#d-i partman-auto/choose_recipe select boot-root

d-i partman-basicmethods/method_only boolean false
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

d-i passwd/root-login boolean true
d-i passwd/make-user boolean false

d-i passwd/root-password password sebest
d-i passwd/root-password-again password sebest
d-i user-setup/allow-password-weak boolean true

d-i pkgsel/update-policy select none
d-i pkgsel/install-language-support boolean false

d-i tasksel/force-tasks string server
d-i tasksel/first multiselect OpenSSH server

d-i debian-installer/allow_unauthenticated string true

d-i grub-installer/with_other_os boolean true

d-i finish-install/reboot_in_progress note

If you more informations about this file you can read the following page. And use this page for infos about partionning.