101

I need a CD or USB stick, that will install Ubuntu on a completely headless machine. Stick CD in and restart, no keyboard or screen should be involved.

There are a few obstacles:

  1. The language selection menu when you first boot the CD.
  2. The fact that the CD menu waits.
  3. The installer's asking questions during installation.
3

4 Answers 4

97

The complete solution is:

Remaster a CD, ie, download a non graphical ubuntu installation ISO (server or alternate installation CD), mount it

$ sudo su -
# mkdir -p /mnt/iso
# mount -o loop ubuntu.iso /mnt/iso

Copy the relevant files to a different directory

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

Prevent the language selection menu from appearing

# cd /opt/ubuntuiso
# echo en >isolinux/lang

Use GUI program to add a kickstart file named ks.cfg

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

To add packages for the installation, add a %package section to the ks.cfg kickstart file, append to the end of ks.cfg file something like this.

%packages
@ ubuntu-server
openssh-server
ftp
build-essential

This will install the ubuntu-server "bundle", and will add the openssh-server, ftp and build-essential packages.

Add a preseed file, to suppress 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' > ks.preseed

Set the boot command line to use the kickstart and preseed files

# vi isolinux/txt.cfg

Search for

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

add ks=cdrom:/ks.cfg and preseed/file=/cdrom/ks.preseed to the append line. You can remove the quiet and vga=788 words. It should look like

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

Now create a new iso

# 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

That's it. You'll have a CD that would install an Ubuntu system once you boot from it, without requiring a single keystroke.

16
  • 1
    Thank you for the great explanation, very useful! I found however that one doesn't need to specify the preseed file, just the filled in ks.cfg file was enough (also specified the partitions etc in there through kickstart). [ubuntu 10.04 64bit]
    – symaedr
    Apr 25, 2012 at 15:08
  • 1
    I still seem to need to press enter when it boots up.
    – Catskul
    Jul 10, 2012 at 17:35
  • 5
    To bypass the need to press enter on boot change the timeout value from 0 to 10 in /isolinux/isolinux.cfg: timeout 10 Note that a value of 10 represents 1 second. Feb 7, 2013 at 14:16
  • 1
    I like the isolinux/lang setting, thank you. Feb 12, 2015 at 2:53
  • 6
    To install from a USB stick, you just need one more step to convert the ISO to a USB drive bootable format: # isohybrid path/to/image.iso
    – jjnebeker
    Jan 24, 2017 at 15:47
6

The instructions at this question cover the process for creating an EFI bootable ISO (like the official Ubuntu x86_64 ISO).:

How do I create an EFI-bootable ISO of a customized version of Ubuntu?

The key differences are setting this as the preseed file:

d-i partman-auto/method string lvm
d-i partman-auto-lvm/guided_size string max
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm_write_new_label     boolean true
d-i partman/choose_partition            select  finish
d-i partman/confirm_nooverwrite         boolean true
d-i partman/confirm                     boolean true
d-i partman-auto/purge_lvm_from_device  boolean true
d-i partman-lvm/device_remove_lvm       boolean true
d-i partman-lvm/confirm                 boolean true
d-i partman-lvm/confirm_nooverwrite     boolean true
d-i partman-auto/init_automatically_partition       select      Guided - use entire disk and set up LVM
d-i partman/choose_partition                select      Finish partitioning and write changes to disk
d-i partman-auto-lvm/no_boot            boolean true
d-i partman-md/device_remove_md         boolean true
d-i partman-md/confirm                  boolean true
d-i partman-md/confirm_nooverwrite      boolean true

Use this as the kickstart file:

lang en_US
langsupport en_US
keyboard us
mouse
timezone America/Los_Angeles
rootpw --disabled
user USERNAME --fullname "USERNAME" --password "PASSWORD"
reboot
text
install
cdrom
auth  --useshadow  --enablemd5 
network --bootproto=dhcp --device=eth0
firewall --disabled 
skipx
%packages
@ ubuntu-server
openssh-server

Edit the grub EFI boot configuration for the ISO:

sudo nano ~/ubuntu/boot/grub/grub.cfg

Set to:

if loadfont /boot/grub/font.pf2 ; then
    set gfxmode=auto
    insmod efi_gop
    insmod efi_uga
    insmod gfxterm
    terminal_output gfxterm
fi

set menu_color_normal=white/light-blue
set menu_color_highlight=light-blue/light-gray
set timeout=10
set default=0

menuentry "Automatically Install Ubuntu Server with Custom Config" {
    set gfxpayload=keep
    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed quiet ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed --
    initrd  /install/initrd.gz
}
menuentry "OEM install (for manufacturers)" {
    set gfxpayload=keep
    linux   /install/vmlinuz  file=/cdrom/preseed/ubuntu-server.seed quiet oem-config/enable=true --
    initrd  /install/initrd.gz
}
menuentry "Multiple server install with MAAS" {
    set gfxpayload=keep
    linux   /install/vmlinuz  modules=maas-enlist-udeb vga=788 initrd=/install/initrd.gz quiet --
    initrd  /install/initrd.gz
}
menuentry "Check disc for defects" {
    set gfxpayload=keep
    linux   /install/vmlinuz  MENU=/bin/cdrom-checker-menu quiet --
    initrd  /install/initrd.gz
}
menuentry "Rescue a broken system" {
    set gfxpayload=keep
    linux   /install/vmlinuz  rescue/enable=true --
    initrd  /install/initrd.gz
}

Set isolinux/txt.cfg like this:

default install
label install
  menu label ^Install Ubuntu Server with Custom Config
  kernel /install/vmlinuz
  append file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed --
label cloud
  menu label ^Multiple server install with MAAS
  kernel /install/vmlinuz
  append   modules=maas-enlist-udeb vga=788 initrd=/install/initrd.gz quiet --
label check
  menu label ^Check disc for defects
  kernel /install/vmlinuz
  append   MENU=/bin/cdrom-checker-menu vga=788 initrd=/install/initrd.gz quiet --
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80

Create a dual boot catalog ISO:

sudo mkisofs -U -A "Custom1404" -V "Custom1404" -volset "Custom1404" -J -joliet-long -r -v -T -o ../Custom1404.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot .

Verify an EFI-bootable ISO has been created:

dumpet -i Custom1404.iso 

Outputs:

Validation Entry:
    Header Indicator: 0x01 (Validation Entry)
    PlatformId: 0x00 (80x86)
    ID: ""
    Checksum: 0x55aa
    Key bytes: 0x55aa
Boot Catalog Default Entry:
    Entry is bootable
    Boot Media emulation type: no emulation
    Media load segment: 0x0 (0000:7c00)
    System type: 0 (0x00)
    Load Sectors: 4 (0x0004)
    Load LBA: 3100 (0x00000c1c)
Section Header Entry:
    Header Indicator: 0x91 (Final Section Header Entry)
    PlatformId: 0xef (EFI)
    Section Entries: 1
    ID: ""
Boot Catalog Section Entry:
    Entry is bootable
    Boot Media emulation type: no emulation
    Media load address: 0 (0x0000)
    System type: 0 (0x00)
    Load Sectors: 4672 (0x1240)
    Load LBA: 1932 (0x0000078c)
5

Here is a shell script which performs this procedure, thanks for the introduction: http://www.utech.de/2013/05/shell-script-creating-a-cd-for-unattended-ubuntu-server-installations/

The script you find following the link basically implements the procedure that @Elazar described, so the essential parts are just a screen above. I added the link to save somebody some time, and to make it a bit easier to repeat this for other versions of Ubuntu.

5
  • 2
    Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – Oyibo
    May 14, 2013 at 21:15
  • 2
    I see. The script you find following the link basically implements the procedure that Elazar described, so the essential parts are just a screen above. I added the link to save somebody some time, and to make it a bit easier to repeat this for other versions of Ubuntu.
    – Michael
    May 14, 2013 at 21:24
  • 1
    Please add the explanation from your comment to your answer.
    – guntbert
    May 22, 2013 at 20:20
  • 4
    Link seems to be broken.
    – Reggie
    Jun 13, 2015 at 13:07
  • 3
    Where is the script now?
    – chicks
    Jun 27, 2016 at 21:15
1

A rather simple method is described at the following link to an answer at AskUbuntu,

How can I make a bootable, unattended USB restore disk?

  • Create the system that you want with portable network connection, for example according to

  • Make a [compressed] dd-image file of the system (I think this is easier than remastering).

  • Make a shellscript and call it via 'autostart' in a persistent live system according to this description. You can do it with minimal modifications (maybe match only the name of the compressed image file), or you can modify it to fit your particular case.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .