LXD: How to create an empty container (rootfs empty)

Is there a simple way to create a raw empty container, with only sys directories in rootfs (proc,sys etc…), and basic metadata?

For the moment i create a container from image and delete everything inside rootfs, but it is not a fast solution.

Hi!

See my tutorial on how to create a minimal LXD container image with distrobuilder,

It describes how to create a container image for Alpine Linux, which is minimal enough. About a couple of megabytes.

If you want fewer files, you can even remove packages.

1 Like

The API lets you do it, though such a container wouldn’t be startable due to lack of init system, so it’s only good to then manually mount and rsync stuff over.

lxc query -X POST /1.0/containers -d '{"name": "blah", "source": {"type": "none"}}' --wait

that’s exactly what i wanted. thanks.

there is no ‘templates’ directory after container creation : is there a way with api to create it? When i want to put templates with put it complains because templates dir is missing.

That sounds like a bug, you’d expect the first template you create would create the directory.
I’ll make sure master is broken and will send a fix.

ok thanks.

And is there a way to create this empty container in privileged mode?

Just add config: {"security.privileged": "true"} to the request.

ok thanks it works fine.

i have a last problem: when creating an empty container, if i want to mount a disk - let’s say “share” - i must start the container for the mount be effective, so i cannot transfer files in rootfs/${share} offline. Is that right?

That’s correct, though if it’s a storage volume managed by LXD, you could attach it to another running container to push things in that way, or if it’s just a disk device for a host path, then write the data through the host instead.

My question, without reading it, why can’t bash script can’t do this? Why LXD?

@lhprojects i am not sure to understand your question.