if the rootfs is a btrfs subvolume, delete it instead of rm -rf

Check if the rootfs is btrfs subvolume, and if so delete it. Otherwise
fall back to the rm -rf.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
This commit is contained in:
Dwight Engen 2012-09-26 12:59:28 -04:00 committed by Stéphane Graber
parent 06a1e1db99
commit 5ae26abb52

View File

@ -106,8 +106,8 @@ if [ $? -eq 0 ]; then
fi fi
# Deduce the type of rootfs # Deduce the type of rootfs
# If LVM partition, destroy it. If anything else, ignore it. We'll support # If LVM partition, destroy it. For btrfs, we delete the subvolue. If anything
# deletion of others later. # else, ignore it. We'll support deletion of others later.
rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config 2>/dev/null | sed -e 's/^[^/]*/\//'` rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config 2>/dev/null | sed -e 's/^[^/]*/\//'`
if [ -n "$rootdev" ]; then if [ -n "$rootdev" ]; then
if [ -b "$rootdev" ]; then if [ -b "$rootdev" ]; then
@ -117,8 +117,13 @@ if [ -n "$rootdev" ]; then
lvremove -f $rootdev lvremove -f $rootdev
fi fi
elif [ -h "$rootdev" -o -d "$rootdev" ]; then elif [ -h "$rootdev" -o -d "$rootdev" ]; then
# In case rootfs is not under $lxc_path/$lxc_name, remove it if which btrfs >/dev/null 2>&1 &&
rm -rf --one-file-system --preserve-root $rootdev btrfs subvolume list "$rootdev" >/dev/null 2>&1; then
btrfs subvolume delete "$rootdev"
else
# In case rootfs is not under $lxc_path/$lxc_name, remove it
rm -rf --one-file-system --preserve-root $rootdev
fi
fi fi
fi fi
# recursively remove the container to remove old container configuration # recursively remove the container to remove old container configuration