3

Today, I have an ISO that includes autoinstall, which installs my product foo. My userdaya.yml looks something like the following -

#cloud-config
autoinstall:
  version: 1
  identity:
    hostname: ubuntu-server
    password: "XXX"
    username: userfoobar
  late-commands:
    - cp -r /cdrom/copy_to_iso/ /target/opt/
  user-data:
    runcmd:
      - |
        mv -v /opt/copy_to_iso/foo_or_bar /opt/foo_or_bar
        bash -x /opt/foo_or_bar/install.sh foo

As you might notice, I pass the parameter foo to /opt/foo_or_bar/install.sh, and this script installs my product foo. I am looking for a way to dynamically install foo or bar based on the parameter I pass to the script /opt/foo_or_bar/install.sh. Where should I get the parameter from? From the grub menu, which today looks like this -

set timeout=30

loadfont unicode

set menu_color_normal=white/black set menu_color_highlight=black/light-gray

menuentry "Ubuntu FOO" { set gfxpayload=keep linux /casper/vmlinuz autoinstall ds=nocloud;s=/cdrom/nocloud/ --- initrd /casper/initrd } grub_platform if [ "$grub_platform" = "efi" ]; then menuentry 'Boot from next volume' { exit 1 } menuentry 'UEFI Firmware Settings' { fwsetup } else menuentry 'Test memory' { linux16 /boot/memtest86+.bin } fi

I wish to add something like this -

menuentry "Ubuntu BAR" {
    set gfxpayload=keep
    linux   /casper/vmlinuz   autoinstall   ds=nocloud\;s=/cdrom/nocloud/  ---
    initrd  /casper/initrd
}

If the user selects this option in the menu, it will install (by install.sh) bar, and not foo.

So my question is - is there a way to pass a parameter to autoinstall by the option selected in the grub menu?

Utz
  • 139
  • 3
  • 15

1 Answers1

5

My suggestion is to pass an argument to the kernel. The grub configuration would include something like

menuentry "Ubuntu FOO" {
    set gfxpayload=keep
    linux   /casper/vmlinuz   autoinstall   ds=nocloud\;s=/cdrom/nocloud/  foo ---
    initrd  /casper/initrd
}
menuentry "Ubuntu BAR" {
    set gfxpayload=keep
    linux   /casper/vmlinuz   autoinstall   ds=nocloud\;s=/cdrom/nocloud/  bar ---
    initrd  /casper/initrd
}

The kernel arguments are available in /proc/cmdline. This is a sample autoinstall snippet that shows how you can change behavior depending on which kernel argument was used.

#cloud-config
autoinstall:
  late-commands:
    - |
      if grep -q foo /proc/cmdline ; then
        touch /target/foo
      fi
      if grep -q bar /proc/cmdline ; then
        touch /target/bar
      fi
      true

notes

  • I tested using Ubuntu 22.04 (subiquity 22.04.2).