Tag Archives: VirtualBox

Unable to set permissions within shared folder using Vagrant and VirtualBox

I recently started experimenting with Vagrant (v1.5.1), Puppet (v3.5.1) and VirtualBox (v4.3.10) to replace my MAMP environment. I used the config.vm.synced_folder method in Vagrant to share a folder of websites with the virtual machine.

Since a few directories, like caching and user uploads, need to be writable by Apache, I figured I’d use Puppet to set those permissions, but regardless of where I specified that requirement, it never took effect — and Puppet did try:

Notice: /Stage[main]/Ryse_apache/File[/var/www/domains/domain.com/www/htdocs/wp-content/cache]/owner: owner changed 'vagrant' to 'apache'
Notice: /Stage[main]/Ryse_apache/File[/var/www/domains/domain.com/www/htdocs/wp-content/cache]/group: group changed 'vagrant' to 'apache'

I found out that this was a limitation with VirtualBox and how it shares folders.

Now, Vagrant does have additional options that can be set when sharing a folder that allow you to specify the owner and group, but the problem is that Puppet installs Apache, and since the folders are shared before the Puppet provisioner runs, the Apache user does not yet exist.

This is the error you get:

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u apache`,gid=`getent group apache | cut -d: -f3` /var/www/domains /var/www/domains
mount -t vboxsf -o uid=`id -u apache`,gid=`id -g apache` /var/www/domains /var/www/domains

Let’s look at a few solutions on how to allow Apache to write to the folders it needs to, and which solution I ended up implementing. If you have a different permissions problem, you might still be able to tweak one of the solutions below, since they broadly cover an array of issues.

Continue reading

Increase space on fixed VirtualBox VDI disk containing Windows 7 on Mac

I use VirtualBox on my Mac to have other operating systems at my disposal. One of my appliances contains a copy of Windows 7 with a fixed, 25GB disk. I’ve run out space and was looking for an easy way to increase it.

I came across the modifyhd command, which in theory let’s you increase the disk space, but it only works on dynamic disks. I opted for performance (fixed disk) when I set up the appliance, and this minor inconvenience is the price.

There are several tutorials out there, but many of them require third-party applications, either on the Mac or in Windows side. The thing is, even without those utilities, it’s fairly easy to increase your disk space.

What we’ll do is create a bigger disk, clone the contents from the small disk to the big disk, and then increase our Windows partition.

Continue reading

mount.vboxsf mounting failed with protocol error

I manage several virtual machines via VirtualBox, and one of the first things I do is share a folder between host and guest OS, but when I ran the command this time, I got an error:

/sbin/mount.vboxsf: mounting failed with the error: Protocol error

Turns out, I forgot to share a folder via the VirtualBox UI, but that possibility didn’t even occur to me until much later. So, as short as this blog post is, I’m sure someone else using VirtualBox will run into this, and before you dive into all kinds of solutions, double check that first ;).

Permanently share a folder between host (Mac) and guest (Linux) OS using VirtualBox

This is mainly for my own reference, but here it goes.

1. Share a folder on the host OS

  • In VirtualBox, click your OS on the left and click on Settings.
  • Click on the Shared Folders tab.
  • Click on the folder with the plus on the right.
  • Browse to a folder of your choice in the folder path.
  • Enter a folder name with no spaces e.g. “Share”.
  • Check Auto-mount and Make Permanent, if available.
  • Click on OK.

2. Mount the folder in the guest OS

  • Create a folder in your guest OS that you want to share.
  • Open up Terminal.
  • Type in id and press ENTER— remember that ID.
  • Switch to the root user using sudo su and enter your password.
  • Browse to the etc folder using cd /etc.
  • Edit the rc.local file using vi rc.local.
  • Move your cursor right above exit 0 and press the letter “i” on your keyboard to insert text.
  • Type in the following: sudo mount -t vboxsf -o uid=1000,gid=1000 Share /home/username/Documents/Share
    • 1000 should match the ID you noted down earlier.
    • Share should match the folder name from step 1.
    • username should match your Linux username.
    • /Documents/Share should be the absolute path of the new folder you created.
  • Now hit “ESC”, type :wq and hit ENTER to save and quit the file editing.

After you restart the guest OS, your shared folder will be automatically mounted.