Skip to content

Instantly share code, notes, and snippets.

@dbkinghorn
Created September 28, 2021 21:49
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dbkinghorn/c236aea31d76028b2b6ccdf6d3c6f07e to your computer and use it in GitHub Desktop.
Save dbkinghorn/c236aea31d76028b2b6ccdf6d3c6f07e to your computer and use it in GitHub Desktop.
Ubuntu 20.04 user-data files for autoinstall ISO
#cloud-config
autoinstall:
version: 1
refresh-installer: # start with an up-to-date installer
update: yes
interactive-sections: # Install groups listed here will wait for user input
- storage
storage: # should set the interactive default but doesn't seem to work??
layout:
name: direct
locale: en_US.UTF-8
keyboard:
layout: us
identity: # This is section you may want to add to interactive-sections (user name and password are ubuntu here)
hostname: puget-000
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
username: ubuntu
ssh:
allow-pw: true
install-server: true
apt:
sources:
ignored1: # This is here to get the yaml formatting right when adding a ppa
source: ppa:graphics-drivers/ppa
packages:
- build-essential
- network-manager
- dkms
- emacs-nox
- ubuntu-desktop-minimal
package_update: true
package_upgrade: true
late-commands:
# Changing from networkd to NetworkManager
# move existing config out of the way
- find /target/etc/netplan/ -name "*.yaml" -exec sh -c 'mv "$1" "$1-orig"' _ {} \;
# Create a new netplan and enable it
- |
cat <<EOF | sudo tee /target/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: NetworkManager
EOF
- curtin in-target --target /target netplan generate
- curtin in-target --target /target netplan apply
- curtin in-target --target /target systemctl enable NetworkManager.service
# 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 'America/Los_Angeles America/Denver America/Chicago America/New_York'
# 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
- cp /target/cdrom/extras/Puget_Systems.png /target/usr/share/backgrounds/
user-data: # Commands here run during first boot (cannot be interactive)
runcmd:
# Install the NVIDIA driver from the ppa we setup earlier
- [apt-get, update]
- [apt-get, dist-upgrade, --yes]
- [apt, autoremove, --yes]
- [apt-get, install, --yes, nvidia-driver-470] #, --no-install-recommends]
- [sudo, -u, ubuntu, dbus-launch, gsettings, set, org.gnome.desktop.background, picture-uri, file:///usr/share/backgrounds/Puget_Systems.png]
# - |
# #!/usr/bin/env bash
# echo ''
# echo '***************************************'
# echo ' To complete install setup please run, '
# echo ' sudo /etc/finish-install-setup.sh'
# echo '***************************************'
# echo ''
#cloud-config
autoinstall:
version: 1
refresh-installer: # start with an up-to-date installer
update: yes
interactive-sections: # Install groups listed here will wait for user input
- storage
storage: # should set the interactive default but doesn't seem to work??
layout:
name: direct
locale: en_US.UTF-8
keyboard:
layout: us
identity: # This is section you may want to add to interactive-sections (user name and password are ubuntu here)
hostname: puget-000
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
username: ubuntu
ssh:
allow-pw: true
install-server: true
apt:
sources:
ignored1: # This is here to get the yaml formatting right when adding a ppa
source: ppa:graphics-drivers/ppa
packages:
- build-essential
- network-manager
- dkms
- emacs-nox
#- ubuntu-desktop-minimal^
package_update: true
package_upgrade: true
late-commands:
# Changing from networkd to NetworkManager
# move existing config out of the way
- find /target/etc/netplan/ -name "*.yaml" -exec sh -c 'mv "$1" "$1-orig"' _ {} \;
# Create a new netplan and enable it
- |
cat <<EOF | sudo tee /target/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: NetworkManager
EOF
- curtin in-target --target /target netplan generate
- curtin in-target --target /target netplan apply
- curtin in-target --target /target systemctl enable NetworkManager.service
# 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 'America/Los_Angeles America/Denver America/Chicago America/New_York'
# 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
- ls -l > /target/root/ls.out
- pwd > /target/root/pwd.out
- mount > /target/root/mount.out
- touch afile
- cp afile /target/root/
- ls -l / > /target/root/ls-root.out
- ls -l /target > /target/root/ls-target.out
- ls -l /target/cdrom > /target/root/ls-target-cdrom.out
user-data: # Commands here run during first boot (cannot be interactive)
runcmd:
# Install the NVIDIA driver from the ppa we setup earlier
- [apt-get, install, --yes, nvidia-driver-470, --no-install-recommends]
- |
#!/usr/bin/env bash
echo ''
echo '***************************************'
echo ' To complete install setup please run, '
echo ' sudo /etc/finish-install-setup.sh'
echo '***************************************'
echo ''
@zero-pytagoras
Copy link

Does cloud-init (c-i) allow adding and installing from other repositories at initilal install with a yaml like yours?
yes: you can add apt tag with address to your repository e.g.

apt:
    sources:
        source: deb.address.to.your.repo

@vgervais
Copy link

Thanks for the info @zero-pytagoras

@finalls
Copy link

finalls commented Apr 28, 2022

Hello, @zero-pytagoras !
ROOT_DEV is a variable that i am substituting with sed with shell script that am running with early-commands of cloud-init.
Could you tell me more about how to use this variable and give me please some examples of it.
Thank you very much!

@zero-pytagoras
Copy link

I am using shell script that runs sed command to substitute the ROOT_DEV as part of early_commands tags.
essentially i run this script

ROOT_DEV=$(lsblk -x TYPE|grep disk|awk '{print $1}')

sed -i 's/ROOT_DEV/${ROOT_DEV}/g'

as part of user-data file

- early-commands:
  - swap-drive-name.sh  

for my use case that was good enough, but might not suit a system where you have more then one drive

@vgervais
Copy link

vgervais commented May 2, 2022

@zero-pytagoras: After I have successfully added the repo, how do I update it, or install the software from it? In my case, I want to install the latest postgresql-client.

@finalls
Copy link

finalls commented May 2, 2022

Hello, @zero-pytagoras !
What file do you change seed to make to work the variable in the config section?
let's give an example, it doesn't work

#cloud-config
autoinstall:
  version: 1
  early-commands:
    - /bin/bash /tmp/hdd.sh
    - /usr/bin/echo "Disk for install - $DISK"

  storage:
    layout:
      name: lvm
      match:
        path: $DISK

Thank you very much!

@zero-pytagoras
Copy link

@vgervais
use tag packages and add to it list of packages you would like to install, for example:

apt:
  repo: link-toyour-repo
packages:
  - ipython
  - postgresql-client

@zero-pytagoras
Copy link

@finalls
not sure i understand what you are trying to do. who is giving you value of $DISK ?
in my case i used early-commands to run script and to edit with sed the user-data file itself. kind of editing script from i am running myself

@vgervais
Copy link

@zero-pytagoras Thanks for the info. My yaml is now working 100%.

@sedasdas
Copy link

@zero-pytagoras Thanks for the info. My yaml is now working 100%.

@finalls not sure i understand what you are trying to do. who is giving you value of ? in my case i used to run script and to edit with the user-data file itself. kind of editing script from i am running myself$DISK``early-commands``sed

#cloud-config
autoinstall:
early-commands:
- ROOT_DEV=$(lsblk -x TYPE|grep disk|grep G|awk '{print $1}')
it is my script , but the ROOT_DEV does not worker ? why

@zero-pytagoras
Copy link

because it is yaml - it can not run shell scripts directly.
you need to run it separate file/script and redirect its value to your current user-data file

@Bartsch462
Copy link

@zero-pytagoras
I'm also trying to define a path using a script in the early commands. Would you know which user-data file to edit with sed so that it is used in the installation? I've tried some of the files in
/var/lib/cloud/instances/nocloud and /var/lib/cloud/instance
but I've had no luck yet.

@zero-pytagoras
Copy link

the default file to be update needs to /automation, but you could test it on failed run.

@Bartsch462
Copy link

the default file to be update needs to /automation, but you could test it on failed run.

I needed to update the /autoinstall.yaml but thanks a lot for pointing me in the right direction! Works great now!

@smahm006
Copy link

Thank you so much for this template.

@andycui66
Copy link

andycui66 commented Oct 14, 2022

I am trying to build an ISO that compatible with two different environments. One has to enable network in interactive-sections, one without. Can I do it my create different entry in the grub file.

The grub file might look like

menuentry "Manual network config" {
        set gfxpayload=keep
        linux   /casper/hwe-vmlinuz   quiet  autoinstall ds=nocloud\;s=/cdrom/nocloud/ ---
        initrd  /casper/hwe-initrd
}

menuentry "Auto network config" {
        set gfxpayload=keep
        linux   /casper/hwe-vmlinuz   quiet  autoinstall ds=nocloud\;s=/cdrom/nocloud/ ---
        initrd  /casper/hwe-initrd
}

When user choose Manual network config the user-data file would have

interactive-sections:
    - network

Is there a way to make it work? I need to create some param and pass it to user-data file to control how the install works.

@zero-pytagoras
Copy link

what you need is different files for different scenarious. Meaning cloud-config.yaml file needs to be replicatrd and networking section changed per use case, as well as grub file to link the required file.

@andycui66
Copy link

Thanks, I guess the solution would be two different ISO. Cannot do the fancy stuff.

@zero-pytagoras
Copy link

Not at all. It is possible to setup one iso with all the required things. I am traveling, but should be able to post later this week a solution.

@dbkinghorn
Copy link
Author

I'll add this even thought it's a late reply ... adding more configs to the ISO is simple.
You are halfway there by making the 2 menu entries. What you want is to use 2 different directories for the differing user-data and meta-data files.
instead of using
s=/cdrom/nocloud/
try
s=/cdrom/manual-net/ for the first menu stanza
and
s=/cdrom/auto-net/ for the second menu stanza
Then add the different user-data files to each of those.
When you make your ISO you will have the menu choice and each will load the appropriate user-data file

@jnlickey
Copy link

jnlickey commented Jan 4, 2023

Can someone tell me why the following grub.cfg will not work? It should be able to pick-up the user-data file in /cdrom/server. However, instead of booting and running the auto-install it defaults to the Ubuntu walk-through (manual) menu.

if loadfont /boot/grub/font.pf2 ; then
	set gfxmode=auto
	insmod efi_gop
	insmod efi_uga
	insmod gfxterm
	terminal_output gfxterm
fi

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

set timeout=5

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

grub_platform
if [ "$grub_platform" = "efi" ]; then
menuentry 'Boot from next volume' {
	exit 1
}
menuentry 'UEFI Firmware Settings' {
	fwsetup
}
fi

submenu 'Boot and Install with the HWE kernel' {

menuentry "Install Ubuntu Server" {
	set gfxpayload=keep
	linux	/casper/hwe-vmlinuz   quiet  ---
	initrd	/casper/hwe-initrd
}
}

/cdrom/server/user-data file:

#cloud-config
# Helpful sights:
#        https://louwrentius.com/understanding-the-ubuntu-2004-lts-server-autoinstaller.html
#        https://www.edwardssite.com/cloud-init
#        https://ubuntu.com/server/docs/install/autoinstall-referencie#commandlist
#        https://www.convertunits.com/from/bytes/to/MB
#        https://www.pugetsystems.com/labs/hpc/how-to-make-ubuntu-autoinstall-iso-with-cloud-init-2213
autoinstall:
  version: 1
  refresh-installer:
  update: yes
  interactive-sections:
  keyboard: {layout: 'us', variant: ''}
  locale: en_US.UTF-8

  # Identification
  identity:
    hostname: ubuntu-test
    username: ubuntu
    password: <password-hash>
  ssh:
    allow-pw: true
    install-server: true

  # Storage Information
  storage:
    config:
    # Find Disk, Partition Boot/EFI, and wipe clean (268435456 = 256MB, 536870912 = 512MB)
    - {grub_device: true, id: disk-sda, name: '', path: /dev/sda, preserve: false, ptable: gpt, type: disk, wipe: superblock-recursive}
    - {device: disk-sda, flag: bios_grub, grub_device: false, id: partition-0, number: 1, preserve: false, size: 1048576, type: partition}
    - {device: disk-sda, flag: '', grub_device: false, id: partition-1, number: 2, preserve: false, size: 536870912, type: partition, wipe: superblock}
    - {fstype: ext4, id: format-0, preserve: false, type: format, volume: partition-1}
    - {device: disk-sda, flag: '', grub_device: false, id: partition-2, number: 3, preserve: false, size: 134217728, type: partition, wipe: superblock}
    - {fstype: ext4, id: format-1, preserve: false, type: format, volume: partition-2}
    # Create SWAP space and mount it (2147483648 = 2GB)
    - {device: disk-sda, flag: swap, grub_device: false, id: partition-3, number: 4, preserve: false, size: 2147483648, type: partition, wipe: superblock}
    - {fstype: swap, id: format-2, preserve: false, type: format, volume: partition-3}
    - {device: format-2, id: mount-2, path: '', type: mount}
    # Create LVM Group from remaining disk space
    - {device: disk-sda, flag: '', grub_device: false, id: partition-4, number: 5, preserve: false, size: -1, type: partition, wipe: superblock}
    - devices:
      - partition-4
      id: lvm_volgroup-0
      name: vgroot
      preserve: false
      type: lvm_volgroup

    # Create LVM Filesystems
    # /
    - {id: lvm_partition-0, name: FS_root, preserve: false, size: 4290772992B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-5, preserve: false, type: format, volume: lvm_partition-0}
    # /home
    - {id: lvm_partition-1, name: FS_home, preserve: false, size: 2147483648B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-6, preserve: false, type: format, volume: lvm_partition-1}
    # /var
    - {id: lvm_partition-2, name: FS_var, preserve: false, size: 2147483648B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-7, preserve: false, type: format, volume: lvm_partition-2}
    # /opt
    - {id: lvm_partition-4, name: FS_opt, preserve: false, size: 1073741824B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-8, preserve: false, type: format, volume: lvm_partition-4}
    # /tmp
    - {id: lvm_partition-5, name: FS_tmp, preserve: false, size: 1073741824B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-9, preserve: false, type: format, volume: lvm_partition-5}
    # /usr
    - {id: lvm_partition-6, name: FS_usr, preserve: false, size: 6242450944B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-10, preserve: false, type: format, volume: lvm_partition-6}
    # /var/log
    - {id: lvm_partition-3, name: FS_var_log, preserve: false, size: 2147483648B, type: lvm_partition, volgroup: lvm_volgroup-0}
    - {fstype: ext4, id: format-11, preserve: false, type: format, volume: lvm_partition-3}

    # Mount Storage devices
    - {device: format-0, id: mount-0, path: /boot, type: mount}
    - {device: format-1, id: mount-1, path: /boot/efi, type: mount}
    - {device: format-5, id: mount-5, path: /, type: mount}
    - {device: format-6, id: mount-6, path: /home, type: mount}
    - {device: format-7, id: mount-7, path: /var, type: mount}
    - {device: format-8, id: mount-8, path: /opt, type: mount}
    - {device: format-9, id: mount-9, path: /tmp, type: mount}
    - {device: format-10, id: mount-10, path: /usr, type: mount}
    - {device: format-11, id: mount-11, path: /var/log, type: mount}

  # Post-install packages to download and include
  packages:
    - vim
    - curl
    - wget
    - openssh-server
    - perl
    - open-vm-tools

  # Commands to complete after installation
  late-commands:
    - mkdir /tmp/mnt
    - mount /dev/sr0 /tmp/mnt
    - curtin in-target --target=/target -- touch /etc/cloud/cloud-init.disabled
    - mkdir /target/DockerInstall
    - cp /tmp/mnt/daemon.json /target/DockerInstall/daemon.json
    - cp /tmp/mnt/DockerInstall.sh /target/DockerInstall/DockerInstall.sh
    - chmod 777 /target/DockerInstall/DockerInstall.sh
    - echo '@reboot root /usr/bin/sleep 30 && /DockerInstall/DockerInstall.sh' | sudo tee /target/etc/cron.d/docker-install
    - cp /tmp/mnt/01-config.yaml /target/etc/netplan/01-config.yaml
    - cp /tmp/mnt/99-custom-network-test /target/etc/update-motd.d/99-custom-network-test
    - sed -i 's/^#DNS\=/DNS\=/g;s/^#Fall/Fall/g;s/^#Domains\=/Domains\=/g' /target/etc/systemd/resolved.conf
    - sed -i '/^DNS\=/ s/$/192.16.0.53/' /target/etc/systemd/resolved.conf
    - sed -i '/^Fall.*\=/ s/$/192.16.0.54/' /target/etc/systemd/resolved.conf
    - sed -i '/^Domains\=/ s/$/ad.example.com. example.com./' /target/etc/systemd/resolved.conf
    - echo "ansible ALL=(ALL:ALL) NOPASSWD:ALL" > /target/etc/sudoers.d/ansible_admin
    - chmod 0440 /target/etc/sudoers.d/ansible_admin
    - curtin in-target --target=/target -- /usr/sbin/useradd -m -c "Ansible Account" -s /bin/bash -G sudo -p <password> ansible
    - curtin in-target --target=/target -- mkdir /home/ansible/.ssh
    - curtin in-target --target=/target -- chmod 0700 /home/ansible/.ssh
    - curtin in-target --target=/target -- touch /tmp/authorized_keys
    - curtin in-target --target=/target -- install -o ansible -g ansible -m 0600 /tmp/authorized_keys -t /home/ansible/.ssh
    - echo "ssh-rsa <SSH PUBLIC KEY> >> /target/home/ansible/.ssh/authorized_keys
    - curtin in-target --target=/target -- chown -R ansible:ansible /home/ansible/
    - curtin in-target --target=/target -- /usr/sbin/useradd -m -c "Ubuntu Account" -s /bin/bash -p '<password>' Ubuntu
    - curtin in-target --target=/target -- timedatectl set-timezone America/Chicago

  # Process to restart the server after build completes
  user-data:
    timezone: America/Chicago
    disable_root: false
    power_state:
      mode: reboot
      condition: true

During UEFI boot I get the grub menu prompt for Auto Install, I wait for the timer to expire, and then after cloud init messages appear I get
waiting for cloud-init and then an error occurred appears. I believe this is when the user-data file is trying to be found but, it's not being seen.

I would also like to get this to work with BIOS (non-UEFI) boot. Which currently just goes straight to the default Ubuntu menu for installation starting with languages.

I'm currently trying to follow along with this websites suggestions for UEFI and BIOS boot.
https://utcc.utoronto.ca/~cks/space/blog/linux/Ubuntu2004ISOWithUEFI-2

@dbkinghorn
Copy link
Author

Hi Jon,
I don't see any obvious errors. A couple of things to try;
Validate your user-data file against the JSON schema

sudo apt-get install cloud-init
cloud-init devel schema --config-file user-data

If there are any errors in the yaml, cloud-init will not start

You might also want to try testing with a very simple user-data file. Maybe just hostname: and identity: Get that working before adding more components to the file.

Debugging this stuff can be a real headache! I hope these suggestions help

@dbkinghorn
Copy link
Author

I just thought of something ... I've been working with 22.04 (as we exchanged messages I have had it in my head that you were using 22.04 not 20.04!)

20.04 has isolinux (that was removed and everything was moved to GPT and partition images in 22.04)
I think you may still need to add a modified txt.cfg into the isolinux dir. I'm completely sure if you need this but it's worth a try. [This would be more like what I did in the post from last September]

The txt.cfg file would start something like,

default autoinstall-server
label autoinstall-server
menu label ^Autoinstall Server
kernel /casper/vmlinuz
append initrd=/casper/initrd quiet autoinstall ds=nocloud;s=/cdrom/server/ ---

@zero-pytagoras
Copy link

yes - on ubuntu20.04, you still need to fix txt.cfg file for boot to work.

@zero-pytagoras
Copy link

@jon
from what i was able to automate, you either can set bios or gpt but not both at the same time.

@jnlickey
Copy link

jnlickey commented Jan 5, 2023

Checking the same user-data file as above I get this:

$ cloud-init schema -h
usage: /usr/bin/cloud-init schema [-h] [-c CONFIG_FILE] [--system] [-d DOCS [DOCS ...]] [--annotate]

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        Path of the cloud-config yaml file to validate
  --system              Validate the system cloud-config userdata
  -d DOCS [DOCS ...], --docs DOCS [DOCS ...]
                        Print schema module docs. Choices: all or space-delimited cc_names.
  --annotate            Annotate existing cloud-config file with errors

$ cloud-init schema --config-file ./server/user-data
Valid cloud-config: user-data

Here's my ./isolinux/txt.cfg file:

$ ls -lah ./isolinux/txt.cfg
-rw-rw-r-- 1 myuser mygroup 627 Jan  4 13:13 ./isolinux/txt.cfg

$ cat ./isolinux/txt.cfg 
default autoinstall-server
label autoinstall-server
  menu label ^Autoinstall Server
  kernel /casper/vmlinuz
  append   initrd=/casper/initrd quiet autoinstall fsck.mode=skip ds=nocloud\;s=/cdrom/server/ ---
label live
  menu label ^Install Ubuntu Server
  kernel /casper/vmlinuz
  append   initrd=/casper/initrd quiet  ---
label hwe-live
  menu label ^Install Ubuntu Server with the HWE kernel
  kernel /casper/hwe-vmlinuz
  append   initrd=/casper/hwe-initrd quiet  ---
label memtest
  menu label Test ^memory
  kernel /install/mt86plus
label hd
  menu label ^Boot from first hard disk
  localboot 0x80

@bashadude
Copy link

Hi @dbkinghorn can you guide me to autoinstall of ubuntu22.04 & also ping me working user data file. please help me out i have tried of so many nothing is not working.

@dbkinghorn
Copy link
Author

My most recent work on this stuff is;
https://www.pugetsystems.com/labs/hpc/ubuntu-22-04-server-autoinstall-iso/

There should be some helpful info in the comments too.
People have been having trouble with MBR vs GPT partitions. What I have in the post worked when I did it but I haven't revisited it since.
I do have a need to build another ISO. Probably this week. I'll be using my own post as a guide. If I encounter anything that doesn't work right now, I will update the post and add comments.

I do empathize with folks that have trouble! I feel this is needlessly difficult for something that, in my opinion, should be clearly documented and facilitated by the distribution provider. On the other hand, it is open source, so we are all in it together to make things better :-)

@bashadude
Copy link

My most recent work on this stuff is; https://www.pugetsystems.com/labs/hpc/ubuntu-22-04-server-autoinstall-iso/

There should be some helpful info in the comments too. People have been having trouble with MBR vs GPT partitions. What I have in the post worked when I did it but I haven't revisited it since. I do have a need to build another ISO. Probably this week. I'll be using my own post as a guide. If I encounter anything that doesn't work right now, I will update the post and add comments.

I do empathize with folks that have trouble! I feel this is needlessly difficult for something that, in my opinion, should be clearly documented and facilitated by the distribution provider. On the other hand, it is open source, so we are all in it together to make things better :-)

Hi @dbkinghorn
I am also facing MBR and GPT issues. Can you tell me when you build another iso or ping in this blog. I am waiting for your post. Also i am facing subiquity/Errorreporter/162334394239423.block_probe_fail : written to /var/crash
image

Thank you so much

@dbkinghorn
Copy link
Author

I ran through the procedure this morning and created ISO bootable from MBR and UEFI using the new install image Ubuntu server 22.04.2

Everything worked fine. Main thing is to be very careful about formating files. YAML is very picky!

My testing is in a comment on
https://www.pugetsystems.com/labs/hpc/ubuntu-22-04-server-autoinstall-iso/

When you do this in bare-metal be sure that you have tried a manual install on that hardware. If there is anything broken with a manual install then the auto-install will also be broken. Some times you need to pass kernel flags on the grub line in order to install. If you have to do that then you would need to add those kernel flags to the grub.cfg stanza. And add them to /etc/defaults/grub too ...

@bashadude
Copy link

I ran through the procedure this morning and created ISO bootable from MBR and UEFI using the new install image Ubuntu server 22.04.2

Everything worked fine. Main thing is to be very careful about formating files. YAML is very picky!

My testing is in a comment on https://www.pugetsystems.com/labs/hpc/ubuntu-22-04-server-autoinstall-iso/

When you do this in bare-metal be sure that you have tried a manual install on that hardware. If there is anything broken with a manual install then the auto-install will also be broken. Some times you need to pass kernel flags on the grub line in order to install. If you have to do that then you would need to add those kernel flags to the grub.cfg stanza. And add them to /etc/defaults/grub too ...

@dbkinghorn Thank you so much

May i know the which kernel flags i need to send to grub.cfg. Please ping here

@dbkinghorn
Copy link
Author

dbkinghorn commented Mar 7, 2023

If you can manually install then you don't need any. But, as an example, on AMD WRX80 Tr Pro motherboards you sometimes need to include
amd_iommu=on iommu=pt

