Unattended Ubuntu 20.04 Server Offline Installation

Last year, I wrote a post about how to install Ubuntu 18.04 Server automatically. The major reason why I choose to install the older version is I failed to make Ubuntu 20.04 install without pressing any key at that time while the approach for the offline installation recommended by the official is not working.

There is an article already described the detailed steps about the automatic installation of Ubuntu 20.04 Server, but according what its author said, their blog system ripped out some important characters. So, by checking with this script, I figured out the correct way to achieve our goal.

Download the image

Download the live CD image in whichever way you prefer. For the user locates in China, I would suggest you download from https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/focal/ubuntu-20.04.3-live-server-amd64.iso.

Update some files in ISO image

Only thing we need to do is updating several files. And here are some recommended editors.

  • For Windows user, I strongly recommend you use Ultraiso to edit the ISO file.
  • For Linux user, ISO Master should work. (I didn't try it before.)
  • For the user who wants to deeply customize the ISO file, including unpacking rootfs image, cubic is everything you need. You can refer to my previous post and learn how it works.

Add Kernel Arguments

Assume the root directory of ISO image is /cdrom. There are two bootloader configuration files need to modify, one for UEFI system, one for the legacy one. Append the kernel arguments like this,

  • /cdrom/isolinux/txt.cfg
1
2
3
4
label live
menu label ^Install Ubuntu Server
kernel /casper/vmlinuz
append initrd=/casper/initrd quiet autoinstall ds=nocloud;s=/cdrom/ ---
  • /cdrom/boot/grub/grub.cfg
1
2
3
4
5
menuentry "Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz quiet autoinstall ds=nocloud\;s=/cdrom/ ---
initrd /casper/initrd
}

If you would like to skip the integrity check, you could try to append the kernel argument fsck.mode=skip as the following example shows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# File: /cdrom/isolinux/txt.cfg

label live
menu label ^Install Ubuntu Server
kernel /casper/vmlinuz
append initrd=/casper/initrd quiet fsck.mode=skip autoinstall ds=nocloud;s=/cdrom/ ---

# File: /cdrom/boot/grub/grub.cfg

menuentry "Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz quiet fsck.mode=skip autoinstall ds=nocloud\;s=/cdrom/ ---
initrd /casper/initrd
}

Note: HWE Kernel is a higher version of Linux kernel compared to the default one, which is shipped with the newer drivers. Theoretically, it has a better support for the latest hardware.

Add Auto-install Configurations

Two new files are also required for automatic answering.

  • /cdrom/user-data

This configuration is what I am using now, and it is for the machine without Internet. I have verified that it can make the installation procedure fully automatic.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#cloud-config
autoinstall:
version: 1
storage: # should set the interactive default but doesn't seem to work??
layout:
name: direct
locale: en_US.UTF-8
keyboard:
layout: us
identity:
hostname: ubuntu-server
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
username: tonny
ssh:
allow-pw: true
install-server: true
package_update: false
package_upgrade: false

Note:

  • direct storage layout means using and erasing the whole disk. (The default option provided by the interactive installer.)
  • The password is ubuntu. This can be generated by mkpasswd.

For more usages, check this example.

  • /cdrom/meta-data

Just create an empty file and put it there.