I've already been using an OVF template for recent Nextcloud builds so this is really just an evolution of that with the main difference being I'm using Ubuntu 24.04 LTS instead of Ubuntu 20.04 LTS, and of course the Nextcloud-specific stuff is not included in the base template.

In this step we create a virtual machine that will become our OVF Template and install Ubuntu server 24.04 LTS in it.

ESXi VM Definition

In terms of the VM definition this is just a cut down version of the VMs I've been using for Nextcloud which I covered in VM Template Creation part 1.

This is sized for creating the installation template and each VM created from this should be sized appropriately once they're built. The amount of CPU and RAM can easily be modified later if needed and even allocating additional disk space is relatively simple. In practice I've been able to reduce the RAM in most deployments although I've found no benefit to reducing below 2 vCPU - in fact some processes take significantly longer with a single vCPU and idle VMs consume minimal CPU resource.

VM Configuration
Item Value
Name X_U2404-base-2
Compatibility ESXi 7.0 U2
OS Family Ubuntu Linux (64-bit)
vCPU 2 (as 2 cores on 1 socket)
RAM 1.5 GB
Disks

2 local disks

Device SCSI Size Partitioning Usage
/dev/sda 0:0 8 GB GPT Boot & Root
/dev/sdb 0:1 1 GB GPT Swap
CD-ROM Datastore file : ubuntu-24.04.1-live-server-amd64.iso
SCSI VMware Paravirtual
Network 1 VMXNET 3, Sandpit
Options

Boot Options:

  • Firmware = EFI
  • Enable UEFI secure boot = ticked
  • Delay = 3000ms

The source VM was created in a sandbox network and I named it X_U2404-base-1 with the X_ prefix denoting it's not a "real" VM.

Ubuntu Server 24.04 LTS now installs in a "minimized" configuration by default which is missing man documents and some otherwise standard packages that Canonical consider unlikely to be needed on a pure server build and the effect is to reduce the size of the installation to about 1.5 GB. An unminimize script is also provided which will install the missing content. I've reduced the  the size of the system disk to 8 GB and so far the maximum utilisation has been 3.7 GB. Only time will tell if this proves to be sufficient or if I'll end up writing some resize playbooks. Not having man has been a mild annoyance at times but it only takes a few seconds with a search site to find the info so for me it's proving a good trade-off so far.

The second disk is intended for a swap partition. Using a partition instead of a file is supposedly faster and it this case it also means I can easily resize it up or down if needed by simply disabling swap, recreating the the disk at the new size then formatting and re-enabling it.

The CD-ROM is enabled during template creation for the Ubuntu installation and then removed before creating the OVF.

Ubuntu 24.04 Configuration

This is also very similar to the build Nextcloud servers, just with a simplified disk layout since the base image doesn't need additional data disks.

Item Configuration
Locale & Keyboard English (UK)
Type of Installation Ubuntu Server (minimized)
Guided Storage Custom storage layout (see filesystems below)
Initial User Created username and password
Ubuntu Pro Skip
SSH Configuration Install OpenSSH server, don't import any keys
Featured server snaps None selected

 

Filesystems
Device Format Filesytem Size
/dev/sda1 vfat /boot/efi 128 MB
/dev/sda2 ext4 /boot 384 MB
/dev/sda3 btrfs / 7.5 GB
/dev/sdb1 swap   1 GB

 

All the disks are created with GPT partitions by default since the VM is set to use EFI. I've also settled on always creating a partition even where I could use the raw disk such as /dev/sdc and /dev/sdd as it makes it obvious the disk is in use and what the filesystem is and also keeps options open for future changes. It does mean a bit more effort to extend but it's not something I expect to do very often and I'm reasonably confident I can automate some of that too.

The first partition to create is the 384 MB partition on /dev/sda for the /boot filesystem and the installer will automatically create a /dev/sda1 partition for /boot/efi set to 538 MB, but can (and should!) be edited down to 128 MB or even 64 MB in the disk configuration screen. Even this is still hugely oversized given it'll only contain about 6 MB of files and while you can configure smaller sizes anything less than 64 MB breaks the boot process. This leaves 7.5 GB for the root partition which is formatted with btrfs.

Using btrfs will allow the the use of snapshots for backup and it also allows disk partitions to shrink as well as expand. Unfortunately the Ubuntu installer still doesn't understand btrfs sub-volumes so setting that up is a post-installation task we need to complete. Another drawback of btrfs is performance with databases ranges from OK to stupidly slow so this base image is not suitable as-is for databases but we will create a child image later for that. Funnily enough it'll be very similar to the Nextcloud image this base is derived from.

Using a dedicated disk partition for swap is apparently faster than using a swap file and at least Ubuntu 24.04 doesn't try to create a swap file too. A server should be sized with enough RAM that it doesn't need swap, but from practical experience having some swap available as an emergency can make the difference between spotting a sizing issue during routine checks and having services randomly fail as the "out of memory killer" nukes services when real memory is exhausted. And it always seems to pick on application services who's failure is instantly obvious to users rather than minor ones that could restart with minimal impact.

Starting the VM in the ESXi Host Client takes you straight into the Ubuntu installer and the only fun part is configuring the filesystems since I don't use the standard build.

Install process for Ubuntu

Installing Ubuntu 24.04 is very similar to previous versions. With the Template VM configured to use the Ubuntu installer .ISO file, power on the VM in the ESXi Host Client and start a console session.

 

Ubuntu installer Grub screen

Select the Try or Install Ubuntu Server option or just wait until it starts automatically. Ubuntu will then start and take you into the Subiquity installer which will install and configure Ubuntu for you.

