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