diff options
-rwxr-xr-x | kvmx | 39 | ||||
-rw-r--r-- | kvmxfile | 6 |
2 files changed, 44 insertions, 1 deletions
@@ -270,6 +270,25 @@ function kvmx_up { #local shared="-net user,smb=$shared_folder" # See http://wiki.qemu-project.org/Documentation/9psetup local shared="-fsdev local,id=shared,path=$shared_folder,security_model=none -device virtio-9p-pci,fsdev=shared,mount_tag=shared" + elif [ ! -z "$shared_folders" ]; then + local old_ifs="$IFS" + local shared_item + local shared + IFS="," + for shared_item in $shared_folders; 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`" + + # Get absolute path of shared folder relative to project path + shared_folder="`cd $KVMX_PROJECT_FOLDER && cd $shared_folder &> /dev/null && pwd`" + + shared="$shared -fsdev local,id=$id,path=$shared_folder,security_model=none -device virtio-9p-pci,fsdev=$id,mount_tag=$id" + + unset shared_folder + unset shared_folder_mountpoint + done + IFS="$old_ifs" fi if [ ! -z "$port_mapping" ]; then @@ -391,6 +410,26 @@ function kvmx_up { echo "sudo mkdir -p $shared_folder_mountpoint" | kvmx_ssh echo "sudo mount -t 9p -o trans=virtio shared $shared_folder_mountpoint -oversion=9p2000.L,posixacl,cache=none -o sync -o dirsync" | kvmx_ssh #echo "sudo mount //10.0.2.4/qemu $shared_folder_mountpint" | kvmx_ssh + elif [ ! -z "$shared_folders" ]; then + local old_ifs="$IFS" + local shared_item + IFS="," + for shared_item in $shared_folders; 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`" + + # Get absolute path of shared folder relative to project path + shared_folder="`cd $KVMX_PROJECT_FOLDER && cd $shared_folder &> /dev/null && pwd`" + + # Restore IFS for a while or kvmx_ssh won't work + IFS="$old_ifs" + echo "Mounting $shared_folder on $shared_folder_mountpoint $id on guest..." + echo "sudo mkdir -p $shared_folder_mountpoint" | kvmx_ssh + echo "sudo mount -t 9p -o trans=virtio $id $shared_folder_mountpoint -oversion=9p2000.L,posixacl,cache=none -o sync -o dirsync" | kvmx_ssh + IFS="," + done + IFS="$old_ifs" fi fi @@ -11,10 +11,14 @@ user="user" # First user password password="`head -c 20 /dev/urandom | base64`" -# Set this is you want to be able to share folders between host and guest. +# Set this is you want to be able to share a single folder between host and guest. shared_folder="." shared_folder_mountpoint="/home/$user/code/$VM" +# Set this is you want to be able to share multiple folders between host and guest. +# Format: <id1>:<host-folder1>:<guest-mountpoint1>,<id2>:<host-folder2>:<guest-mountpoint2>[,...] +#shared_folders="shared1:.:/home/$user/code/$VM,shared2:$HOME/.local/share/app:/home/$user/.local/share/app" + # Folder to sync during provisioning in the format "/host/folder /guest/folder". #provision_rsync="$KVMX_BASE/share/provision/ /usr/local/share/kvmx/provision/" |