Ubuntu main language selection

The language selection screen now has a couple more to choose from but I'm still going with English (UK).

Option to download and switch to newer installer version

You can choose to use the latest version of the installer if you wish. I carried on without updating but it's your call.

Choose keyboard layout

Pick the keyboard layout and variant that you prefer. Again I'm going with English (UK) to match my keyboard.

Choose the installation type

The full Ubuntu Server option contains all the packages that Ubuntu consider as best for a server installation. The minimized version is a lot smaller as they've removed man and a lot of the diagnostic and other tools although you can of course add them yourself. While man is quite useful the same is available on the interwebs and most applications own --help output and worst case you can add all the removed components back in afterwards with the unminimize script.

Confirm network interface

Wait until our fledgling server install picks up an IP address. I only have IPv4 active on this sandpit network at the moment so it'll be interesting to see what happens once I get IPv6 enabled again. As soon as an address is allocated - which should only take a couple of seconds - select Done to continue.

Provide proxy details if needed

If you need to manually configure a proxy for internet access now is the time to do it, otherwise leave it blank and select Done to continue

Select default mirror for package installation

Choose the default location that apt will use for retrieving installation packages from. It will need to verify this but you can continue without doing so or if it fails completely due to network / proxy issues. You may have more issues later though so for the sake of a couple of minutes this is worth letting it complete the tests.

Choose standard or custom disk layout

And this is where we go a little bit off the beaten track and start doing our own thing. Pick Custom storage layout so we make our own filesystem and storage choices which are required for other customisations later.

Configure size and format of the /boot file system

Referring to the filesystems table in our design, the first one to be defined is the second on the list and will be a 384 MB ext4 filesystem for /boot. Pick the format and mount options from the options offered in each case and specify the size, not forgetting to include the M on the end. When you're ready highlight Create and select it.

Edit the ESP partition

The first partition for /boot/efi will be create for you, but with the crazy size of 538 MB. Navigate down to the partition 1 entry under Used Devices and hit return to bring up the config options for it and select Edit.

Choose a new more sensible size for the EFI System Partition

Select a more appropriate size for the EFI System Partition. While there is no official mimimum in the UEFI specs and it'll only end up with 6.1 MB of files in these VMs, in practical terms if you choose anything less than 64 MB then the VM won't actually boot even though the editor will quite happily let you pick just 8 MB. I chose 128 MB since together with a 384 MB for /boot that makes it a nice round number, but I may well change that in the next iteration.  You're stuck with fat32 of course since that is part of the UEFI spec. Make sure your size still ends with an M and click on save when you're finished editing.

Note: Other OS will have a different requirement, and possibly even Ubuntu under a different hypervisor or physical hardware will need more space.

/boot and /boot/efi now configured

You should now have the /boot and /boot/efi filesystems correctly specified. Navigate down to free space under /dev/sda on the available devices list and hit enter to add another partition

Create the root partition

We're going to allocate the rest of this disk to the root partition so we can leave the size blank. Set the format to btrfs and mount to / and then select Create when you're ready.

Back on the storage configuration screen navigate down to free space under /dev/sdb on the available device list and press enter to select it.

Create swap partition

Leave the size empty as we want to use all of /dev/sdb for our swap partition. Set format to swap and select Create when you're ready.

Verify the partition layout is as intended

You should now have your partition layout configured ready to be built. Check everything is as intended and make any corrections now, if you've really got messed up you can select Reset or even Back to clear out your settings and start again. If you're sure it's good then select Done.

Note: And yes, at this point in the write-up I realised I haven't collected new screenshots after downsizing the swap disk to 1 GB. Oops.

  Confirm everything has been correctly specified so farFormatting disks is destructive so you need to confirm if you're really sure if you want to go ahead. You'll not be able make any changes to the choices you've made so far after this point.

But since we're building a new VM with new virtual disks this really isn't an issue. And if you realise you've goofed then it's just a case of delete the VM and start again. So just click Continue with confidence and keep on going.

Create initial user for building the template VM

Ubuntu doesn't let you configure the root user during installation so you need to create first user that will have sudo rights and give it a sufficiently long password so it stays secure. During the configuration phase we'll create another user that will have an SSH key instead of a password, and even that user will be removed and replaced with the real admin users by the deployment playbooks. In case you haven't guessed I really don't like hardcoded credentials in templates and certainly don't like them being reused across multiple templates.

We also need to set a host name for this VM to use while it's being built and also for the first stage of deployment. This gets replaced at the start of the deployment process too.

Skip Ubuntu Pro

Ubuntu Pro is an extended support offering which has a free tier for personal use. Since this can be enabled later if you want to enroll a VM go with the Skip for now option, especially as enterprise users need to pay for each instance and personal users have a limited supply of free enrollments. Not something you'd want to burn through in a geek lab.

Enable SSH server

We also need to enable the OpenSSH server to allow remote access to the VM (and for all VMs that will be created from the template). As with the initial user creation we don't want to import any SSH keys now as we'll do that during the template configuration and of course the playbooks will configure keys for they admin users during deployment.

Ignore the feature snaps

We don't want any of these featured snaps in our template so just skip all of these and select Done.

Installation log showing success

The installation will then run and it'll write some minimal logging as to what it has done. Once it gives the Reboot Now option select it and the VM will restart and with any luck it'll boot into Ubuntu.

Successfully started template VM

 

The ESXi console should show the standard server login prompt with the version and template hostname we chose earlier. At this point it's worth shutting down the VM and taking a snapshot so that in something interesting happens during configuration you don't have to do it all over again.

In the next article we'll complete the configuration of our VM and export it to an OVF Template