Score:0

Autoinstall support both EFI and Legacy boot

mh flag
Utz

I'm trying to install Ubuntu 22.04 using Autoinstall. My generated ISO that includes userdata.yml (main autoinstall's file) has storage section, that should support both EFI and Legacy boot, but I cannot find a way to implement it.

Storage section in userdata.yml that supports only EFI boot:

  storage:
    config:
    - ptable: gpt
      path: /dev/sda
      wipe: superblock-recursive
      preserve: false
      name: ''
      grub_device: false
      type: disk
      id: disk-sda
    - device: disk-sda
      size: 1127219200
      wipe: superblock
      flag: boot
      number: 1
      preserve: false
      grub_device: true
      type: partition
      id: partition-0
    - fstype: fat32
      volume: partition-0
      preserve: false
      type: format
      id: format-0
    - device: disk-sda
      size: 1073741824
      wipe: superblock
      flag: ''
      number: 2
      preserve: false
      grub_device: false
      type: partition
      id: partition-1
    - fstype: ext4
      volume: partition-1
      preserve: false
      type: format
      id: format-1
    - device: disk-sda
      size: 54760833024
      wipe: superblock
      flag: ''
      number: 3
      preserve: false
      grub_device: false
      type: partition
      id: partition-2
    - name: myvg
      devices:
      - partition-2
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - name: slashlv
      volgroup: lvm_volgroup-0
      size: 53687091200B
      wipe: superblock
      preserve: false
      type: lvm_partition
      id: lvm_partition-0
    - fstype: ext4
      volume: lvm_partition-0
      preserve: false
      type: format
      id: format-2
    - path: /
      device: format-2
      type: mount
      id: mount-2
    - path: /boot
      device: format-1
      type: mount
      id: mount-1
    - path: /boot/efi
      device: format-0
      type: mount
      id: mount-0

Storage section in userdata.yml that supports only Legacy boot:

  storage:
    config:
    - ptable: gpt
      path: /dev/sda
      wipe: superblock-recursive
      preserve: false
      name: ''
      grub_device: true
      type: disk
      id: disk-sda
    - device: disk-sda
      size: 1048576
      flag: bios_grub
      number: 1
      preserve: false
      grub_device: false
      type: partition
      id: partition-0
    - device: disk-sda
      size: 1073741824
      wipe: superblock
      flag: ''
      number: 2
      preserve: false
      grub_device: false
      type: partition
      id: partition-1
    - fstype: ext4
      volume: partition-1
      preserve: false
      type: format
      id: format-1
    - device: disk-sda
      size: 54760833024
      wipe: superblock
      flag: ''
      number: 3
      preserve: false
      grub_device: false
      type: partition
      id: partition-2
    - name: myvg
      devices:
      - partition-2
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - name: slashlv
      volgroup: lvm_volgroup-0
      size: 53687091200B
      wipe: superblock
      preserve: false
      type: lvm_partition
      id: lvm_partition-0
    - fstype: ext4
      volume: lvm_partition-0
      preserve: false
      type: format
      id: format-2
    - path: /
      device: format-2
      type: mount
      id: mount-1
    - path: /boot
      device: format-1
      type: mount
      id: mount-0

My failure when I'm trying to install EFI with userdata.yml that supports only legacy boot (and the opposite) -

2022-11-03 09:48:37,448 ERROR root:39 finish: subiquity/Filesystem/apply_autoinstall_config: FAIL: autoinstall config did not create needed bootloader partition
2022-11-03 09:48:37,448 ERROR root:39 finish: subiquity/apply_autoinstall_config: FAIL: autoinstall config did not create needed bootloader partition

Again, I need to support both EFI and Legacy boot, in the same userdata.yml file.

Thanks!

David avatar
cn flag
Am I misreading this you have the exact same info twice. From your question "Storage section in userdata.yml that supports only EFI boot:" this and the post after seems to be exactly the same .
Utz avatar
mh flag
Utz
I just wrote EFI twice, the yml is a bit different. Thanks!
Score:2
jp flag

Officially, you can't create a single storage config that supports both BIOS and UEFI. The grub_device settings are incompatible. Quoting from one of the installer (subiquity) developers

Yes, probably. I actually wanted to clean this whole area up and make the config saner (for example, it really ought to be possible to install a system that will boot both legacy and UEFI) but it doesn’t look like I’m going to get around to that any time soon…

As a workaround, early-commands can be used to make a single config work. Here is a sample user-data snippet that I have used. It will modify the /autoinstall.yaml file depending on the existence of /sys/firmware/efi.

#cloud-config
autoinstall:
  storage:
    config:
    - type: disk
      match:
        size: largest
      ptable: gpt
      preserve: false
      name: ''
      grub_device: true
      id: disk-sda
    - type: partition
      device: disk-sda
      size: 4194304
      wipe: superblock
      flag: bios_grub
      number: 14
      preserve: false
      grub_device: false
      id: partition-14
    - type: partition
      device: disk-sda
      size: 111149056
      wipe: superblock
      flag: boot
      number: 15
      preserve: false
      grub_device: UEFI
      id: partition-15
    - type: partition
      device: disk-sda
      size: -1
      wipe: superblock
      number: 1
      preserve: false
      grub_device: false
      id: partition-1
    - type: format
      fstype: ext4
      volume: partition-1
      preserve: false
      id: format-1
    - type: mount
      path: /
      device: format-1
      id: mount-1
    - type: format
      fstype: fat32
      volume: partition-15
      preserve: false
      id: format-15
    - type: mount
      path: /boot/efi
      device: format-15
      id: mount-15
  early-commands:
    - |
      if [ -e "/sys/firmware/efi" ]; then
        sed -i -e "s/grub_device: UEFI/grub_device: true/" /autoinstall.yaml
      else
        sed -i -e "s/grub_device: UEFI/grub_device: false/" /autoinstall.yaml
      fi
      true

With this snippet all devices will end up with the same partition layout, which could be confusing. For example, a BIOS based machine will still end up with an unnecessary ESP partition mounted at /boot/efi, and a UEFI based machine will have an unnecessary bios_grub partition.

The cloud images have a partition layout that was used as inspiration for this config. The cloud images support both BIOS and UEFI and I wanted to duplicate that. The resulting partition table looks like this, where the final partition fills the disk.

Partition Table: gpt
Disk Flags:

Number  Start    End       Size      File system  Name  Flags
 1      1.00MiB  5.00MiB   4.00MiB                      bios_grub
 2      5.00MiB  111MiB    106MiB    fat32              boot, esp
 3      111MiB   20479MiB  20368MiB  ext4
Utz avatar
mh flag
Utz
Can you please clarify in my example of `user-data` what should be added in the `early-commands` section? Thanks a lot!
Score:0
mh flag
Utz

Solution:

I deleted the whole storage section in user-data; The default autoinstall "knows" how to deal with it whether you are running in a UEFI system or a Legacy BIOS.

Note: It creates the following as default -

/boot - 2g
(If UEFI) /boot/efi - 1g±
/ - as LVM - 100g, or if your disk is less than 100g, it creates it with about 70% of the disk's size.
VG name - ubuntu-vg
LV name (that mounted to /) - ubuntu-lv
Andrew Lowther avatar
jp flag
If you delete the whole `storage` config then the installer (subiquity) will use an `lvm` `layout` configuration [by default](https://github.com/canonical/subiquity/blob/c03b23d7e4aa66a25252a1de1578c5ab099f1667/subiquity/server/controllers/filesystem.py#L142).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.