LXC/LXD
Profiles
cloud-init
The following content is based off LXC's documentation and various searches. You may want to first have a look at the official documentation.
Here's a short example of a profile with a cloud-init configuration.
config:
user.user-data: |
#cloud-config
ssh_authorized_keys:
- {{ Insert your SSH public key }}
package_update: true
packages:
- htop
- vim
- tmux
- mtr-tiny
runcmd: # Runs on first boot, but later than bootcmd
- mkdir -pv /etc/vim
- curl -o /etc/vim/vimrc.local https://raw.githubusercontent.com/amix/vimrc/master/vimrcs/basic.vim
bootcmd: # Runs on first boot, but earlier than runcmd
- dateThere are a few ways to edit a profile, here's the one that worked best for me.
Create a new profile based on the default one:
lxc profile copy default {{ profile name }}Pipe base profile to a new file in the home directory:
lxc profile show {{ profile name }} > ~/{{ profile name }}.yamlEdit the new profile file with your favorite editor
Pipe the modified profile back to LXC:
cat ~/{{ profile name }} | lxc profile edit {{ profile name }}Start a new instance with the profile:
lxc launch ubuntu:20.04 local:ubuntu_cloud-init -p {{ profile name }}Check the status of cloud-init inside the instance:
lxc exec ubuntu_cloud-init cloud-init status
It can take a few minutes for cloud-init to run all the instructions.
Here's the whole file for reference purposes. Yours will most likely defer depending on the configuration done with lxd ini.
References
LXD documentation
cloud-init documentation
Last updated
Was this helpful?