Here is a quick and dirty shell script I put to check LXD container size and how much space they are taking on the BTRFS subvolume. Naturally, you must run the script as a root user, and LXD must be configured with BTRFS storage backend on Linux operating systems. See how to set up and install LXD on Ubuntu 20.04 LTS using the apt command

Checking LXD container BTRFS disk usage on Linux

Sample shell script:

#!/usr/bin/env bash
## Usage: 
## Find LXD container disk size and how much space they are using when storage back end set to BTRFS.
## Tested on Ubuntu Linux 20.04 LTS only
## Syntax:
## /path/to/lxd-btrfs-df 
## /path/to/lxd-btrfs-df | more
## /path/to/lxd-btrfs-df | grep "container-name"
## /path/to/lxd-btrfs-df  /dev/sda2
## ----------------------------------------------------------------------------
## Written by Vivek Gite <https://www.cyberciti.biz/>
## (c) 2020 Vivek Gite under GNU GPL v2.0+
## ----------------------------------------------------------------------------
## Last updated: 23/Oct/2020
## ----------------------------------------------------------------------------
set -eu -o pipefail

## Default set to aws /dev/xvdf but override using the cli arg
DEV="${1:-/dev/xvdf}"

## BTRFS mount point 
MNT="/mnt/btrfs"

## Look for btrfs binary
_BTRFS="$(command -v btrfs)"

## Am i root user? if not die.
[ "$(id -u)" -ne "0" ] && { echo "This script must be run as root."; exit 1; }

## Failsafe stuff
[ "$_BTRFS" == "" ] && { echo "btrfs command not found."; exit 2; }
[ ! -d "$MNT" ] && mkdir -p "$MNT"
[ ! -b "$DEV" ] && { echo "$DEV not found. Try '$0 /dev/BTRFS_DEVICE' command."; exit 3; }

## Is $DEV mounted?
if ! mount | grep -q "^${DEV}" 
then
	mount "$DEV" "$MNT" 
else
	MNT="$(mount | grep ^"${DEV}" | awk '{print $3}')"
fi

## My quick df for lxd containers 
echo -e "\n\t* Disk usage for LXD containers with BTRFS fs\n"
for d in "${MNT}"/containers/*
do 
	$_BTRFS filesystem du -s "$d"
done

## Run df on mount fs too to get total disk usage 
echo -e "\n\t* Total (df) for $MNT BTRFS fs\n"
$_BTRFS filesystem df "$MNT"

umount "$MNT"

#linux

How To check LXD container BTRFS disk usage on Linux
5.35 GEEK