Migrate LXC container to LXD (with ZFS storage)

CONTAINER_NAME=www

lxc-stop -n ${CONTAINER_NAME}
lxc init ubuntu:18.04 ${CONTAINER_NAME} -c security.privileged=true -c boot.autostart=true
#lxc stop ${CONTAINER_NAME}
#lxc config set ${CONTAINER_NAME} boot.autostart true
zfs mount tank/lxd/containers/${CONTAINER_NAME}
mv /var/lib/lxd/containers/${CONTAINER_NAME}/rootfs{,.org}
rsync -av --numeric-ids /var/lib/lxc/${CONTAINER_NAME}/rootfs /var/lib/lxd/containers/${CONTAINER_NAME}/
mv /var/lib/lxd/containers/${CONTAINER_NAME}/rootfs/dev{,.org}
rsync -av /var/lib/lxd/containers/${CONTAINER_NAME}/rootfs.org/dev /var/lib/lxd/containers/${CONTAINER_NAME}/rootfs/
rm -r /var/lib/lxd/storage-pools/zfs/containers/${CONTAINER_NAME}/rootfs.org
umount /var/lib/lxd/containers/${CONTAINER_NAME}
sed -i 's|lxc.start.auto = .*|lxc.start.auto = 0|g' /var/lib/lxc/${CONTAINER_NAME}/config
lxc config set ${CONTAINER_NAME} volatile.eth0.hwaddr $(grep lxc.net.0.hwaddr /var/lib/lxc/${CONTAINER_NAME}/config | cut -d"=" -f2)
lxc config show ${CONTAINER_NAME}
lxc-ls -n ${CONTAINER_NAME} -f
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER}
lxc config set ${CONTAINER} security.privileged false
lxc start ${CONTAINER}