It's fairly common to need to use "nomodeset" if you have an install that just goes to a black screen.

@bashadude
Copy link

bashadude commented Mar 7, 2023

If you can manually install then you don't need any. But, as an example, on AMD WRX80 Tr Pro motherboards you sometimes need to include amd_iommu=on iommu=pt

It's fairly common to need to use "nomodeset" if you have an install that just goes to a black screen.

Hi @dbkinghorn @zero-pytagoras sorry to disturb you. I need your help

In my baremetal server i checked it was not working both manual and autoinstall. I am getting this error
error1

Next i am trying edit the kernel flags & can you please check in the below image in grub file
image

In boot mode i am pressing the e edit and next to edit /etc/defaults/grub i am using ctrl + c
Next in command line i am running these command to GRUB_CMDLINE_LINUX="amd_iommu=on iommu=pt"

I am sharing the user-data file
image

@dbkinghorn Thanks in advance

@jnlickey
Copy link

jnlickey commented Mar 7, 2023 via email

@dbkinghorn
Copy link
Author

running yamllint is a great idea! It is very easy to have a file error that is not even be noticeable.

Also, I highly recommend using a very simple user-data file for testing. Maybe just up to the point of creating an account. Try to simplify and then add on once you get a basic auto install working.

It does look like you are installing to an AMD Tr Pro motherboard! That error you see when doing the manual install is related to iommu.

