diff --git a/beadm b/beadm index 44c7d75..185af09 100755 --- a/beadm +++ b/beadm @@ -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 @@ -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 @@ -69,6 +69,7 @@ __usage() { echo " ${NAME} rename " echo " ${NAME} mount [mountpoint]" echo " ${NAME} { umount | unmount } [-f] " + echo " ${NAME} chroot " echo " ${NAME} reroot " echo " ${NAME} version" exit 1 @@ -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}'" @@ -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 @@ -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} diff --git a/beadm.8 b/beadm.8 index 553ddc2..0139496 100644 --- a/beadm.8 +++ b/beadm.8 @@ -15,7 +15,7 @@ .\" @(#)beadm.8 .\" $FreeBSD$ .\" -.Dd December 1, 2020 +.Dd May 6, 2022 .Dt BEADM 8 .Os .Sh NAME @@ -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 @@ -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