The regular way of getting access to the files now, is to allow VirtualBox to automount the shared folder (which will make it show up under /media/sf_directory_name
) and then to add your regular Ubuntu user to the vboxsf
group (as root #
).
# usermod -aG vboxsf <youruser>
By default, without manual action, the mounts look like this,
drwxrwx--- 1 root vboxsf 40960 Oct 23 10:42 sf_<name>
so the vboxsf
group has full access. By adding your user to that group, you gain full access. So you wouldn't worry about changing their permissions (which don't make sense on the Windows host), you just give yourself access.
In this specific case, this is the automounted Shared Folder,
Ubuntu 214153212 31893804 182259408 15% /media/sf_Ubuntu
and it is that directory that should be used to access to the Shared Folder, by putting the local user into the vboxsf
group. If you want a 'better' link under your user's home directory, you could always create a symbolic link.
ln -s /media/sf_Ubuntu /home/m/Desktop/vbox_shared
You will need to reboot your VM for these changes to take effect
If you manually mount the shared folder, then you need to use the relevant options on the mount
command to set the folder with the right ownership (i.e. the gid, uid and umask options to mount
). This is because the Host OS doesn't support the same permission system as Linux, so VirtualBox has no way of knowing who should own the files.
However, I strongly recommend just configuring the shared folder to be auto-mounted (it's a setting on the Shared Folder configuration in VirtualBox itself).
For the avoidance of doubt, I do not believe you can change permissions normally anyway, on that filesystem if it's mounted in the regular way,
tony@jabba:/media/sf_name$ ls -l tst.txt
-rwxrwx--- 1 root vboxsf 2283 Apr 4 2012 tst.txt
tony@jabba:/media/sf_name$ sudo chown tony tst.txt
[sudo] password for tony:
tony@jabba:/media/sf_name$ ls -l tst.txt
-rwxrwx--- 1 root vboxsf 2283 Apr 4 2012 tst.txt
tony@jabba:/media/sf_name$
I realize this is a very old post but I just recently solved this exact problem by submitting patches to libvirt. Starting in libvirt v6.10, you'll be able to specify the "fmode" and "dmode" options on 9pfs shares which control the default host permissions on files and directories, respectively.
If you can't run v6.10, I found a workaround using the qemu:commandline
feature of libvirt's XML domain to pass the raw QEMU flags. I wrote a blog post about how to do this but the quick version is to put something like
<commandline xmlns="http://libvirt.org/schemas/domain/qemu/1.0">
<arg value="-fsdev"/>
<arg value="local,security_model=mapped,id=fsdev-fs0,path=/path/to/share,fmode=0644,dmode=0755"/>
<arg value="-device"/>
<arg value="virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,mount_tag=sharename,bus=pci.6,addr=0x0"/>
</commandline>
into your domain XML as a child of "domain." The blog post goes into more detail about the values but you may need to tweak fsdev-fs0
, fs0
, and sharename
to fit your domain.
Best Answer
You may be able to use one of the polling tools that pre-date dnotify and inotify: gamin or fam, along with something like fileschanged which is an
inotifywait
-like CLI tool. The gamin and fam projects are related, and both quite old (though gamin slightly less so).For simple and portable tasks I have used something like this via cron:
This uses primitive locking, and a GNU
find
conditional to only find files older than two minutes so I could be sure that files were completely written. In my casemyprocess
was anrsync --remove-source-files --files-from=-
so that files were removed once they were processed.This approach also lets you use
find -print0
/xargs -0
/rsync -0
to handle troublesome filenames.If you must keep all (old and new) files in the same directory hierarchy, then building directory-listing snapshots and diff-ing them might also work for you:
This
bash
script:find -printf
to print a \0 (nul) delimited list of filesread -d ''
to process that list, andprintf %q
to escape filenames where necessarymyprocess
with each new file (safely quoted)(Also handling modified files would require slightly more effort, a double-line format with
find ... -printf '%p\0%s %Ts\0'
could be used, with associated changes to thewhile
loops.)