Custom preseed Ubuntu SERVER iso from usb

Last Modified: Thu, 03 May 2018 16:52:20 +0000 ; Created: Mon, 06 Nov 2017 22:32:55 +0000

I wanted a bootable USB that could install Ubuntu Server edition automatically. Normally I use a non-extracted iso method (i.e. casper), but that is only available with Ubuntu Desktop and not in the server iso.

So I used the following to create a bootable USB from the ubuntu-16.04.3-server-amd64.iso with a custom grub menuentry that runs the installer without any prompts (no language, keymap, etc. asked for just chosen).

  1. Setup a USB drive with dos partition table and FAT32 (type b) partition
  2. Ensure that vfat file system is setup (mkfs.vfat)
  3. Will assume /dev/sdX, but change instructions to match your drive
  4. mount /dev/sdX /mnt/sdX
  5. Do not use 7z x ubuntu-server-amd64.iso as it extracts isohybrid with corruption
  6. mkdir /mnt/iso
  7. mount -o ro,loop ~/Downloads/ubuntu-server-amd64.iso /mnt/iso/
  8. rsync -av /mnt/iso/ /mnt/sdX/
    • You can ignore the chmod permission errors, fat32 fs doesn't support them
  9. umount /mnt/iso/
  10. ls -la /mnt/sdX/
    • Verify that boot and the hidden .* directories from iso all appear
  11. grub-install --no-floppy --root-directory=/mnt/sdX /dev/sdX
    • Grub 2 (2.02) is required
  12. Modify /mnt/sdX/boot/grub/grub.cfg by *adding* at the top the content in the later section on this page
  13. Create the file /mnt/sdX/preseed/automated.cfg with the content from the later section
  14. umount /dev/sdX
  15. Boot from the usb and enjoy the customized auto-installer

/boot/grub/grub.cfg

set default=0
set timeout=2

menuentry "Auto-install Ubuntu Server" {
	set gfxpayload=keep
	linux	/install/vmlinuz  file=/cdrom/preseed/automated.cfg locale=en_US keymap=us quiet ---
	initrd	/install/initrd.gz
}

/preseed/automated.cfg

# Care of https://help.ubuntu.com/lts/installation-guide/amd64/apb.html


# These must also be set in the grub2.cfg boot line to avoid lang setting prompts
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us


d-i netcfg/get_hostname string unassigned-hostname

d-i netcfg/get_domain string unassigned-domain

d-i passwd/user-fullname string ubuntu
d-i passwd/username string ubuntu

d-i passwd/user-password-crypted password MmWbL6cJiRDbA

d-i user-setup/encrypt-home boolean false


d-i clock-setup/utc boolean true
d-i time/zone string UTC

# Leave it blank so the question is not asked
d-i mirror/http/proxy string

d-i pkgsel/update-policy select none


# Install the Ubuntu Server seed.
tasksel tasksel/force-tasks     string server

tasksel tasksel/first multiselect standard, openssh-server


# Disk related
# ============

# Regular partitioning, use the whole disk
d-i partman-auto/method string regular
d-i partman-auto/choose_recipe select atomic

# This makes partman automatically partition without confirmation, provided
# that you told it what to do using one of the methods above.
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

# Install to MBR
d-i grub-installer/only_debian boolean true



# Reboot without message asking user to confirm
d-i finish-install/reboot_in_progress note

Bonus Custom ISO Booting

https://askubuntu.com/questions/625286/how-to-create-uefi-bootable-iso

Above site has more up-to-date than Ubuntu Community Wiki page on how to build a custom iso with a preseed.

xorriso -as mkisofs \
  -isohybrid-mbr /usr/lib/syslinux/mbr/isohdpfx.bin \
  -c isolinux/boot.cat \
  -b isolinux/isolinux.bin \
  -no-emul-boot \
  -boot-load-size 4 \
  -boot-info-table \
  -eltorito-alt-boot \
  -e boot/grub/efi.img \
  -no-emul-boot \
  -isohybrid-gpt-basdat \
  -o /path/to/tmp.iso \
  /path/to/tmp