How to ditch the container image (zfs clone) on creation

I create a seperate zfs pool for each container and it’s volumes to have a unified storage limit on the whole pool. I would like to run my containers longer, so I’d like to upgrade to Ubuntu LTS 24.04.1 in the container once it is there. At that point the image will just waste 700MB and not be needed anymore. Can I ditch the image at container creation now? Will I have to wait for lxc rebuild?

The way i figured out is:

### Create empty container
lxc init --empty containername

### Mount the empty container to fill it manually
mkdir /mnt/containername
mount -t zfs zfs/lxd-pool/containers/containername /mnt/containername
mkdir /mnt/containername/rootfs

### Download an OS manually into the rootfs folder
eval "wget" -O- https://cloud-images.ubuntu.com/minimal/releases/jammy/release/ubuntu-22.04-minimal-cloudimg-amd64-root.tar.xz | tar xJ -C /mnt/containername/rootfs

### Unmount temporary mount
umount /mnt/containername

Then simply start the container, this should work fine.

lxc start containername

Normally you’d put the LXD manifest from the same source(https://cloud-images.ubuntu.com/minimal/releases/jammy/release/) next to the rootfs as well, but in my tests it also worked this way.

@stgraber This might be a quick tutorial for some?

We have a setting on ZFS pool to not use clones during creation and copy but instead use send/receive.
If you set that flag and then make a copy of the instance, that will detach it from its image.

1 Like

https://linuxcontainers.org/lxd/docs/master/reference/storage_zfs/#storage-pool-configuration

zfs.clone_copy

1 Like

Thank you very much @stgraber and @tomp!

For anybody stumbling upon this, this works:

### Create storage on a zfs pool with zfs.clone_copy=false
lxc storage create container-pool zfs source=zfs/container-pool zfs.clone_copy=false

### Initialize or launch a container on that pool
lxc init ubuntu:22.04 containername -s container-pool

### Delete the image that has not been cloned but copied due to zfs.clone_copy=false
# With yq
lxc image delete "$(lxc storage info container-pool | yq '.["used by"]'.images.[])"
# With bash, grep and sed only
lxc image delete "$(lxc storage info "$containername"-pool | grep -A1 "images:" | grep -v "images:" | sed 's/^[[:space:]]*-[[:space:]]//g')"

Link to yq

1 Like