VM data sharing?

My desktop PC runs Arch (BTW).

On it, I run KVM/QEMU VM’s.

As a Distro Whore, I like different having different distros, for different scenarios: Garuda for Gaming, Ubuntu Studio for Audio & Video stuff etc. and a few others, including Win11, just for fun or specific things to try.

I know sharing “Home” between distros, is a very bad idea, but i’d like an easier way to share the sub-directories (Documents, Downloads etc.) between them, as well as the host. Is there an easy way to set this up for multiple VM’s to point them to these directories on the host system?

VirtioFS and a bash script or something?

Creating a share on the host or network (SMB, NFS, whatever) then mounting that share on each VM worked best for me. no jumping through hoops, plain old tech that works in every OS.

1 Like

Sorry, I should have been more precise. I want to redirect each VM (and host), to use the sub-directories as they would the ones in their own Home. eg anything that would use Documents by default, would seamlessly us the one in the shared Home sub-folder, without me having to mess with symlinks etc. for every directory on every VM.

That make sense?

The magic word is virtiofs

You can add a virtio filesystem to the guest (like with any other hardware) and then mount it via

mount -t virtiofs /sharename ~/Videos. This acts like a filesystem or directory passthrough.

requires the virtiofs package being intalled on the guests. Might just run with libvirt installed, not sure.
Called qemu-virtiofsd in arch repositories.

NFS is the traditional solution for this. Make sure UIDs and GIDs are the same across all systems otherwise more sophisticated configuration is required.

1 Like

Yup. You could even make the nfs host a VM.

I ran NFS on the host and added a 2nd NIC to the VM’s for Host-VM sharing before I tried the new VirtioFS, which I now use. Trouble is, mounting an NFS share on the VM’s slowed down the boot because I had to increase the timeout to make sure the share (on an HDD) mounted every time. Same user and ID’s on all (Linux) VM’s.

I use VirtioFS now for my SteamLibrary, which is great. But I’m trying to find a way to get each VM to use Documents, Downloads, Music, Pictures, Videos in a shared directory, easily. It would be OK to set up once or twice on the VM’s I use permanently, but I want to easily repeat the setup on any new VM’s I want to use, by running a script or something. Any clearer?

Create a network share to hold your /home
In the VM fstab add an SMB mount that mounts the share onto /home
Don’t run more than one VM like this at once.
Another way of doing it would be create an iSCSI drive and mount that into /home

PS, what you’re asking how to do is completely stupid. Better to have an actual network share and use it as a network share.

If it were as simple as mounting a shared directory as /home, I would have. But as /home contains a lot of dotfiles and machine specific configs, it’s a very bad idea.

The method of sharing is irrelevant. I simply want to redirect access to subfolders on each machine without having to set it up manually on all of them.

Stupid would be not to ask the question at all, and remain ignorant.

2 Likes

It’s not entirely clear what you’re trying to do that’s different from having a network share. Sharing the home folder between different VMs is stupid but does seem to be the answer to your question.

No, I want to have a shared folder containing the subdirectories, and have the VM I am using, use those, instead of the ones created in /home.

Eg, If I download an image from Firefox, it would normally go into /home/Downloads by default. Instead, I want it to go into /sharedhome/Downloads by redirecting calls to /home/Downloads to the shared location. Then If I use a different VM later, that image will be accessible in the same place as far as that VM is concerned. Repeat with all other standard /home/subdirs. Still probably doesn’t make sense, I know.

basically your looking to share your data from your host machines files and folders.
with the operating system on each vm and vice versa.
using the host as a share repo for the rest of your virtual machines.

allowing the vm to read and write to the host file system running the vm.
not exactly good for security mate.

in your vm host program is there options for sharing.
i use vbox myself and it just gives you the option of selecting specific folder from the host o.s that can be shared with the vm.
so maybe your vm host program has a similar option that you just have to add paths to.

Yup, just “normal” data. Security-wise, it would probably be more secure than installing everything on the host, and just using that for everything. With the VM’s, only my Games share, and basic data saved in /home (not hidden) would be accessible. The VM’s I just use for testing don’t have any access to shared stuff. Again, sharing a single folder is easy enough, but I want to redirect default storage locations on several machines. Doing that for 5+ folders on each one, pluse future ones, would be a nightmare.

1 Like

I think i’ve found what I need: “~/.config/user-dirs.dirs” seems to containg the paths I need to edit. Hopefully I just need to copy that file, or contents to all the machines.

Thanks for the comments!

So. I could edit the locations and copy/paste everything. But I think a neater solution would be to replace the $HOME variable with a newly defined one like: $SHAREDHOME,

How can I define a new system-wide variable to do this?

1 Like

i think you can define it as a ENV variable.
depending on what terminal your using just save it in the .bashrc or .zshrc
adding each var$ you need to set at boot time.
that way the vars should enable on per user basis.
you can make it system wide with a .systemd edit but.
thats not always the best or most secure.

Got it. Used export to define $SHAREDHOME to /shared/dir/on/host/$USER

Looks like /etc/xdg/user-dirs.defaults contains the global paths to edit, but it only seems able to parse paths relative to $HOME. so I think i’m stuck using bind mounts to mount each dir in the user dirs for now.

Still, it works! Only one directory for multiple machines to back up now

1 Like

Using bind mounts other than temporarily seems a bit of a kludge, IMO, but they can solve problems that sym links don’t, and I had such a problem till I set up a bind mount in /etc/fstab.

Some software can be confused by bind mounts. The find utility, for example.

If the mlocate or plocate packages are installed and updatedb is run (typically a systemd service) it might be good to check the size of the .db file, and review /etc/updatedb.conf. Updatedb was treating all my btrfs subvolume mounts as bind mounts, so setting PRUNE_BIND_MOUNTS to “yes” caused everything useful to be pruned, but set to “no” generated multiple duplicate entries and the .db file balooned to several hundred MB. I’ve had to add directories to PRUNEPATHS to tame it back to ~15 MB.

Yup. It is a kludge. But until my skills improve enough to find a better solution, it will have to do. At least my system is a lot tidier now.

I can’t seen any issues arising, as the Dirs are purely for user data. no settings or configs AFAIK.

1 Like