Fix bad mountpoint detection for BEADM MOUNT and add a check to BEADM ACTIVATE if BE is not mounted by BEADM MOUNT

This commit is contained in:
Slawomir Wojciech Wojtczak (vermaden) 2012-07-27 14:15:23 +02:00
parent 87029cad37
commit 94556e1f72
1 changed files with 26 additions and 1 deletions

27
beadm
View File

@ -217,6 +217,16 @@ case ${1} in
echo "Already activated" echo "Already activated"
exit 0 exit 0
else else
if mount | grep -E "^${POOL}/ROOT/${2} " 1> /dev/null 2> /dev/null
then
MNT=$( mount | grep -E "^${POOL}/ROOT/${2} " | awk '{print $3}' )
if [ "${MNT}" != "/" ]
then
echo "ERROR: The '${2}' is mounted at '${MNT}'"
echo "ERROR: Cannot activate mounted boot environment"
exit 1
fi
fi
if [ "${ROOTFS}" != "${POOL}/ROOT/${2}" ] if [ "${ROOTFS}" != "${POOL}/ROOT/${2}" ]
then then
TMPMNT="/tmp/BE" TMPMNT="/tmp/BE"
@ -414,7 +424,7 @@ EOF
fi fi
if ! [ ${3} ] if ! [ ${3} ]
then then
TARGET=$( mktemp /tmp/tmp.XXXXXX ) TARGET=$( mktemp -d /tmp/tmp.XXXXXX )
mkdir -p ${TARGET} mkdir -p ${TARGET}
fi fi
if ! mount -t zfs ${POOL}/ROOT/${BE} ${TARGET} if ! mount -t zfs ${POOL}/ROOT/${BE} ${TARGET}
@ -422,12 +432,27 @@ EOF
echo "ERROR: Cannot mount '${POOL}/ROOT/${BE}' at '${TARGET}' mountpoint" echo "ERROR: Cannot mount '${POOL}/ROOT/${BE}' at '${TARGET}' mountpoint"
exit 1 exit 1
fi fi
PREFIX=$( echo ${POOL}/ROOT/${BE}/ | sed 's/\//\\\//g' )
zfs list -H -o name,mountpoint -r ${POOL}/ROOT/${BE} \ zfs list -H -o name,mountpoint -r ${POOL}/ROOT/${BE} \
| grep -v "legacy$" \ | grep -v "legacy$" \
| sort -n \ | sort -n \
| grep -E "^${POOL}/ROOT/${BE}/" \ | grep -E "^${POOL}/ROOT/${BE}/" \
| while read FS MOUNTPOINT | while read FS MOUNTPOINT
do do
if [ "{FS}" != "${POOL}/ROOT/${BE}" ]
then
INHERIT=$( zfs get -H -o source mountpoint ${FS} )
if [ "${INHERIT}" = "local" ]
then
if [ "${MOUNTPOINT}" = "legacy" ]
then
continue
else
MOUNTPOINT=$( echo "${FS}" | sed s/"${PREFIX}"//g )
MOUNTPOINT="/${MOUNTPOINT}"
fi
fi
fi
if ! mkdir -p ${TARGET}${MOUNTPOINT} 1> /dev/null 2> /dev/null if ! mkdir -p ${TARGET}${MOUNTPOINT} 1> /dev/null 2> /dev/null
then then
echo "ERROR: Cannot create '${TARGET}${MOUNTPOINT}' mountpoint" echo "ERROR: Cannot create '${TARGET}${MOUNTPOINT}' mountpoint"