Ubuntu pxe autoinstall

From silverwiki

DHCP server configuration

With ISC dhcpd add these lines in your subnet declaration or host declaration

        filename "pxelinux.0";
  • filename: Filename to be retrieved containing bootloader from tftp server
  • next-server: The next server in the boot process, which is the tftp server

Tftp server configuration

Tftp servers are usually configured to serve from /tftpboot, but that sucks so here's my debian /etc/default/tftpd-hpa

# /etc/default/tftpd-hpa


Note that it's on UDP (YOU DEE PEE!!!) so no tcpdump. See if it's open with netstat -lpn

PXE server configuraton

You need a pxe config in your tftp root's pxelinux.cfg/ folder. That is where the bootloader will look for a file that matches it's machine information.

Ways to define a pxe configuration for pxelinux.0 to use:

pxelinux.0 uses config files in the tftp root pxelinux.cfg/ folder. They can be named silly things like:

  • By non-separated uppercase HEX encoded IP address, can be shortened to match a subnet
  • By a - separated lowercase MAC address with an 01- in front of it
  • filename "default" will match everything, good for a utility menu with a localboot timeout value (memtest the planet!)

You can make symlinks from mac addresses to machine names and then symlink those machine names to their desired boot configs, if you want to be fancy and use pxe boot control. Say you have a new machine or VM with mac "01-52-54-00-1c-cf-87" named "dirtyharry". You can make it easy to view and change it's configuration with the following pattern: (Assuming you have a local boot config named local-boot and a ubuntu installer config named ubuntu-installer)

ln -s dirtyharry 01-52-54-00-1c-cf-87
ln -s ubuntu-installer dirtyharry

then when you want to change it just redo the second one

ln -s local-boot dirtyharry

Ubuntu 14.04 specific bits

Kernel and initrd

mount the ubuntu cd with something like

mount -o loop ubuntu-1404-server.iso /mnt

yoink the files you need, leave the ones you don't

mkdir -p /srv/tftp/ubuntu-installer/amd64/
cp /mnt/install/netboot/ubuntu-installer/pxelinux.0 /srv/tftp/ubuntu-installer/amd64/
cp /mnt/install/netboot/ubuntu-installer/linux /srv/tftp/ubuntu-installer/amd64/
cp /mnt/install/netboot/ubuntu-installer/initrd.gz /srv/tftp/ubuntu-installer/amd64/
  • pxelinux.0 is the bootloader
  • linux is the kernel binary
  • initrd.gz is a ramdisk containing the installer

pxe config (goes in pxelinux.cfg/)

Make sure you fill in your hostname, domain, and tftp server address

default install
label install
        menu label ^Install
        menu default
        kernel ubuntu-installer/amd64/linux
        append vga=788 initrd=ubuntu-installer/amd64/initrd.gz auto=true locale=en_US.UTF-8 console-setup/charmap=UTF-8 console-keymaps-at/keymaps=en104 console-setup/layoutcode=en console-setup/ask_detect=false pkgsel/language-pack-patterns=pkgsel/install-language-support=false interface=eth0 hostname=preseedexample domain=example.com url=tftp:// --

preseed file

Make sure you fill in your hostname, domain, and user info. You can do some tricks to avoid exposing your password here like hashing, or creating a sudo account.

# Language setting
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debian-installer/locale string en_US.UTF-8
d-i localechooser/supported-locales en_US.UTF-8

# Keyboard setting
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
d-i console-setup/charmap select UTF-8
d-i keymap select jp106
d-i keyboard-configuration/xkb-keymap select jp106
d-i keyboard-configuration/layoutcode string jp
d-i keyboard-configuration/modelcode jp106

# Network setting
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string preseedexample
d-i netcfg/get_domain string example.org

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

# Clock setting
d-i clock-setup/utc boolean true
d-i time/zone string Japan
d-i clock-setup/ntp boolean true

# Partition setting
# すべてのRAIDデバイス構成を破棄する
d-i partman-md/device_remove_md boolean true
# すべてのLVMデバイス構成を破棄する
d-i partman-lvm/device_remove_lvm boolean true

d-i partman-auto-lvm/guided_size string max
#d-i partman-auto/init_automatically_partition select biggest_free
#d-i partman-auto/init_automatically_partition seen false
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/choose_partition select finish

d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/mount_style select uuid

# User setting
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password password test
d-i passwd/root-password-again password test
#d-i passwd/user-fullname string testuser
#d-i passwd/username string testuser
#d-i passwd/user-password password insecure
#d-i passwd/user-password-again password insecure
## このpreseedの例ではパスワードが短すぎるので、以下が必要
d-i user-setup/allow-password-weak boolean true
#d-i user-setup/encrypt-home boolean false

# Base system installation
#d-i base-installer/install-recommends boolean false
d-i base-installer/kernel/image string linux-image-amd64

# APT setting
# You can choose to install restricted and universe software, or to install
# software from the backports repository.
#d-i apt-setup/restricted boolean true
#d-i apt-setup/universe boolean true
#d-i apt-setup/backports boolean true
# Uncomment this if you don't want to use a network mirror.
#d-i apt-setup/use_mirror boolean false
# Select which update services to use; define the mirrors to be used.
# Values shown below are the normal defaults.
#d-i apt-setup/services-select multiselect security
#d-i apt-setup/security_host string security.ubuntu.com
#d-i apt-setup/security_path string /ubuntu

# package selection
tasksel tasksel/first multiselect standard
d-i pkgsel/update-policy select none
d-i pkgsel/include string openssh-server
d-i pkgsel/upgrade select none

# Grub
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i finish-install/reboot_in_progress note

Client machine configuration

boot order

For PXE install then localboot oneshot headshot

This will allow a clean disk to pxe install and reboot into the OS

  1. Hard disk boot
  2. PXE boot

PXE server in full control of boot

Alternatively but less automagically and more overly controlling:

  1. PXE boot

You will be required to create a pxe config file to enforce localboot when pxe boot is not desired (eg, After install)

default local
LABEL local
        MENU LABEL Boot local hard drive
        LOCALBOOT 0