If doing the manual install and adding those kernel flags using "e" editing during boot works. Then what you have in the grub.cfg file should also work.

If the manual install is still failing then try these 3 kernel flags (I added an extra one that is sometimes needed on those motherboards)

amd-iommu=on iommu=pt pci=nommconf

@bashadude
Copy link

bashadude commented Mar 8, 2023

running yamllint is a great idea! It is very easy to have a file error that is not even be noticeable.

Also, I highly recommend using a very simple user-data file for testing. Maybe just up to the point of creating an account. Try to simplify and then add on once you get a basic auto install working.

It does look like you are installing to an AMD Tr Pro motherboard! That error you see when doing the manual install is related to iommu.

If doing the manual install and adding those kernel flags using "e" editing during boot works. Then what you have in the grub.cfg file should also work.

If the manual install is still failing then try these 3 kernel flags (I added an extra one that is sometimes needed on those motherboards)

amd-iommu=on iommu=pt pci=nommconf

Hi @dbkinghorn

I have tried manual with these commands amd-iommu=on iommu=pt pci=nommconf working
But I tried same with auto install it was not working same error

error1

I have yamllint , cloudint for user-data there were no errors
image

@dbkinghorn can you please help me to get out this issue. can you please schedule meeting for 10-15 min orelse can you please send the exact iso include kernel flags.

Thanks in advance

@jnlickey
Copy link

jnlickey commented Mar 8, 2023 via email

@bashadude
Copy link

Fix your yaml errors and warnings. When you run yamllint it should not return anything. JonSent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: D Mahaboobabasha @.> Date: 3/8/23 4:42 AM (GMT-05:00) To: bashadude @.> Cc: Comment @.> Subject: Re: dbkinghorn/user-data-server @bashadude commented on this gist.running yamllint is a great idea! It is very easy to have a file error that is not even be noticeable.Also, I highly recommend using a very simple user-data file for testing. Maybe just up to the point of creating an account. Try to simplify and then add on once you get a basic auto install working.It does look like you are installing to an AMD Tr Pro motherboard! That error you see when doing the manual install is related to iommu.If doing the manual install and adding those kernel flags using "e" editing during boot works. Then what you have in the grub.cfg file should also work.If the manual install is still failing then try these 3 kernel flags (I added an extra one that is sometimes needed on those motherboards)amd-iommu=on iommu=pt pci=nommconfHi @dbkinghornI have tried manual with these commands amd-iommu=on iommu=pt pci=nommconf workingBut I tried same with auto install it was not working same errorI have yamllint , cloudint for user-data there were no @. can you please help me to get out this issue. can you please should meeting for 10-15 min orelse can you please send the exact iso include kernel flags.Thanks in advance—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you commented on the thread.Triage notifications on the go with GitHub Mobile for iOS or Android.

@jnlickey Thank you jnlickey I have cleared all errors and warnings with yamllint

But i check with cloudint it starts with #cloud-config. In yaml it was asking to start with this ---. I am following yamllint. let me try now

@bashadude
Copy link

image
Hi @jnlickey @zero-pytagoras @dbkinghorn

I got issue from the storage side. My user-data code below

#cloud-config
autoinstall:
version: 1
refresh-installer: # start with an up-to-date installer
channel: edge
update: yes

interactive-sections: # Install groups listed here will wait for user input
- storage
storage: # should set the interactive default but doesn't seem to work??
layout:
name: lvm

