Using tar on a VirtualBox shared drive

I set up my laptop using VirtualBox with several virtual machines.  The last time I set up a machine this way, I ended up with some VMs with large drives that I didn’t use, and I ran out of space on the host.  To avoid this on my new machine, I decided this time to keep my VMs as small as possible, and do all major work on shared drives.

So, I was running a build on the shared drive, when I hit this error:

Cannot utime: Operation not permitted

This error isn’t very helpful, but I was able to google around until I found out that this error can happen if you don’t have full ownership of the files you’re trying to tar.  The next step was to figure out why my user didn’t have full ownership of those files.

It seems that if you use the VirtualBox Guest Additions to share folders, you have no option to set any options for the mounted folder.  This means that all files are owned by root.  Most of the time this is not a problem, but tar was very unhappy with this.

You cannot edit the /etc/fstab file to mount the drive automatically, because the shared folder module is not loaded before the file is processed (see the VB forum link below). So, for the time being I have manually mounted the drive with options that give my user ownership over files:

sudo mount -t vboxsf -o uid=1000,gid=1000 <shared folder> <mount point>

According to the VirtualBox forums, it looks like you can add this line to the /etc/rc.local file to mount at startup.  As soon as I have to reboot I will try this.

Leave a Reply

Your email address will not be published. Required fields are marked *