Fix BEADM DESTROY for 'static' boot environments.

This commit is contained in:
Slawomir Wojciech Wojtczak (vermaden) 2012-08-18 03:56:06 +02:00
parent cca014136e
commit af3dbd80b7
1 changed files with 61 additions and 36 deletions

25
beadm
View File

@ -70,6 +70,25 @@ __be_mounted() { # 1=BE
mount 2> /dev/null | grep -q -E "^${1} " 2> /dev/null
}
# check if boot environment is a clone
__be_clone() { # 1=DATASET
if zfs list sys/ROOT/static 1> /dev/null 2> /dev/null
then
local ORIGIN="$( zfs list -H -o origin ${1} )"
if [ "${ORIGIN}" = "-" ]
then
# boot environment is not a clone
return 1
else
# boot environment is a clone
return 0
fi
else
# boot environment does not exist
return 2
fi
}
# create new boot environment
__be_new() { # 1=SOURCE 2=TARGET
local SOURCE=$( echo ${1} | cut -d '@' -f 1 )
@ -364,6 +383,8 @@ EOF
exit 1
fi
else
if __be_clone ${POOL}/ROOT/${DESTROY}
then
# promote clones dependent on snapshots used by destroyed boot environment
zfs list -H -t all -o name,origin \
| while read NAME ORIGIN
@ -375,8 +396,11 @@ EOF
done
# get origins used by destroyed boot environment
ORIGIN_SNAPSHOTS=$( zfs list -H -t all -o origin -r ${POOL}/ROOT/${DESTROY} | grep -v '^-$' | awk -F "@" '{print $2}' | sort -u )
fi
# destroy boot environment
zfs destroy -r ${POOL}/ROOT/${DESTROY}
if __be_clone ${POOL}/ROOT/${DESTROY}
then
# promote datasets dependent on origins used by destroyed boot environment
ALL_ORIGINS=$( zfs list -H -t all -o name,origin )
echo "${ORIGIN_SNAPSHOTS}" \
@ -403,6 +427,7 @@ EOF
done
done
fi
fi
echo "Destroyed successfully"
;;
(*)