Skip to content

Instantly share code, notes, and snippets.

@ljm42
Last active Feb 26, 2021
Embed
What would you like to do?
#!/bin/bash
#
# Version 1.4
# Latest version of this script: https://gist.github.com/ljm42/a49268b325df3a2e78d5bafec10b5be7
#
# This script will automatically mount any 9p mount tags that exist
# Designed to be run on Unraid through the User Scripts plugin
#
# 9p docs:
# https://wiki.qemu.org/Documentation/9psetup
# https://www.kernel.org/doc/Documentation/filesystems/9p.txt
#
# Other info:
# To list 9p mount points: mount -t 9p
# To unmount 9p share: umount <MOUNT_TAG> or umount /mnt/9p/<MOUNT_TAG>
# To unmount all 9p shares: umount -a -t 9p
#
log() {
echo "$1"
logger -t "mount9p" "$1"
}
MSIZE=$((256 * 1024))
for T in /sys/bus/virtio/drivers/9pnet_virtio/virtio*/mount_tag; do
if [[ ! -f "${T}" ]]; then
log "No 9p mount points defined"
continue
fi
MOUNT_TAG=$(tr -d '\0' <"${T}")
MOUNT_POINT="/mnt/9p/${MOUNT_TAG}"
if [[ $(findmnt -S "${MOUNT_TAG}") ]]; then
log "[${MOUNT_TAG}] already mounted"
elif [[ $(findmnt -M "${MOUNT_POINT}") ]]; then
log "Something already mounted in ${MOUNT_POINT}"
elif [[ -d "${MOUNT_POINT}" && "$(ls -A "${MOUNT_POINT}")" ]]; then
log "${MOUNT_POINT} is not empty"
else
mkdir -p "${MOUNT_POINT}"
mount -t 9p -o trans=virtio,version=9p2000.L,msize="${MSIZE}" "${MOUNT_TAG}" "${MOUNT_POINT}"
retVal=$?
if [[ $retVal -eq 0 ]]; then
log "[${MOUNT_TAG}] mounted as ${MOUNT_POINT}"
else
log "[${MOUNT_TAG}] not mounted error [${retVal}]"
fi
fi
done
#!/bin/bash
#
# Version 1.4
# Latest version of this script: https://gist.github.com/ljm42/a49268b325df3a2e78d5bafec10b5be7
#
# This script will automatically umount anything in /mnt/9p/
# Designed to be run on Unraid through the User Scripts plugin
#
log() {
echo "$1"
logger -t "umount9p" "$1"
}
ROOT9P=/mnt/9p/
# shellcheck disable=SC2231
for MOUNT_POINT in ${ROOT9P}*; do
if [[ ! -d "${MOUNT_POINT}" ]]; then
log "No mount points defined in ${ROOT9P}"
continue
fi
if [[ $(findmnt -M "${MOUNT_POINT}") ]]; then
umount -t 9p "${MOUNT_POINT}"
rmdir "${MOUNT_POINT}"
log "${MOUNT_POINT} unmounted"
fi
done
[[ -d "${ROOT9P}" ]] && rmdir "${ROOT9P}" &>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment