Completely Automatic Unattended Install of Ubuntu

Completely Automatic Unattended Install of Ubuntu

2016-12-14. Category & Tags: Linux, Automatic, Ubuntu, Installation

OBS 1: this works only for ubuntu server edition, not desktop version. tested in ubuntu 16 x64.
OBS 2: remember to change some parts to real values, near: # modify to real value !!!
OBS 3: my version need some files in .iso file: “10_linux” & “sources.list”.
Warn: the default ks.cfg partition settings will erase the entire disk, and use LVM.

See also:
Boot Partitions, Install Multi-OS


sudo -s

cd /dev/shm/
mkdir oldiso
mkdir newiso
mount -o loop </path/to/ubuntu>.iso oldiso # modify to real value !!!
cp -rT oldiso newiso
cd newiso # OBS: all following actions are done in this folder
echo en > isolinux/lang # does not work ???

EDIT FILE isolinux/txt.cfg #

The 1st choice should be modified to:

label install
  menu label ^Install Sunny Ubuntu Server 16 LTS
  kernel /install/vmlinuz
  append file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed --

The changes are two parameters at the end: ks=... and preseed/..., “menu label”/name can also be changed.
Hint: it is ok to use files online, see using http or ftp.

ADD FILE ks.cfg #

Method 1: use existing (sunny setup):

#Generated by Kickstart Configurator
#platform=AMD64 or Intel EM64T

#System language
lang en_GB
#Language modules to install
langsupport zh_CN sv_SE --default=en_GB
#System keyboard
keyboard se
#System mouse
#System timezone
#timezone --utc Atlantic/Reykjavik
rm /etc/localtime; ln -s /usr/share/zoneinfo/UTC /etc/localtime
#Root password
rootpw --disabled
#Initial user
user hpc --fullname "hpc" --iscrypted --password $1$tlHWVLOl$sI/Qr2lD.lmCY2yr7JBLt/ # modify to real value !!!
# or:
# user hpc --fullname "hpc" --password 12345 # modify to real value !!!

#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
#Clear any existing partition information
clearpart --all --initlabel

#Disk partitioning, using LVM, size1 means use all the rest.
part /boot --fstype ext2 --size=500
#part swap --size=1024
part pv.01 --size=1 --grow
volgroup vg_1 pv.01
logvol swap --vgname=vg_1 --fstype swap --name=lv_swap --recommended
logvol  /  --vgname=vg_1  --size=1  --name=lv_root
#logvol  /var  --vgname=vg_1  --size=4096  --name=lv_var
#logvol  /tmp  --vgname=vg_1  --size=2048  --name=lv_tmp
#logvol  /spare  --vgname=vg_1  --size=1  --grow  --name=lv_spare

#System authorization infomation
auth  --useshadow  --enablemd5

#Firewall configuration
firewall --disabled
#network --bootproto=dhcp --device=eth0 # already dhcp by default, no need to set.

#Do not configure the X Window System
@ ubuntu-server


Method 2: generate (in GUI):

apt-get install system-config-kickstart
# then save file to newiso/ks.cfg

ADD FILE ks.preseed #

Used for some questions not (cannot be ???) answered in ks.cfg.

# Partition
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 partman/confirm_nooverwrite boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

# Keyboard selection.
# Disable automatic (interactive) keymap detection.
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/xkb-keymap select se

# Network
d-i netcfg/choose_interface select auto
## for slow init net device
d-i netcfg/dhcp_timeout string 120
d-i netcfg/dhcpv6_timeout string 10
d-i netcfg/dhcp_failed note
d-i netcfg/dhcp_options select Retry network autoconfiguration

# For mounted partition bug: umout if mounted
d-i preseed/early_command string umount /media || echo ''
## mountpoint -q /media && umount /media is better, but mountpoint is not a cmd during installation.
#d-i partman/unmount_active boolean true

# Is the system clock set to UTC?
#d-i clock-setup/utc     boolean false
#d-i clock-setup/ntp     boolean true
#d-i clock-setup/ntp-server

# Finishing-offline
d-i preseed/late_command string \
cp /cdrom/sources.list  /target/etc/apt/sources.list; \
in-target apt-get update; \
in-target apt-get -y upgrade; \
cp /cdrom/10_linux  /target/etc/grub.d/10_linux; in-target update-grub;

# Finishing-if-trust-online
#d-i preseed/late_command string \
#wget --no-check-certificate -O /target/etc/apt/sources.list; \
#in-target apt-get update; \
#in-target apt-get -y upgrade; \
#wget --no-check-certificate -O /target/etc/grub.d/10_linux; in-target update-grub;

# Keep regular virtual consoles (VT1-VT6) during installations from serial console.
d-i finish-install/keep-consoles boolean true
# Skip confirm reboot. WARN: make sure it will NOT reboot to installation.
#d-i finish-install/reboot_in_progress note
# Poweroff
#d-i debian-installer/exit/poweroff boolean true

For more preseed options, see official example.

EDIT FILE isolinux/isolinux.cfg #

timeout 50

The unit is 0.1 sec. This will select english on the first language selection and skip install menu selection. ref1, ref2.


mkisofs -D -r -V "SUNNY_UBUNTU" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -o /temp/autoinstall.iso ../newiso



  1. still has 3 times of pressing “enter”, two times at the very beginning (init language selection and install selection) (though auto install is the 1st); one time at the very ending: install completed confirm;
  2. w/o netowrk, will get net config error (in the middle of installation) and selected software install error (at the end, and need screen to change selection to “finishing …”);
  3. DHCP auto config may fail due to long time of negociation between PC & switch, which will not send DHCP request and cause DHCP client getting time out.
  4. %post does not work, use preseed instaed.
  5. not all specified packages are installed, e.g. vnc related packages, even put into %packages.
  6. see linux init if screen blacked out after 1st reboot.

OBS: even with network, there are 3 “enter"s should be typed: init language selection; install menu selection; install completed confirm. (will reboot after the 3rd “enter”).

main ref
lvm: logical volume
this post may help with headless and no keyboard/mouse installation (not tested)
dhcp timeout issue: see official example
mounted partition problem is a bug see official example mounted partition problem is a bug