Improved initial mount & 'snapshots' subvolume check
This commit is contained in:
parent
a13cba3790
commit
d502f26ed8
38
snapsh
38
snapsh
|
@ -60,39 +60,29 @@ mount_check() {
|
||||||
# Check that the toplevel subvolume (id=5) is mounted, and if not,
|
# Check that the toplevel subvolume (id=5) is mounted, and if not,
|
||||||
# mount it to path defined in $TOPLEVEL
|
# mount it to path defined in $TOPLEVEL
|
||||||
|
|
||||||
mount | grep subvolid=5 | grep "${TOPLEVEL}" > /dev/null
|
if ! mount | grep subvolid=5 | grep "${TOPLEVEL}" &> /dev/null; then
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
# Get the UUID of the current btrfs volume
|
# Get the UUID of the current btrfs volume
|
||||||
MOUNT_UUID=$(btrfs filesystem show | grep uuid | cut -d ':' -f 3)
|
MOUNT_UUID=$(btrfs filesystem show | grep uuid | cut -d ':' -f 3)
|
||||||
# Create the mountpoint for the toplevel if needed
|
# Create the mountpoint for the toplevel if needed
|
||||||
[[ -d ${TOPLEVEL} ]] || mkdir -p ${TOPLEVEL}
|
[[ -d ${TOPLEVEL} ]] || mkdir -p ${TOPLEVEL}
|
||||||
# Mount the toplevel
|
# Mount the toplevel
|
||||||
mount -U ${MOUNT_UUID} -o subvolid=5 ${TOPLEVEL}
|
mount -U ${MOUNT_UUID} -o subvolid=5 ${TOPLEVEL}
|
||||||
|
printf "Created mountpoint ${TOPLEVEL} for the top level subvolume.\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n ${SNAPSHOT} ]]; then
|
# Check that the subvolume for storing snapshots exists, and if not,
|
||||||
# If taking a snapshot,
|
# ask to create it
|
||||||
# check that the subvolume storing snapshots exists and if not, ask
|
if ! ${BTRFS_EXECUTABLE} subvolume show ${SNAPSHOTS_LOCATION} &> /dev/null; then
|
||||||
# to create it.
|
printf "Subvolume ${SNAPSHOTS_LOCATION} does not exist. Create it now? "
|
||||||
${BTRFS_EXECUTABLE} subvolume show ${SNAPSHOTS_LOCATION} > /dev/null
|
read -n 1 -p "y/n: "
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
printf "Subvolume ${SNAPSHOTS_LOCATION} does not exist. Create it now?\n"
|
|
||||||
read -n 1 -p "y/n: "
|
|
||||||
|
|
||||||
if [[ "${REPLY}" == "y" ]]; then
|
if [[ "${REPLY}" == "y" ]]; then
|
||||||
# Create subvolume defined with SNAPSHOTS_LOCATION
|
printf "\n"
|
||||||
${BTRFS_EXECUTABLE} subvolume create ${SNAPSHOTS_LOCATION}
|
# Create subvolume defined with SNAPSHOTS_LOCATION
|
||||||
unset ${REPLY}
|
${BTRFS_EXECUTABLE} subvolume create ${SNAPSHOTS_LOCATION}
|
||||||
else
|
unset ${REPLY}
|
||||||
exit 1
|
else
|
||||||
fi
|
printf "\n$0 needs the 'snapshots' subvolume to operate. Please see README.md\n"
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Otherwise, just check that the subvolume in SNAPSHOTS_LOCATION
|
|
||||||
# exists, and notify if not.
|
|
||||||
${BTRFS_EXECUTABLE} subvolume show ${SNAPSHOTS_LOCATION} > /dev/null
|
|
||||||
if [[ "$?" -ne 0 ]]; then
|
|
||||||
printf "Subvolume ${SNAPSHOTS_LOCATION} does not exist.\n"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue