From ab82ad7fa360a32e76fa0f2371a842877929e876 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Mon, 7 Oct 2019 19:07:08 -0300 Subject: Adds shared_folders_sshfs config --- IDEAS.md | 1 - README.md | 2 +- kvmx | 25 ++++++++++++++++++++++++- kvmxfile | 7 ++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/IDEAS.md b/IDEAS.md index bf9f47a..0b7e341 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -8,7 +8,6 @@ * https://bbs.archlinux.org/viewtopic.php?id=177299 * Alternative folder sharing support: * NFS, SMB. - * Using [sshfs like vagrant-libvirt](https://fedoramagazine.org/vagrant-sharing-folders-vagrant-sshfs/). * Or even [SSH to a server](https://superuser.com/questions/831659/mount-a-local-directory-to-a-remote-ssh-server)). * Remount 9p shared folders and reinitialize spice-vdagent upon resume from disk [see possible bug](https://bugzilla.redhat.com/show_bug.cgi?id=1333072). * [Nested virtualization](http://www.rdoxenham.com/?p=275) ([1](https://wiki.archlinux.org/index.php/KVM#Nested_virtualization), [2](https://ladipro.wordpress.com/2017/02/24/running-hyperv-in-kvm-guest/)). diff --git a/README.md b/README.md index ecae6d5..7e1c56c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ sources, you'll feel welcome here :) KVMX currently needs a Debian-based system and the following dependencies: - sudo apt install git qemu qemu-kvm virt-viewer spice-client spice-client-gtk socat screen + sudo apt install git qemu qemu-kvm virt-viewer spice-client spice-client-gtk socat screen sshfs If you plan to create guest images, you may also want the following packages: diff --git a/kvmx b/kvmx index 616631d..ae85762 100755 --- a/kvmx +++ b/kvmx @@ -632,6 +632,27 @@ function kvmx_up { IFS="$old_ifs" fi + # Shall we add an umount hook when powering off the guest? + if [ ! -z "$shared_folders_sshfs" ]; then + local old_ifs="$IFS" + local shared_item + IFS="," + for shared_item in $shared_folders_sshfs; do + local id="`echo $shared_item | cut -d ':' -f 1`" + local shared_folder="`echo $shared_item | cut -d ':' -f 2`" + local shared_folder_mountpoint="`echo $shared_item | cut -d ':' -f 3`" + + # Temporaly reset IFS so kvmx_sshfs executes correctly + IFS="$old_ifs" + kvmx_sshfs $shared_folder $shared_folder_mountpoint + IFS="," + + unset shared_folder + unset shared_folder_mountpoint + done + IFS="$old_ifs" + fi + if [ "$xrandr" == "1" ] && [ "$run_spice_client" == "1" ]; then echo "Waiting for X11 to come up so we can set machine resolution..." sleep 8 @@ -799,7 +820,9 @@ function kvmx_sshfs { fi SSH="`cat $SSHFILE`" - sshfs $SSH_LOGIN@127.0.0.1:$folder $mountpoint $SSH_OPTS -o nonempty -p $SSH + + # See https://github.com/libfuse/sshfs/issues/82 about "-o writeback_cache=no" + sshfs $SSH_LOGIN@127.0.0.1:$folder $mountpoint $SSH_OPTS -o nonempty -o sshfs_sync -o sync_readdir -o cache=no -o follow_symlinks -o sync_read -o workaround=rename -o noforget -p $SSH } # Get guest PID diff --git a/kvmxfile b/kvmxfile index d9cc787..860dfe3 100644 --- a/kvmxfile +++ b/kvmxfile @@ -35,7 +35,7 @@ shared_folder_mountpoint="/home/$user/code/$VM" #shared_folder_mountpoint="/srv/kvmx" #shared_folder_mountpoint="/vagrant" -# Set this is you want to be able to share multiple folders between host and guest. +# Set this is you want to be able to share multiple folders between host and guest using 9p. # Needs ssh_support set to "y" and a workable SSH connection to the guest. # Format: ::,::[,...] #shared_folders="shared1:.:/home/$user/code/$VM,shared2:$HOME/.local/share/app:/home/$user/.local/share/app" @@ -49,6 +49,11 @@ shared_folder_mountpoint="/home/$user/code/$VM" # See https://www.kernel.org/doc/Documentation/filesystems/9p.txt #shared_folders_cache="none" +# Set this is you want to be able to share multiple folders between host and guest using SSHFS. +# Needs ssh_support set to "y" and a workable SSH connection to the guest. +# Format: ::,::[,...] +#shared_folders_sshfs="shared1:/home/$user/code/$VM:.,shared2:/home/$user/.local/share/app:$HOME/.local/share/app" + # Folder to sync during provisioning in the format "/host/folder1 /guest/folder1,/host/folder2 /guest/folder2[,...]". # Needs ssh_support set to "y" and a workable SSH connection to the guest. #provision_rsync="$KVMX_BASE/share/provision/ /usr/local/share/kvmx/provision/" -- cgit v1.2.3