valibuk.net

A place for opinions and notes of a valibuk.

Accessing Mac OS X harddrive from Ubuntu in VirtualBox via shared folders

Tagged with: — ondrej at 12:25 am on Sunday, March 8, 2009

I installed Ubuntu in a VirtualBox machine on OS X (pretty easy and straightforward), but to access a Mac harddrive from Ubuntu was slightly more complicated.

I. Install Guest Additions

Firstly, it is necessary to install the VirtualBox’s Guest Additions to the host system:

  1. Choose in the VitualBox’s menu: Devices -> Install Guest Additions
    It mounts a new ISO for the host system.
  2. A new CD appears in Ubuntu (or mount it). Run as root the VBoxLinuxAdditions-x86.run installation script (because it is an Intel based Mac) in a Terminal window:

    cd /media/cdrom
    sudo VBoxLinuxAdditions-x86.run
    
  3. Probably you will be asked to restart Ubuntu.

Installing the Guest Additions has many advantages such as adopting screen resolution (your window size is the system resolution, i.e. no scrollbars), easy mouse mode (no need to press the left command button to release the mouse cursor) and, what we are looking for, shared folders.

II. Create Shared Folder

The goal is to access a shared folder, what is an easier way than to use sshd or Samba.

  1. Choose in the VitualBox’s menu: Devices -> Shared Folders...
  2. Click on the Add new shared folder button.
  3. Choose a Folder Path - a folder on your Mac harddrive, e.g. /Users/ondrej/Pictures.
    Choose a Folder Name - a name that identifies this shared folder in Ubuntu (as a host system), e.g. pictures.
    Select Make Permanent - if you would like to persist this shared folder definition.
    Click on OK.
  4. Click OK to close the list of shared folders.

III. Mount Shared Folder
Mount the created shared folder into a folder with permissions for your user. Let’s open a Terminal window on Ubuntu and:

  1. Create a folder where will be the shared folder mounted. (Skip this step if have already a folder for this.)
    mkdir DIR
    

    e.g.

    mkdir share
    
  2. Get your user uid.
    id

    The result will be something like:

    uid=1000(ondrej)gid=1000(ondrej)groups=4(adm),20(dialout),24(cdrom),
    46(plugdev),112(lpadmin),119(admin),120(sambashare),1000(ondrej)
    

    so uid of my user is 1000.

  3. Mount the shared folder SHARED_FOLDER_NAME into folder MOUNTED_FOLDER with ownership for user with uid USER_ID as root:
    sudo mount -t vboxsf -o uid=USER_ID SHARED_FOLDER_NAME MOUNTED_FOLDER
    

    e.g.

    sudo mount -t vboxsf -o uid=1000 pictures share
    
  4. The mounted folder MOUNTED_FOLDER (e.g. share) contains files from the shared folder on your Mac harddrive.

Enjoy :)

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • DZone
  • Digg
  • Reddit
  • Technorati
  • Furl
  • NewsVine
  • Slashdot
  • Ma.gnolia
  • StumbleUpon

7 Comments »

Comment by André

April 27, 2009 @ 2:35 am

Thank you! Just what I was looking for.

Comment by Roberto

May 10, 2009 @ 8:27 pm

Thank you,

How would I have the share folder auto mount upon boot up?

Presently I have to manually mount the share folder every time I restart.

Roberto

Comment by Spencer9

June 21, 2009 @ 9:24 am

Thank you! Excellent post.

Comment by olivier

September 14, 2009 @ 2:43 pm

Thank you very much.
Solved my problem.

Comment by dodo

November 17, 2009 @ 5:37 pm

top quality post!
thanks :)

Comment by Julian

December 10, 2009 @ 4:20 pm

Ditto @Roberto - how do I make it stick? Thanks from a n00b!

Comment by ondrej

December 21, 2009 @ 12:15 am

automatic mounting could be done as auto-starting the mount command:

1. create a script for mounting:
cat sudo mount -t vboxsf -o uid=USER_ID SHARED_FOLDER_NAME MOUNTED_FOLDER > /etc/init.d/vbox_automount

2. set permissions for the file to be executable:
chmod +x /etc/init.d/vbox_automount

3. to tell the system to start the script at boot (this is a linux distro dependent command - for ubuntu):
sudo update-rc.d vbox_automoun defaults

[not tested, sorry]

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment Preview


commercial break :)

Make an account on slicehost.com -- a really good hosting where you have your own virtual machine. I installed Gentoo there = I like it very much ;)