How to Properly Delete Btrfs Snapshots: Resolving “Device or Resource Busy” Errors


9 views

When working with Btrfs snapshots, many users encounter the frustrating "Device or resource busy" error when attempting deletion. This typically occurs because the snapshot is either currently mounted or has open file handles. Here's how to properly identify and delete snapshots.

First, list all subvolumes to locate your snapshots:

sudo btrfs subvolume list /

You'll see output similar to:

ID 257 gen 82021 top level 5 path @
ID 258 gen 82021 top level 5 path @home
ID 263 gen 81983 top level 5 path @home/.ecryptfs/user/.Private/.../root_post_install_2014-04-29

If you simply try to delete with:

sudo btrfs subvolume delete snapshot_name

And get the busy error, try these solutions:

Method 1: Unmount First

Check if the snapshot is mounted:

mount | grep btrfs

If mounted, unmount it:

sudo umount /path/to/snapshot

Method 2: Check for Open Files

Use lsof to find processes using the snapshot:

sudo lsof +D /path/to/snapshot

Terminate relevant processes or close applications before deletion.

Method 3: Force Deletion

As a last resort, use the recursive delete option:

sudo btrfs subvolume delete -c /path/to/snapshot

For regular maintenance, consider using btrbk or snapper:

sudo snapper delete 263  # Using snapshot ID from list command

For snapshots in encrypted directories (like your ecryptfs path), ensure you've decrypted the Private directory first:

ecryptfs-mount-private

Then proceed with the deletion methods above.


When working with Btrfs snapshots, you might encounter a common but frustrating error when trying to delete old snapshots:

ERROR: cannot delete '/path/to/snapshot' - Device or resource busy

This typically happens because the snapshot is currently mounted or being used by some process. Let's explore how to properly handle this situation.

First, ensure you're identifying snapshots accurately. The btrfs subvolume list command shows all subvolumes, not just snapshots. To specifically list snapshots:

sudo btrfs subvolume list -s /

Or to see snapshots recursively:

sudo btrfs subvolume list -s -r /

Before deletion, check if the snapshot is mounted:

mount | grep btrfs

Or more specifically:

findmnt -t btrfs

If your snapshot appears in the output, it needs to be unmounted first.

Here are three reliable ways to delete Btrfs snapshots:

Method 1: Unmount then Delete

# Unmount if mounted
sudo umount /path/to/snapshot

# Then delete
sudo btrfs subvolume delete /path/to/snapshot

Method 2: Delete by ID

Sometimes it's more reliable to delete using the subvolume ID:

# First get the ID
sudo btrfs subvolume list / | grep your_snapshot_name

# Then delete by ID (e.g., ID 263)
sudo btrfs subvolume delete -i 263 /

Method 3: Force Deletion (Use with Caution)

For stubborn snapshots that won't unmount:

sudo btrfs subvolume delete --commit-after /path/to/snapshot

In your case, the snapshots are inside an encrypted directory (ecryptfs). This adds complexity. You'll need to:

  1. Ensure the encrypted directory is properly mounted
  2. Navigate to the decrypted view of the directory
  3. Then attempt deletion
# First make sure .Private is decrypted and mounted
ecryptfs-mount-private

# Then delete from within the decrypted view
sudo btrfs subvolume delete ~/.Private/.../your_snapshot

For regular maintenance, consider using snapper or a custom script:

#!/bin/bash
# Delete snapshots older than 30 days
SNAPSHOTS=$(sudo btrfs subvolume list -s / | awk '{print $14}')
for SNAP in $SNAPSHOTS; do
    SNAP_DATE=$(stat -c %y "$SNAP" | cut -d' ' -f1)
    DAYS_OLD=$(( ( $(date +%s) - $(date -d "$SNAP_DATE" +%s) ) / 86400 ))
    if [ "$DAYS_OLD" -gt 30 ]; then
        sudo btrfs subvolume delete "$SNAP"
    fi
done

If you still can't delete a snapshot:

  • Check for open files with lsof | grep /path/to/snapshot
  • Reboot and try again (ensuring the snapshot isn't in fstab)
  • Verify filesystem integrity with btrfs scrub

Remember that Btrfs uses copy-on-write, so deleting snapshots only frees space that isn't shared with other snapshots or subvolumes.