1

the auto installation runs perfectly with customize user-data, but it won't auto reboot when install complete.

I find no documents about reboot in https://ubuntu.com/server/docs/install/autoinstall-reference

and I also find an article here http://junyelee.blogspot.com/2021/05/subiquity.html

# use interactive-sections to avoid an automatic reboot

and here is my user-data

#cloud-config
autoinstall:
  ### config storage and network manually
  interactive-sections:
    - storage
  # Swapfile on root volume
  swap:
    swap: 16GB
  late-commands:
    - curtin in-target --target=/target -- apt-get --purge -y --quiet=2 remove byobu
    - curtin in-target --target=/target -- apt-get install -y git wget curl rsync net-tools ssh ubuntu-desktop plymouth-theme-ubuntu-logo grub-gfxpayload-lists mailutils
    - curtin in-target --target=/target -- hostnamectl set-hostname ubuntu-jammy.abc.com
  # Write a script that can take care of some post install setup "late-commands" cannot be interactive unfortunately"
    - |
      cat <<EOF | sudo tee /target/etc/finish-install-setup.sh
      #!/usr/bin/env bash
      echo *************************
      echo ****  Finish Setup   ****
      echo *************************
      echo 'Enter the hostname for this system: '
      read NEW_HOSTNAME
      hostnamectl set-hostname \${NEW_HOSTNAME}
      echo
      echo 'Enter the timezone for this system: '
      echo 'Asia/Taipei'
      read NEW_TIMEZONE
      timedatectl set-timezone \${NEW_TIMEZONE}
      echo *************************
      echo
      echo *************************
      echo 'Restarting to finish ...'
      shutdown -r 3
      EOF
    - curtin in-target --target /target chmod 744 /etc/finish-install-setup.sh
  apt:
    disable_components: []
    geoip: true
    preserve_sources_list: false
    primary:
    - arches:
      - amd64
      - i386
      uri: http://free.nchc.org.tw/ubuntu
    - arches:
      - default
      uri: http://ports.ubuntu.com/ubuntu-ports
  drivers:
    install: false
  identity:
    hostname: ubuntu-jammy
    password: somesupersecretpasswordhere
    realname: administrator
    username: administrator
  kernel:
    package: linux-generic
  keyboard:
    layout: us
    toggle: null
    variant: ''
  locale: en_US.UTF-8
  network:
    ethernets:
      ens18:
        dhcp4: true
    version: 2
  ssh:
    allow-pw: true
    authorized-keys: []
    install-server: true
  ### user-data , commands run during first boot
  user-data:
    runcmd:
      - rm -rf  /usr/bin/python
      - ln -s /usr/bin/python3.10 usr/bin/python
      - wget https://download.nomachine.com/download/7.8/Linux/nomachine_7.8.2_1_amd64.deb -O /opt/nomachine.deb
      - dpkg -i /opt/nomachine.deb
      #- /etc/finish-install-setup.sh
  version: 1

I have to press enter at the end to reboot machine , which I don't think it's a good "automation".

But I need to configure storage layout manually , is there any solutions the force to reboot after the installation complete ?

1 Answers1

2

If you specify any interactive-sections then the installer (subiquity) considers the installation "interactive". If the installation is "interactive" then the installer will wait for the user to click Reboot when the installation is complete.

The simple way to reboot anyway is to use late-commands to call /sbin/reboot. The downside is that the installer does not get to finish, and any installation steps performed after late-commands will not happen. I believe the only step that will get skipped is copying the installer logs to the installed system.

#cloud-config
autoinstall:
  late-commands:
    - |
      /sbin/reboot

A more kludgy method is to simulate the Reboot click. The client subiquity process communicates this event to the server subiquity process using a socket at /run/subiquity/socket. Here is an example late-command that simulates the client communication so the server believes the user has requested a reboot. In this example the curl process will block, which is why it is run in the background using screen.

#cloud-config
autoinstall:
  late-commands:
    - |
      screen -dmS reboot curl --unix-socket /run/subiquity/socket -X POST http://a/shutdown?mode=%22REBOOT%22 --header "Content-Type:application/octet-stream"
      true

notes

I tested using Ubuntu 22.04 (subiquity 22.04.2)