lxc-destroy: Separately rm rootfs if it is a symlink

If rootfs is a symbolic link but not to a block device, then do a separate
rm of its contents.  We have to do this because, out of cowardice, we call
rm with --one-filesystem.

Removing the '-o -h $rootdev' is ok, because if $rootdev is a symbolic
link to a block device (including lvm blockdev) then -b will still return
true.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Serge Hallyn 2012-09-05 21:59:13 -05:00 committed by Stéphane Graber
parent b942e67226
commit 55116c42e7

View File

@ -110,13 +110,16 @@ fi
# If LVM partition, destroy it. If anything 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/^[^/]*/\//'`
if [ ! -z "$rootdev" ]; then
if [ -b "$rootdev" -o -h "$rootdev" ]; then
if [ -n "$rootdev" ]; then
if [ -b "$rootdev" ]; then
lvdisplay $rootdev > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "removing backing store: $rootdev"
lvremove -f $rootdev
fi
elif [ -h "$rootdev" -o -d "$rootdev" ]; then
# In case rootfs is not under $lxc_path/$lxc_name, remove it
rm -rf --one-file-system --preserve-root $rootdev
fi
fi
# recursively remove the container to remove old container configuration