Use a service for virtiofs for better control.

This commit is contained in:
Andreas B. Mundt 2023-09-04 07:59:43 +02:00
parent 51cb0a2804
commit 7fd6c76996
4 changed files with 24 additions and 25 deletions

View file

@ -10,27 +10,7 @@ if [[ $# -ne 1 ]]; then
fi
VM_NAME="$1"
XDG_RUNTIME_DIR="/run/user/${SUDO_UID}"
## Make sure VMs can read the base directory:
chgrp 1010 "/lmn/media/${SUDO_USER}"
if ! [[ -d "${XDG_RUNTIME_DIR}/virtiofs" ]]; then
mkdir "${XDG_RUNTIME_DIR}/virtiofs/"
chown "${SUDO_UID}" "${XDG_RUNTIME_DIR}/virtiofs/"
fi
if [[ -S "${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock" ]] ; then
/usr/bin/rm "${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock"
fi
#sudo /usr/lib/qemu/virtiofsd --socket-path="${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock" \
# --socket-group="${SUDO_USER}" --announce-submounts -o source="/media/${USER}" > /dev/null &
#sudo /usr/lib/qemu/virtiofsd --socket-path="${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock" \
# --socket-group="${SUDO_USER}" -o source="/media/${USER}" > /dev/null &
/usr/lib/qemu/virtiofsd --socket-path="${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock" \
-o source="/lmn/media/${SUDO_USER}/" &
# Wait until socket-File exists and chown to user
until [[ -S "${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock" ]]; do
echo "waiting for ${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock"
sleep 0.1
done
/usr/bin/chown "${SUDO_USER}" "${XDG_RUNTIME_DIR}/virtiofs/${VM_NAME}-clone.sock"
systemctl restart virtiofs@${VM_NAME}-clone:${SUDO_USER}.service