Skip to content

Instantly share code, notes, and snippets.

@smoser
Created January 11, 2022 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoser/54aef9c50abf53b2dc686d51c2a45216 to your computer and use it in GitHub Desktop.
Save smoser/54aef9c50abf53b2dc686d51c2a45216 to your computer and use it in GitHub Desktop.
seed user-data and metadata from a directory with network config from nocloud seed.

Seed user-data, meta-data and network config from a directory in nocloud

A while back a collegue asked me for help. He was trying to seed nocloud data from the kernel command line. Below is how I tested the functionality using LXD.

start a "normal" lxc container

$ lxc launch ubuntu:focal test1

enter it.

$ lxc exec testf1 /bin/bash
root@testf1:~# PS1="% "

create a new seed, stealing the network config from existing (just for ease of use)

% mkdir /myseed
% cd /myseed
% printf "%s\n%s\n" \
  '#!/bin/sh' 'echo hi mom > /run/user-data.log' \
  > user-data
% printf "%s\n%s\n" \
   "instance-id: i-smoser" "local-hostname: smoser1" \
   > meta-data
% cp /var/lib/cloud/seed/nocloud-net/network-config  .
% cat network-config
version: 1
config:
 - type: physical
   name: eth0
   subnets:
    - type: dhcp
      control: auto

cleanup container

% cloud-init clean --logs --seed

exit container, back on host.

% exit

edit lxc config. (Note the 'dummy' at the end without it, or some thing there, the trailing '/' will just get swallowed by lxc/lxd... lxc/lxc#4015)

$ lxc stop testf1
$ lxc config set testf1 raw.lxc="lxc.init.cmd = /sbin/init ds=nocloud;seedfrom=/myseed/ dummy"

start it,

$ lxc start testf1
$ sleep 10 # let it boot

hop inside, see what happened.

$ lxc exec testf1 -- cat /run/user-data.log hi mom

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