Skip to content

Commit

Permalink
Add chroot(8) feature. Some minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vermaden committed May 6, 2022
1 parent 75f7f38 commit f3b6d85
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
33 changes: 26 additions & 7 deletions beadm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PATH=${PATH}:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
# check FreeBSD version
if [ $( uname -r | cut -d '-' -f1 | cut -d '.' -f1 ) -lt 8 ]
then
echo "ERROR: beadm works on FreeBSD 8.0 or later"
echo "ERROR: beadm(8) works on FreeBSD 8.0 or later"
exit 1
fi

Expand All @@ -50,7 +50,7 @@ then
echo " / / // ___// / // / // / / /\ \ / / // / "
echo " \____/ \____/ \_____\\\____//__/__/__/ \_\\\____//_/ "
echo
echo "beadm 1.3.4 2022/03/09"
echo "beadm 1.3.5 2022/05/06"
echo
exit 0
fi
Expand All @@ -69,6 +69,7 @@ __usage() {
echo " ${NAME} rename <origBeName> <newBeName>"
echo " ${NAME} mount <beName> [mountpoint]"
echo " ${NAME} { umount | unmount } [-f] <beName>"
echo " ${NAME} chroot <beName>"
echo " ${NAME} reroot <beName>"
echo " ${NAME} version"
exit 1
Expand Down Expand Up @@ -889,8 +890,8 @@ EOF
else
__usage
fi
__be_exist "${POOL}/${BEDS}/${2}"
if __be_mounted "${POOL}/${BEDS}/${2}"
__be_exist ${POOL}/${BEDS}/${2}
if __be_mounted ${POOL}/${BEDS}/${2}
then
MNT=$( mount | grep -E "^${POOL}/${BEDS}/${2} " | awk '{print $3}' )
echo "Boot environment '${2}' is already mounted at '${MNT}'"
Expand Down Expand Up @@ -953,8 +954,8 @@ EOF
else
__usage
fi
__be_exist "${POOL}/${BEDS}/${2}"
if ! __be_mounted "${POOL}/${BEDS}/${2}"
__be_exist ${POOL}/${BEDS}/${2}
if ! __be_mounted ${POOL}/${BEDS}/${2}
then
echo "Boot environment '${2}' is not mounted"
exit 1
Expand All @@ -980,11 +981,29 @@ EOF
# delete only when it is empty directory
if [ $( find ${MOUNTPOINT} | head | wc -l | bc ) -eq 1 ]
then
rm -r ${MOUNTPOINT}
rm -r "${MOUNTPOINT}"
fi
fi
;;

(chroot) # ----------------------------------------------------------
if [ ${#} -ne 2 ]
then
__usage
fi
__be_exist ${POOL}/${BEDS}/${2}
if ! __be_mounted ${POOL}/${BEDS}/${2}
then
"${0}" mount "${2}" 1> /dev/null 2> /dev/null
fi
MOUNT=$( mount )
MOUNTPOINT=$( echo "${MOUNT}" | grep -m 1 "^${POOL}/${BEDS}/${2} on " | awk '{print $3}' )
echo "Entered chroot(8) for '${2}' boot environment"
chroot "${MOUNTPOINT}"
"${0}" umount -f "${2}" 1> /dev/null 2> /dev/null
echo "Leaved from chroot(8) for '${2}' boot environment"
;;

(reroot) # -----------------------------------------------------------------
# activate new BE which would also set new root filesystem using kenv(1)
${0} activate ${2}
Expand Down
14 changes: 13 additions & 1 deletion beadm.8
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.\" @(#)beadm.8
.\" $FreeBSD$
.\"
.Dd December 1, 2020
.Dd May 6, 2022
.Dt BEADM 8
.Os
.Sh NAME
Expand Down Expand Up @@ -52,6 +52,10 @@
.Nm
.Cm umount Op Fl f Ar beName
.Nm
.Cm chroot Ar beName
.Nm
.Cm reroot Ar beName
.Nm
.Cm version
.Sh DESCRIPTION
The
Expand Down Expand Up @@ -165,6 +169,14 @@ This command can be called with either
.Cm umount
or
.Cm unmount .
.It Cm chroot
Enter to selected boot environment with the
.Xr chroot 8
command.
.It Cm reroot
Use 'reroot' feature from the
.Xr reboot 8 -r
command.
.It Cm version
Print the
.Nm
Expand Down

0 comments on commit f3b6d85

Please sign in to comment.