storage:
config:
- ptable: gpt
serial: 362cea7f0bfdbe5002ab3267d0c098d7a
wwn: '0x62cea7f0bfdbe5002ab3267d0c098d7a'
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
offset: 1048576
type: partition
id: partition-0
- fstype: fat32
volume: partition-0
preserve: false
type: format
id: format-0
- device: disk-sda
size: 2147483648
wipe: superblock
number: 2
preserve: false
grub_device: false
offset: 1128267776
type: partition
id: partition-1
- fstype: ext4
volume: partition-1
preserve: false
type: format
id: format-1
- device: disk-sda
size: 955843084288
wipe: superblock
number: 3
preserve: false
grub_device: false
offset: 3275751424
type: partition
id: partition-2
- name: ubuntu-vg
devices:
- partition-2
preserve: false
type: lvm_volgroup
id: lvm_volgroup-0
- name: ubuntu-lv
volgroup: lvm_volgroup-0
size: 107374182400B
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
updates: security
version: 1
locale: en_US.UTF-8
keyboard:
layout: us
identity: # This is section you may want to add to interactive-sections (user name and password are ubuntu here)
hostname: puget-000
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
username: ubuntu
ssh:
allow-pw: true
install-server: true
apt:
sources:
ignored1: # This is here to get the yaml formatting right when adding a ppa
source: ppa:graphics-drivers/ppa
packages:
- build-essential
- network-manager
- dkms
- emacs-nox
#- ubuntu-desktop-minimal^
package_update: true
package_upgrade: true
late-commands:
# Changing from networkd to NetworkManager
# move existing config out of the way
- find /target/etc/netplan/ -name "*.yaml" -exec sh -c 'mv "$1" "$1-orig"' _ {} ;
# Create a new netplan and enable it
- |
cat <<EOF | sudo tee /target/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: NetworkManager
EOF
- curtin in-target --target /target netplan generate
- curtin in-target --target /target netplan apply
- curtin in-target --target /target systemctl enable NetworkManager.service
# 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 'America/Los_Angeles America/Denver America/Chicago America/New_York'
# 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

- ls -l > /target/root/ls.out

- pwd > /target/root/pwd.out

- mount > /target/root/mount.out

- touch afile

- cp afile /target/root/

- ls -l / > /target/root/ls-root.out

- ls -l /target > /target/root/ls-target.out

- ls -l /target/cdrom > /target/root/ls-target-cdrom.out

- sed -i 's/ENABLED=1/ENABLED=0/' /target/etc/default/motd-news
- ln -fs /dev/null /target/etc/systemd/system/connman.service
- ln -fs /dev/null /target/etc/systemd/system/display-manager.service
- ln -fs /dev/null /target/etc/systemd/system/motd-news.service
- ln -fs /dev/null /target/etc/systemd/system/motd-news.timer
- ln -fs /dev/null /target/etc/systemd/system/plymouth-quit-wait.service
- ln -fs /dev/null /target/etc/systemd/system/plymouth-start.service
- ln -fs /dev/null /target/etc/systemd/system/systemd-resolved.service
- ln -fs /usr/share/zoneinfo/Europe/Kiev /target/etc/localtime
- rm -f /target/etc/resolv.conf
- printf 'nameserver 8.8.8.8\nnameserver 1.1.1.1\noptions timeout:1\noptions attempts:1\noptions rotate\n' > /target/etc/resolv.conf
- rm -f /target/etc/update-motd.d/10-help-text

user-data: # Commands here run during first boot (cannot be interactive)
runcmd:
# Install the NVIDIA driver from the ppa we setup earlier
- [apt-get, install, --yes, nvidia-driver-470, --no-install-recommends]
- |
#!/usr/bin/env bash
echo ''
echo ''
echo ' To complete install setup please run, '
echo ' sudo /etc/finish-install-setup.sh'
echo '
'
echo ''

@bashadude
Copy link

Hi @dbkinghorn I am waiting for your reply can you please help me to debug this in baremetal server in AMD TR pro motherboards

@dbkinghorn
Copy link
Author

The suggestions I've given are all I know for issues with WRX80 motherboards. If you are still having trouble with a local install then maybe you have a physical hardware problem. I can't really help you diagnose that.

@einsteinagogo
Copy link

einsteinagogo commented Jul 6, 2023

Any ideas, why the write script option in your template is not being executed ?

edit. Probably a typo, one issue is though /etc/hosts file goes not get changed, on changing hostname via hostnamectl ? any ideas ?

@dbkinghorn
Copy link
Author

Yes. In the write section I have commented out there are interactive sections for reading hostname and timezone. Those hang because there isn't proper terminal i/o at that point.

You can write scripts like that out and I thought it would run properly during the user-data section but there still isn't terminal i/o available.

It seems like there should be some way to do this but I was not able to find it.

...
I wish Canonical would have kept an option to do server installs from the Debian installer! ... or better adopted Kickstart :-)

@einsteinagogo
Copy link

Thanks for reply, I cross posted because I edited it, and got it working.

but changing hostname, via hostnamectl does not change the hostname in the /etc/hosts, so not sure if need to drop back to interactivite method of entering name password and hostname to get the correct hostname in /etc/hosts

@dbkinghorn
Copy link
Author

... I don't like to drop back to interactive for all of that but it may be the best (easiest) solution.
When you go to an interactive section, the installer is supposed to populate you defaults with any values you give in the cloud-init file. Like a default user and pw, but I've had trouble getting that to work too!

@einsteinagogo
Copy link

I found a way, to update /etc/hosts file, I think scripted, but this may all be a waste of time, because of domain join to Active Directory and if the workstation was joined to domain on build and later hostname change, it's going to break domain connection, so may have to also script domain join, and not make part of cloud-init

@homaur
Copy link

homaur commented Sep 7, 2023

Hi @dbkinghorn
Nice to meet you.
I have read your blogs but I am totally confused about how to create an autoinstall configuration file and edit it.

I have set up an iPXE boot server and that works. However, I would like to automate the installation of additional software so Ubuntu installs automatically with either autoinstall/preseed. However I am not sure how to add additional software packages to the autoinstall file and where is autoinstall configuration file etc. Finally, I'd like to install salt at the end so it can finish configuring the device with the software I need.

@zero-pytagoras
Copy link

Hi @homaur
as mentioned above - create the user-data file that has apt and packages parts, where you add repositories and packages for you use.
as an example, part of user-data file:

apt:
    sources:
      ignored1:  # This is here to get the yaml formatting right when adding a ppa
        source: ppa:saltstack/salt
  packages: 
    - build-essential
    - network-manager
    - dkms
    - salt # <-- here you add the package 

@homaur
Copy link

homaur commented Sep 7, 2023

Hi @homaur as mentioned above - create the user-data file that has apt and packages parts, where you add repositories and packages for you use. as an example, part of user-data file:

apt:
    sources:
      ignored1:  # This is here to get the yaml formatting right when adding a ppa
        source: ppa:saltstack/salt
  packages: 
    - build-essential
    - network-manager
    - dkms
    - salt # <-- here you add the package 

Great!
But as I mentioned above, I am not clear on how to create the user-data file and where this file should be located.
I can't find any blogs for how to create the user-data file and where this file is and so on.
There are many blogs with rough explanations. No details.
Please help me how to do that.
Did you understand what I want to do?

I have set up an iPXE boot server and that works. However, I would like to automate the installation of additional software so Ubuntu installs automatically with either autoinstall/preseed. However I am not sure how to add additional software packages to the autoinstall file and where is autoinstall configuration file etc. Finally, I'd like to install salt at the end so it can finish configuring the device with the software I need.

@jnlickey
Copy link

jnlickey commented Sep 7, 2023 via email

@homaur
Copy link

homaur commented Sep 7, 2023

Homaur,Feel free to use my Ubuntu AutoInstaller script. It will help to auto generate the user data file, by setting up the networking information, name, user accounts, etc. However, you'll need to modify either the script or the user-data file for your needs. Here's an example user-data file:https://github.com/jnlickey/Ubuntu_AutoInstaller/blob/main/user-dataJon Lickey, M.I.S Sent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: Homaur @.> Date: 9/7/23 6:03 AM (GMT-05:00) To: homaur @.> Cc: Comment @.***> Subject: Re: dbkinghorn/user-data-server @homaur commented on this gist.Hi @homaur as mentioned above - create the user-data file that has apt and packages parts, where you add repositories and packages for you use. as an example, part of user-data "notranslate">apt: sources: ignored1: # This is here to get the yaml formatting right when adding a ppa source: ppa:saltstack/salt packages: - build-essential - network-manager - dkms - salt # <-- here you add the package Great!But as I mentioned above, I am not clear on how to create the user-data file and where this file should be located.—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you commented on the thread.Triage notifications on the go with GitHub Mobile for iOS or Android.

Oh great and Oh very complicated.
I am not sure if you understand what I want or not. Here is my explanation of what I want to do.

I have set up an iPXE boot server and that works. However, I would like to automate the installation of additional software so Ubuntu installs automatically with either autoinstall/preseed. However I am not sure how to add additional software packages to the autoinstall file and where is autoinstall configuration file etc. Finally, I'd like to install salt at the end so it can finish configuring the device with the software I need. Totally, I want to install additional software automatically after Ubuntu has installed. Ubuntu will be installed via PXE net.
Do you understand?

@zero-pytagoras
Copy link

zero-pytagoras commented Sep 7, 2023

Hi @homaur as mentioned above - create the user-data file that has apt and packages parts, where you add repositories and packages for you use. as an example, part of user-data file:

apt:
    sources:
      ignored1:  # This is here to get the yaml formatting right when adding a ppa
        source: ppa:saltstack/salt
  packages: 
    - build-essential
    - network-manager
    - dkms
    - salt # <-- here you add the package 

Great! But as I mentioned above, I am not clear on how to create the user-data file and where this file should be located. I can't find any blogs for how to create the user-data file and where this file is and so on. There are many blogs with rough explanations. No details. Please help me how to do that. Did you understand what I want to do?

I have set up an iPXE boot server and that works. However, I would like to automate the installation of additional software so Ubuntu installs automatically with either autoinstall/preseed. However I am not sure how to add additional software packages to the autoinstall file and where is autoinstall configuration file etc. Finally, I'd like to install salt at the end so it can finish configuring the device with the software I need.

Hi @homaur
In regards to where, It depends - if you wish to use iPXE then it should be located on PXE server , on the path that is shared. For example: /var/www/pxe/user-data folder.
All is left is to take ISO file of ubuntu -> boot -> choose boot from PXE(should be in advanced settings) -> give it pxe address and path to user-data, and it will perform what ever is configured in user-data
In regards to How to create user-data : @jnlickey provided link to github repository with example of user-data and tool to build the file. there is also cloud-init documentation that is used to create the file and also there is youtube tutorial to guide you and another one that might be useful

@homaur
Copy link

homaur commented Sep 7, 2023

Hi @homaur as mentioned above - create the user-data file that has apt and packages parts, where you add repositories and packages for you use. as an example, part of user-data file:

apt:
    sources:
      ignored1:  # This is here to get the yaml formatting right when adding a ppa
        source: ppa:saltstack/salt
  packages: 
    - build-essential
    - network-manager
    - dkms
    - salt # <-- here you add the package 

Great! But as I mentioned above, I am not clear on how to create the user-data file and where this file should be located. I can't find any blogs for how to create the user-data file and where this file is and so on. There are many blogs with rough explanations. No details. Please help me how to do that. Did you understand what I want to do?
I have set up an iPXE boot server and that works. However, I would like to automate the installation of additional software so Ubuntu installs automatically with either autoinstall/preseed. However I am not sure how to add additional software packages to the autoinstall file and where is autoinstall configuration file etc. Finally, I'd like to install salt at the end so it can finish configuring the device with the software I need.

Hi @homaur In regards to where, It depends - if you wish to use iPXE then it should be located on PXE server , on the path that is share. For example: /var/www/pxe/user-data folder. All is left is to take ISO file of ubuntu -> boot -> choose boot from PXE(should be in advanced settings) -> give it pxe address and path to user-data, and it will perform what ever is configured in user-data In regards to How to create user-data : @jnlickey provided link to github repository with example of user-data and tool to build the file. there is also cloud-init documentation that is used to create the file and also there is youtube tutorial to guide you and another one that might be useful

