From eec7fcf965763d5395c336f92cd56b193d054947 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Tue, 7 Mar 2017 20:14:50 +0100 Subject: archbuild/makechrootpkg: Delete subvolumes in roots The systemd package creates a subvolume at /var/lib/machines (through tmpfiles), if it can. We need to delete this subvolume before we can delete the parent subvolume. Look through the root for inodes with the number 256. These identify subvolume roots. --- lib/archroot.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib') diff --git a/lib/archroot.sh b/lib/archroot.sh index 14417aa..989f1e1 100644 --- a/lib/archroot.sh +++ b/lib/archroot.sh @@ -20,3 +20,23 @@ check_root() { is_btrfs() { [[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]] } + +## +# usage : subvolume_delete_recursive( $path ) +# +# Find all btrfs subvolumes under and including $path and delete them. +## +subvolume_delete_recursive() { + local subvol + + is_btrfs "$1" || return 0 + + while IFS= read -d $'\0' -r subvol; do + if ! btrfs subvolume delete "$subvol" &>/dev/null; then + error "Unable to delete subvolume %s" "$subvol" + return 1 + fi + done < <(find "$1" -xdev -depth -inum 256 -print0) + + return 0 +} -- cgit v1.2.3-54-g00ecf