Ubuntu22 partition template with optional disk

I’m using foreman 3.6.1 to provision ubuntu 22.04 on hosts with autoinstall template through host group assignment.
everything working as expected but i want to automate setup of secondary disk if available,
currently i’m doing installation on the smallest disk by match spec-

    - type: disk
        size: smallest

i want to be able to partition secondary disk if available, adding another match will fail the installation if no match found.

is there a way to make a condition in partition template based on the number of disks on the provisioned system? is it possible on general to get information on the host before or during templates rendering?

with kickstart i can do some detection and adjustments in %pre , maybe there is some equivalent with foreman/ubuntu autoinstall?

Hey @nvno!

I’m happy to hear that Ubuntu deployment works fine for you.

Regarding the optional disk configuration: I see two ways this could work.

a) During the installation, Ubuntu Autoinstall recognizes that it is an optional disk and doesn’t stop the installation in case the secondary disk is not found.
b) Foreman figures there is/is not a secondary disk and prepares the userdata Autoinstall template accordingly.

For a), you should consider the Ubuntu forum, in the Autoinstall doc, or the curtin doc.

For b) I don’t know of a way that Foreman itself could recognize the available number of disks for your host - so, it might not be possible to configure this during the host deployment.
But, if you know it beforehand you could just use a different partition table with a second host group (that inherits all parameters from your original hostgroup, but changes the partition table)

I hope this helps!

@bastian-src thanks.
i ended up adding my own snippet to finish.sh which run in late-commands using curtin.

1 Like

Can you maybe share the snippet or consider making a Pull Request?
It sounds like a very useful extension!

i’m not sure it’s generic enough to be used as is for everyone but it might be good starting point for some.
it’s running inside the target chroot through the finish.sh script that run in late-commands:

  • curtin in-target – /tmp/finish.sh

so it will need the package “gdisk” to to be installed(can be done in “packages:” stage).

this is the actual script-

if [ "$(lsblk -ldnb -I 8,259 -o NAME |wc -l)" -ge "2" ] ; then 
    echo "Found multiple disks, formating data disk..."
    #ROOT DISK    
    MYROOT=$(lsblk -no PKNAME /dev/$(findmnt -uno SOURCE / |awk -F/ '{print $NF}'))
    #Extra DISK
    DISK2=$(lsblk -ldnb -I 8,259 -o NAME -x SIZE |grep -v $MYROOT | head -1 )

    #Destroy old Partition table.
    sgdisk -Z /dev/${DISK2}
    #Create partition that fill the disk
    sgdisk -N 0 /dev/${DISK2}
    #Change partition type(LINUX)
    sgdisk -t 0:8300 /dev/${DISK2}

    #format new partition
    NEWPART=$(lsblk -lnp -o NAME,TYPE /dev/${DISK2} |grep part |head -1 | cut -d" " -f1)
    mkfs.ext4 -F $NEWPART
    NEWUUID=$(blkid -o value -s UUID $NEWPART)
    echo "UUID=$NEWUUID /data ext4 defaults 0 1" >> /etc/fstab
    #Set mount Permissions
    mkdir /data
    mount $NEWPART /data
    chmod 1777 /data
1 Like

@Bernhard_Suttner Do you have any suggestions on this one?