Oh so, for example, autoinstall configuration file will be located in /var/www/pxe/user-data folder in iPXE server, right?

@zero-pytagoras
Copy link

Hi @homaur as mentioned above - create the user-data file that has apt and packages parts, where you add repositories and packages for you use. as an example, part of user-data file:

apt:
    sources:
      ignored1:  # This is here to get the yaml formatting right when adding a ppa
        source: ppa:saltstack/salt
  packages: 
    - build-essential
    - network-manager
    - dkms
    - salt # <-- here you add the package 

Great! But as I mentioned above, I am not clear on how to create the user-data file and where this file should be located. I can't find any blogs for how to create the user-data file and where this file is and so on. There are many blogs with rough explanations. No details. Please help me how to do that. Did you understand what I want to do?
I have set up an iPXE boot server and that works. However, I would like to automate the installation of additional software so Ubuntu installs automatically with either autoinstall/preseed. However I am not sure how to add additional software packages to the autoinstall file and where is autoinstall configuration file etc. Finally, I'd like to install salt at the end so it can finish configuring the device with the software I need.

Hi @homaur In regards to where, It depends - if you wish to use iPXE then it should be located on PXE server , on the path that is share. For example: /var/www/pxe/user-data folder. All is left is to take ISO file of ubuntu -> boot -> choose boot from PXE(should be in advanced settings) -> give it pxe address and path to user-data, and it will perform what ever is configured in user-data In regards to How to create user-data : @jnlickey provided link to github repository with example of user-data and tool to build the file. there is also cloud-init documentation that is used to create the file and also there is youtube tutorial to guide you and another one that might be useful

Oh so, for example, autoinstall configuration file will be located in /var/www/pxe/user-data folder in iPXE server, right?

Yes - indeed ...

@homaur
Copy link

homaur commented Sep 7, 2023

Ah!!! Great!!!
Thank you for your kind reply.
I will try with your suggestion and let you know.
I really appreciate it.
Thank you again!!!

@shubham-kshetre
Copy link

shubham-kshetre commented Sep 17, 2023

Hello there,

I am currently building an autoinstall ISO using Ubuntu 22.04.3 LTS live server. A blog post by @dbkinghorn has been immensely helpful in this process. However, I have encountered an issue with the autoinstall script I created, specifically with regard to enabling autologin for the new user.

The purpose of this autoinstall is to run docker engine. I am in need of suggestions or assistance to resolve this issue. Below is my 'user-data' configuration:

#cloud-config
autoinstall:
  version: 1
  storage:
    layout:
      name: direct
  partitions:
    - name: primary
      number: 1
      size: 100%
      type: ext4
      wipe: superblock
  preserve_layout: false
  overwrite: true
  filesystems:
    - device: /dev/disk/by-id/*
      format: ext4
      label: ubuntu
  locale: en_US.UTF-8
  keyboard:
    layout: us
  identity:
    hostname: ubuntu_machine
    password: $6$NpdhCKROExJxGAP9$uJ/hKo9ON7VZ.nwC02p8yKHPFtEWz.aphNk7D1fDI7aUmtrXTN5i/QmDhtbCf0xNQEr/LTphOfdcgovbDwG8l.
    username: ubuntu
  ssh:
    allow-pw: true
    install-server: true
  apt:
    primary:
      - arches: [default]
        uri: http://us.archive.ubuntu.com/ubuntu/
  packages:
    - build-essential
    - network-manager
    - dkms
    - vim
    - git
    - docker.io
    - nodejs
    - npm
    - sqlite

  package_update: true
  package_upgrade: true
  late-commands:
    # Changing from networkd to NetworkManager
    # move existing config out of the way
    - find /target/etc/netplan/ -name "*.yaml"
      -exec sh -c 'mv "$1" "$1-orig"' _ {} \;
    # Create a new netplan and enable it
    - |
      cat <<EOF | sudo tee /target/etc/netplan/01-netcfg.yaml
      network:
        version: 2
        renderer: NetworkManager
      EOF
    - curtin in-target --target /target netplan generate
    - curtin in-target --target /target netplan apply
    - curtin in-target --target /target systemctl enable NetworkManager.service
  users:
    - name: ubuntu
      groups: docker
      shell: /bin/bash
      sudo: ALL=(ALL) NOPASSWD:ALL
  autologin:
    enable: true
    user: root

I have been working on this problem for several weeks and would greatly appreciate any guidance or help. Thank you.

@dbkinghorn
Copy link
Author

You probably still have a little more experimenting to do. Here are a couple of things to try;

  • You have the user 'ubuntu' already defined with a password (effectively the install root user'.) You might want to try setting up your auto-login user with at different name. (I'm not sure how this is done with a manual install. Maybe you want to do this in the identity section and not assign a password at all??)

  • If you want to have the user 'ubuntu' as the auto login user then you might have better luck in late-commands using curtin in-target --target to do the config change manually with system commands like usermod etc..

I don't have experience using auto login but I hope I'm giving you good advise on things to try. Best wishes --Don

@smahm006
Copy link

smahm006 commented Nov 5, 2023

@shubham-kshetre I had a kinda successful but disgusting method go get autologin working.

In late_commands add this:

# Create a service to run above script on bootup
- |
  cat <<EOF | sudo tee /target/etc/systemd/system/setup_autologin.service
  [Unit]
  Description=Configure autologin for user "tester"

  [Service]
  Type=oneshot
  ExecStart=/bin/bash -c "sed -i 's/#  AutomaticLoginEnable = true/AutomaticLoginEnable = true/' /etc/gdm3/custom.conf && sed -i 's/#  AutomaticLogin = user1/AutomaticLogin = tester/' /etc/gdm3/custom.conf && groupadd docker && usermod -aG docker tester && newgrp docker"

  [Install]
  WantedBy=multi-user.target
  EOF
- curtin in-target --target /target chmod 0644 /etc/systemd/system/setup_autologin.service
- curtin in-target --target /target systemctl enable setup_autologin

Basically create a service that will run prior to the desktop loading. Problem is that you have to delete the service file post login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment