Score:2

Pass parameters to Autoinstall

mh flag
Utz

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?

Score:3
jp flag

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).
Utz avatar
mh flag
Utz
Looks amazing! I'll check it in a few weeks. Thanks a lot!
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.