← Back to team overview

cloud-init team mailing list archive

Re: Provisioning bare metal boxes with cloud-init?


Hi Marcel,

   Sorry for the delay in response here.

I'm presuming your Raspberry Pi setup with user-data was mounting either a
disk labelled 'CIDATA' which contained a user-data file or by creating a
file on the attached boot disk under /var/lib/cloud/nocloud-net/user-data.
Either one of those solutions for your Raspberry Pi would have allowed
cloud-init to discover the DatasourceNoCloud and provide your user-data

The Live installer behavior (subiquity) for cloud-init is slightly
different than the DataSourceNoCloud because subiquity seeds configuration
from the answers provided to the installer by using a different datasource
type (DataSourceNone). All userdata_raw and metadata are provided in a
single configuration file.

Ubuntu live-server and live-desktop canary ISOs are subiquity-based
installers that drive cloud-init in two stages during installation:
 1. Commissioning/Ephemeral stage: Initial boot from ISO boots into memory
    - cloud-init is active for initial network detection and bring up or
providing option of detecting different datasources to the installer
    - cloud-init user-data can manipulate the commissioning environment to
change the behavior of the installer dialogs/choices etc
    - any `autoinstall:user-data:` #cloud-config keys are merged into the
user-data which is provided to cloud-init across "post-install first reboot"
 2. Final Installation stage: post-install first reboot
    - All combined subiquity configuration and user-data for cloud-init
lives in /etc/cloud/cloud.cfg.d/99-installer.cfg as a DataSourceNone
    - cloud-init detects DataSourceNone and applies combined configuration
and userdata_raw to finalize setup during the first reboot after
commissioning completes

All said, while there are other ways to inject supplemental user-data into
the target system across reboot, the best way is to simply provide your
normal #cloud-config directives to subiquity under the
`#cloud-config\nautoinstall: user-data:` YAML key path[1] . Subiquity will
then augment any answers you provide to installer prompts to any
autoinstall:user-data keys available.

For example, to add PPAs and install 'sl' package in the installed system
you normally would provide something like the following in a cloud
     packages: [sl]



            source: 'deb [arch=amd64]
http://ppa.launchpad.net/cloud-init-dev/daily/ubuntu $RELEASE main'
            keyserver: keyserver.ubuntu.com

            keyid: E4D304DF

Now in LIVE installer(subiquity) context you would provide those same keys
scoped below a top-level autoinstall:user-data KEY path:

If you wish to be prompted for each interactive section of the installer
you would include the `interactive-sections: [*]`

   version: 1
   interactive-sections: ["*"]
     packages: [sl]
     apt: ...

To only selectively get prompted to specific prompts in the installer you
want to see, interactive-sections can be something like:
[network, identity] instead of ['*']

The way I install an old laptop at home is an adaptation of the autoinstall
quickstart[2] without using kvm.

1. Create a subdir with minimally a user-data and meta-data file and a
simple python http server to host those files
   mkdir autoinstall
   cd autoinstall
   touch meta-data # empty is ok
   cat > user-data <<EOF
   version: 1
   interactive-sections: ["*"]
     packages: [sl]
python3 -m http.server 8000

# Figure out YOUR_IP from `ip addr`

2. When booting the live-server ISO extend grub kernel cmdline params
specifying:  autoinstall 'ds=nocloud-net;s=http://YOUR_IP:8000/
   In grub hit 'e' to edit the boot menu option for installing ubuntu
  on the line starting with linux  append the following after the ---
   autoinstall 'ds=nocloud-net;s=http://YOUR_IP:8000/'

# The above tells cloud-init to look for a user-data and meta-data file at
that URL. The single quotes are important around 'ds=nocloud-net;s=http://

   CTRL-X to save and tell grub to boot with those kernel params

The installer should start (and still prompt you for any specific
partitioning(storage), primary users(identity), proxies for any autoinstall
value you didn't already provide).
It will also include your autoinstall.user-data into the configuration that
is provided to the target host after reboot.

Hope this helps,

 - [1] autoinstall user-data schema
 - [2] autoinstall quickstart

On Wed, Nov 30, 2022 at 2:08 PM Marcel Hernandez <e6990620@xxxxxxxxx> wrote:

> I have an old laptop in which I'd like to install Ubuntu Server 22.04 and
> provision it automatically with a cloud-init template.
> I've been doing this for some time with a Raspberry Pi 4, whose Ubuntu
> image already comes with an accessible
> user-data file that you can modify to your liking before booting it for
> the first time (https://ubuntu.com/download/raspberry-pi).
> However it's not clear to me at all how to do this with a run of the mill
> x86_64 box. I know that Ubuntu Server comes preinstalled
> with cloud-init and that the installation program (subiquity?) uses it for
> some of the tasks (like creating your main user), but I have no clue how to
> feed cloud-init my own user-data and execute on the next boot. Or provide
> the template during the installation process so that it runs on first boot,
> like an EC2 instance would.
> Just to clarify I'm not interested in autoinstall. I don't mind running
> the Ubuntu installation wizard manually. What I want to automate
> is the post-installation setup (adding third party PPAs, installing
> packages, creating files and users etc.)
> --
> Mailing list: https://launchpad.net/~cloud-init
> Post to     : cloud-init@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~cloud-init
> More help   : https://help.launchpad.net/ListHelp