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.

Updated on January 19, 2011: updates based on helpful comments :) thanks
Updated on September 7, 2011: clearer instructions for the automatic mounting
Updated on January 3, 2012: please check also the last comments for the latests updates

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. (in /tmp)

    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 /tmp/share
    

    Specifying the uid parameter enables writing to the shared folder for your user.

  4. The mounted folder MOUNTED_FOLDER (e.g. /tmp/share) contains files from the shared folder on your Mac harddrive. It is possible to write to the share folder as well.
  5. Optionally, a shared folder can be automatically mounted on the virtual machine start.
    Add the following line to the /etc/fstab file (as root, e.g. sudo vim /etc/fstab):

    SHARED_FOLDER_NAME /PATH/TO/MOUNTED/FOLDER vboxsf uid=1000,gid=1000 0 0
    

    e.g.

    pictures /tmp/share vboxsf uid=1000,gid=1000 0 0
    

    where the uid and gid values can be find in the output of the id command (see the step 2 for detailed example).
    The shared folder will be available also after a restart of the virtual machine.

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

19 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]

Comment by nickrud

August 25, 2010 @ 12:30 am

Thanks for this – been a while since I’d done this and it was a very good reminder. A good answer to the ‘how to mount on virtual machine start’ is to add a line to /etc/fstab.

vbox /PATH/TO/SHARED/FOLDER vboxsf uid=1000,gid=1000 0 0

will work just fine.

Comment by Andrew

September 26, 2010 @ 4:09 am

Thanks, this is very helpful as it includes correct information for mounting share folder with ability to write to share [maybe you could make this more explicit in the step for finding user id]. Also, can you include the last comment by Nickrud as a last step in the instructions for those that want to mount the folder on startup by editing fstab?
In any case, hard to find all this info in one place elsewhere. Good job!

Comment by jesustadeo

January 19, 2011 @ 4:32 pm

Hey! thank you so much this is the best tutorial ever! ive been trying to do this since 2 weeks searching and searching.
Thank you so much again!
(;

Jesus

Comment by John

September 6, 2011 @ 10:31 pm

Nice instructions.

In Ubuntu 11.04 I am having trouble finding my mounted folder.

1) I go into Devices->Shared Folders drop-down

2) I see …

Machine folders
local_folder_name /OSX/folder/shared Yes on auto Mount and Full on Access

3) But looking at my Ubuntu filesystem I am not finding “local_folder_name” anywhere

Have I left out something in the mounting process?

Thanks

Comment by ondrej

September 7, 2011 @ 12:21 am

hi John,

thank you :)

what you refer as the “local_folder_name” is actually only a reference name or a label – provided for the hosted system by VirtualBox. only then the vboxsf file system type (a part of the VirtualBox’s Guest Additions) is able connect the label with a real directory on the hosted system – Ubuntu.

it can be described also as:
[OS X folder] -> [SHARED_FOLDER_NAME label] -> [Ubuntu MOUNTED_FOLDER]

so to use the example values mentioned in the blog entry above:
[/Users/ondrej/Pictures] -> [pictures] -> [/home/ondrej/share]

please, check the part III., especially step III.3, e.g.:
sudo mount -t vboxsf -o uid=USER_ID local_folder_name /tmp/here_i_am
connects the “local_folder_name” label with the real directory “/tmp/here_i_am” in Ubuntu.

i hope it works :)

Comment by Ali

September 18, 2011 @ 11:57 pm

I followed your steps . but I still was not able to share.

please your help

Comment by Jose

October 10, 2011 @ 9:39 am

Hi there,

Very helpfull post, thanks!

Just wanted to add… from my experience…. once you installed the Guest Additions and created the shared folder, if you checked the auto-mount item in the configuration, the folder will be available in the “/media/sf_whatever_you_called_your_folder” directory.

Just creating a simlynk from there to wherever you´d like to place it, will avoid you the user id stuff and editing fstab.

Cheers.

Jose

Comment by Aurea

November 29, 2011 @ 1:29 pm

Thank you!!!

Comment by Harry Wood

January 3, 2012 @ 4:30 pm

I got this to work just now with VirtualBox 4.1.8. and ubuntu 11. Some notes:

* The ‘Devices’ menu appears when you’re running the guest virtual machine, and have it’s window open. If in fullscreen you get the ‘Devices’ menu down below (I was looking in the wrong place for a long time)
* As Jose says above, you can skip a few of these steps with the “Auto mount” option now provided by Virtual box: https://www.virtualbox.org/manual/ch04.html#sf_mount_auto
* In the guest ubuntu (after a restart) this mounts the drive under /media, but you’ll get ‘permission denied’ until you add your user to the ‘vboxsf’ group. (And as an additional fun hurdle, the ubuntu 11 no longer comes with the gui tool to manage groups! To get pointy-clicky group config you can do: sudo apt-get install gnome-system-tools )

Comment by openwiki500

February 9, 2012 @ 10:49 pm

I confirm last comment.
Problem : permission denied :
Solve : add you user in group vboxsf
(sudo adducer user vboxsf )
Thanks.

Comment by Dimas

June 12, 2012 @ 12:43 pm

Thanks, Thanks, Thanks.

Comment by Shane

February 8, 2013 @ 7:27 pm

Thanks!!! Worked like a champ. If updates like a Kernel are updated, then usually the vbox guest additions needs to be re-installed, if Linux is your guest.

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=""> <s> <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 ;)