Alright, the title is a little bit grand. In any case, let it be known that I pretty much hate darwinports and fink, as something always seems to go wrong when I try to use them. [Although, they are very necessary for development in OSX -- and I am certain I won't be able to get by without them]
In this tutorial I will briefly explain how to tightly integrate VirtualBox into OSX as an Ubuntu Host. [This would probably work with other Virtual Machines, but I'll use VirtualBox as my example because it's free.
- First, Download and install VirtualBox from Virtualbox.org
- Second, download and a recent 32-bit ubuntu ISO from ubuntu.org
- Install Ubuntu under VirtualBox, remember the name of your virtualbox, you will need it later -- there are many tutorials around, and for anyone who wants ubuntu running in virtualbox, this should be pretty straight forward
- On ubuntu install some key packages:
apt-get install ssh smbfs
- Also create a .ssh directory inside of your home directory (i.e.
mkdir ~/.ssh
)
- Shut down your Ubuntu VirtualBox
- Open up a Terminal (on your OSX box)
cd /Applications/VirtualBox.app/Contents/MacOS
- Add this script as
portfw.rbsudo bash # (you'll need to be root to create this script) #!/usr/bin/ruby # if(ARGV.size < 4) print "Ussage: ruby portfw.rb \n" exit() end print "Adding Portforwarding from #{ARGV[2]} to #{ARGV[3]} named (#{ARGV[1]} on VBOX:#{ARGV[0]}\n” print `./VBoxManage setextradata “#{ARGV[0]}” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/HostPort” #{ARGV[2]}` print `./VBoxManage setextradata “#{ARGV[0]}” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/GuestPort” #{ARGV[3]}` print `./VBoxManage setextradata “#{ARGV[0]}” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/Protocol” TCP` - We'll want to forward some of our local ports to VirtualBox for testing
exit # to become non root again -- so you can see your virtualbox # ruby portfw.rb ruby portfw.rb ubuntu ssh 2222 22 # for Rails Testing ruby portfw.rb ubuntu rails 3001 3000 # for HTTP ruby portfw.rb ubuntu http 8080 80
- You can restart you virtual box now if you want.
- Now, let's make it so we can mount our OSX drive from the virtualbox, without doing anything fancy -- yes virtualbox has a virtual-drive, but it is horrible. (or was at the time of this writing). First, let's add a local IP alias, so we can have a constant pointer to our SMB Share.
sudo vim /etc/rc.local /sbin/ifconfig en0 alias 10.1.1.10 netmask 255.255.255.255
- You can run this file by typing:
source /etc/rc.local
- Now you want to make OSX share Samba -- this is somewhat insecure, and you should probably tweak your firewall to prevent non-local connections. [I haven't looked this up yet].
- In OSX, goto the sharing preference pane
- Check the box marked File Sharing
- Add a share (I share my homedirectory /Users/bcx )
- In the left panel make sure your User has Read & Write access to the directory also make sure Everyone has "no Access" and no one else has access besides you
- Under the [Options..] tab, check the box "Share files and folders using SMB" and "On" for next to your username
- Exit out of sharing.
- I ran into a few problems with SAMBA and Subversion. Which were causing some file permissions errors, and completely broke SVN over SAMBA. A combination of adding three configuration options to your
/etc/smb.confon OSX fixed the errors I got. Under globals you will need to add[Globals] force create mode = 0777 force directory mode = 0777 delete readonly = yes # ....Once this is done you need to restart samba:
sudo service smbd stop sudo service nmbd stop sudo service smbd start sudo service nmbd start
- The next step is to make it easy to log into your Ubuntu install. If you don't already have one create a file called .bash_profile and .bashrc.
vim ~/.bash_profile #~/.bash_profile source ~/.bashrc
Create an alias for SSHing locally
vim ~/.bashrc #~/.bashrc alias sshl='ssh -p 2222 localhost'
- If you don't have a public key, or don't know what they are, you'll need to generate one
# type this in the terminal. Leave the pass phrase empty, and use the default values ssh-keygen
- Next copy your SSH key to your local virtual box (this one liner will do it)
cat ~/.ssh/id_rsa.pub | sshl "cat - >> ~/.ssh/authorized_keys"
- Now typing
sshl
on the command line will ssh into your virtual ubuntu instance. We are almost there.
- log into your virtual box. IF for some reason RSA authentication isn't working take a look at /etc/ssh_config and make sure that
RSAAuthentication = yes PubkeyAuthentication = yes
are set
- You are almost there, next step -- setup samba
mkdir /mnt/smb sudo vim /etc/fstab # add the line: //10.1.1.10/[osx_username] /mnt/smb smbfs user=[osx_username],uid=[ubuntu_username],password=[osx_password] 0 0
- Finally mount your OSX home directory inside of ubuntu
sudo mount /mnt/smb
And then make an easy to access symlink to it
ln -s /mnt/smb ~/osx
- That should do it! Now you can do cool things like edit files inside your home directory using textmate, and run them on ubuntu.
[...] The goal is to access a shared folder, what is an easier way than to use sshd or Samba. [...]
If you’ve ever tried to do anything complicated on the shared folders (at least the old versions) you’ll quickly see that they are/were pretty unreliable.