Fix “dataset is busy” error when deleting container in LXD.

If you try to delete a LXD container, you may get a “dataset is busy” error message because the dataset the container uses in the ZFS storage pool remains mounted in the namespace used by LXD. In this example, we will simulate this problem by trying to delete a container “alpine”.

# lxc delete alpine
# Error: Error deleting storage volume: Failed to run: zfs destroy -r lxd-01/containers/alpine: cannot destroy 'lxd-01/containers/alpine': dataset is busy

To manually unmount the dataset, we need to know process ID (PID) and mountpoint.

# grep containers/alpine /proc/*/mountinfo
# /proc/35527/mountinfo:3515 7152 0:235 / /var/snap/lxd/common/lxd/storage-pools/lxd-01/containers/alpine rw,relatime shared:1510 - zfs lxd-01/containers/alpine rw,xattr,posixacl

In this case our PID is “35527” and mountpoint “/var/snap/lxd/common/lxd/storage-pools/lxd-01/containers/alpine”. With this information we can enter the namespace and unmount the relevant mointpoint.

# nsenter -t 35527 -m -- umount /var/snap/lxd/common/lxd/storage-pools/lxd-01/containers/alpine

You should now be able to delete the container without any errors.

# lxc delete alpine

Similar Posts