Page MenuHomePhabricator

automatic shared folder mounting in VMs
Closed, ResolvedPublic


Migrated from:

Where we are:

The /mnt/shared folder gets already created by the shared-folder-help package.



Implement this using systemd.

For VirtualBox, use Requires=vboxguest [or so, just do nothing if vboxguest or just output an info if not installed], then run.

mount -t vboxsf -o uid=1000,gid=1000 shared /mnt/shared

For kvm/qemu/libvirt, check necessary conditions(?), then run.

mount -t 9p -o trans=virtio shared /mnt/shared -oversion=9p2000.L



Event Timeline

Patrick raised the priority of this task from to Normal.
Patrick updated the task description. (Show Details)
Patrick added subscribers: Patrick, HulaHoop.

With the migration to systemd, is it now easier to add this?

Patrick set Impact to Needs Triage.

fstab.d should be available in the libmount version in Jessie:

A bug in the kernel causes the regular expression for mounting 9p shares to fail. A tested workaround works in /etc/fstab :

shared /mnt/shared 9p x-systemd.automount,x-systemd.device-timeout=10,trans=virtio,version=9p2000.L,rw 0 0

Tests with fstab.d giving me problems. It could be a matter of not knowing how it works. I first didn't know that there should be a directory called fstab.d and not a file. Apparently configuration files in there should be named a special way:

/etc/fstab.d/00_header.fstab, /etc/fstab.d/50_middle.fstab, /etc/fstab.d/99_end.fstab

A different option for share mounting is /sbin/mount.filetype for example /sbin/mount.nfs. Needs more research doesn't seem as easy as dropping a text file in sbin says fstab.d support has been removed. Not a great long term solution.

systemd could help. It supports ConditionVirtualization=kvm. Has tmpfiles.d. + Running the mount command. Should be doable.

Anyone feel free to submit a tested patch.

systemd can understand mount entries but they still have to be specified in /etc/fstab which won't solve anything.

More information on fstab.d:

Turns out fstab.d is not supported by default in libmount however the mount option can take an alternate mount table file/directory as specified in a command. Please read the linked answer that I'm trying to paraphrase here:

Alternatives to system-wide fstab is to tell udsisks to mount a directory for a user account upon login:

If the manual mount command that does not involve /etc/fstab, i.e. mount -t 9p -o trans=virtio shared /mnt/shared -oversion=9p2000.L work for you in terminal, then a systemd unit file could do the same. Also without requiring /etc/fstab.

Excellent example of shared folder mounting with systemd files in Arch documentation. It will take changing them from vmware to suit KVM and drop them in the same paths for testing:



These units must be "enabled" to make them automatically start with subsequent system startups

Command cheat sheet:

Show the status of a unit, including whether it is running or not:

$ systemctl status unit

Check whether a unit is already enabled or not:

$ systemctl is-enabled unit

Enable a unit to be started on bootup:

  1. systemctl enable unit

Nice. Much better than manually running mount from systemd.

How far I've gone:
I managed to debug errors until I corrected the parameters in the unit files so they should be correct. The remaining error has something to do with the 9p kernel module and I'm not sure where to go from here.

host mount[8341]: mount: mount(2) failed: No such file or directory
host kernel: 9pnet_virtio: no channels available
host systemd[1]: mnt-shared.mount mount process exited, code=exited status=32
host systemd[1]: Failed to mount Load KVM shared folders.


Description=Load KVM shared folders




Description=Load KVM shared folders



Run as root

systemctl daemon-reload
systemctl start mnt-shared.mount
journalctl -xn

q to quit detailed error report by journalctl

edit the files once again and save thenreload daemons and so on.

This option is dead because of some rare bug. There are only 4 search results for it and none of the situations really applies to our setup here.

A solution you probably won't like is patching the fstab file directly.

Something based on the third method on here:

Followed by column -t /etc/fstab to make it reader friendly:

HulaHoop (HulaHoop):

A solution you probably won't like is patching the fstab file directly.


Have systemd run the 'mount' command would be better and should be possible.

Ok I see what you're talking about.

The mount command is placed in a regular script file and then a custom systemd service is configured to execute it on startup:

I can do the systemd service file part but I'm unsure as to how the script should look like. If its as simple as pasting the command I use in there, no problem.

Yes, somewhat.

I don't think you need a separate script. Instead of running a single
line script, you could try running the mount command directly from the
systemd unit file.

Great news! automatic shared folders is now achieved :D

I used this as an example:

Two systemd service files were created under /etc/systemd/system/

To enable and start them:

sudo systemctl enable service-name
sudo systemctl start service-name


Description=Mounts KVM shared folder during start

ExecStart=/bin/mount -t 9p -o trans=virtio shared /mnt/shared -oversion=9p2000.L



Description=Mounts VirtualBox shared folder during start

ExecStart=/bin/mount -t vboxsf -o uid=1000,gid=1000 shared /mnt/shared




  • In section [Unit] it should probably use After= something. I.e. make it run after VBox / KVM guest additions.
  • debian/rules modifications
  • debian/control modifications
  • use /lib/systemd/system/
  • commit to shared-folder-help package
  • build package, test if it actually works

What is the name of the systemd vbox guest additions service so I can add it? KVM does not rely on spice or a guest additions equivalent to share folders.

A vbox guest additions dependency only makes sense if its installed by default.

How to find out? Look manually into /etc/init.d/virtualbox-guest-utils
(or systemd unit files if it had those) and/or 'grep -i provides


OK I edited my comment and added those in under the Unit section.

Patrick changed Impact from Needs Triage to Normal.
Patrick changed the task status from Open to Review.Aug 6 2015, 3:27 PM

Merged. Requires testing when new test images get available.

In T144#6289, @Patrick wrote:

Merged. Requires testing when new test images get available.

Does it work in KVM?

Patrick claimed this task.

@HulaHoop reported it works in KVM.