Monday, March 26, 2012

VirtualBox and The Pesky Shared Folder

VirtualBox and Shared Folders

What I learned: if you want full access to your shared folder on VirtualBox, do manual mounts.


System:
Host: Mac OSX 10.7 (a.k.a. "Lion")
Guest: Ubuntu 11.10 (a.k.a. "Oneiric Ocelot")
VirtualBox version: 4.1.10 r76795
VirtualBox Guest Addition version: 4.1.10
Shared Folder name: ~/sharedfolder

Case:
I need to rebuild a database in the guest OS. The database dump is stored in the shared folder (due to limited space in my .vdi), and I need to use it to rebuild the database.

Issue:
I used the command:
~$ sudo su postgres -c "psql -d < path-to-shared-folder/database.pgdump"

Result:
after entering root password, it returned:
"Permission denied"

I checked the permission on the shared folder and the dump file. The file's permission was:
-rwxr-x---

I tried changing the permission to no avail.

Solution: manual mount!

  1. Create a new folder in your HOST system. e.g. ~/sharedfolder
  2. Add the folder to your VirtualBox Guest OS shared folder list
    1. To access the Shared Folders option: select your guest OS > Settings > Shared Folders
    2. Add your shared folder. Make sure NOT to check "Auto-mount" (it's evil). Then click "OK".
  3. Run your guest OS. The following instructions are for Ubuntu only (sorry!).
  4. In your guest OS, create the directory you want the shared folder to be mounted to. For example: /mnt/shared
  5. Open a Terminal and mount your shared folder
  6. Et voila, your file (if you have any in the shared folder) will have the following permission:
    -rwxr-xr-x 1 root root
Only after doing the manual mount, I was able to use the .pgdump file to rebuild the database. Prior to that, it's just a bunch of "Permission denied", "Wrong protocol", "file or folder not found", etc. I can't say whether or not this would work if you want to use a shared folder you already used with Auto-mount. I had to create a new folder for it to work. Let me know if you had a different experience/luck. Signing off...

No comments:

Post a Comment