Pretty much everyone has a mobile phone. When you are doing ubicomp prototyping it is often difficult to do field tests on large systems because there is normally a shortage of devices you can use in a field trial, and/or it is difficult to get users to carry around and charge a secondary device. Bluetooth is an excellent method of approximating identity and proximity detection for ubicomp systems.

I have developed a really simple, fast, easy to use bluetooth scanning system, that users RSSI (Received Signal Strength Indicators) to determine Nearness/Far-ness, as well as perform Asynchronous name lookups, and find hidden bluetooth devices, for the use in prototyping systems that detect nearby users:

http://code.google.com/p/python-bluetooth-scanner/

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.

  1. First, Download and install VirtualBox from Virtualbox.org
  2. Second, download and a recent 32-bit ubuntu ISO from ubuntu.org
  3. 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
  4. On ubuntu install some key packages:
    apt-get install ssh smbfs
  5. Also create a .ssh directory inside of your home directory (i.e.
    mkdir ~/.ssh

    )

  6. Shut down your Ubuntu VirtualBox
  7. Open up a Terminal (on your OSX box)
    cd /Applications/VirtualBox.app/Contents/MacOS
  8. Add this script as portfw.rb
    sudo 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`
  9. 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
  10. You can restart you virtual box now if you want.
  11. 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
  12. You can run this file by typing:
    source /etc/rc.local
  13. 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].
    1. In OSX, goto the sharing preference pane
    2. Check the box marked File Sharing
    3. Add a share (I share my homedirectory /Users/bcx )
    4. 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
    5. Under the [Options..] tab, check the box "Share files and folders using SMB" and "On" for next to your username
    6. Exit out of sharing.
  14. 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.conf on 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
    
  15. 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'
  16. 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
  17. 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"
  18. Now typing
    sshl

    on the command line will ssh into your virtual ubuntu instance. We are almost there.

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

  20. 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
  21. 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
  22. That should do it!  Now you can do cool things like edit files inside your home directory using textmate, and run them on ubuntu.

On a Mac change directories to:

/Applications/VirtualBox.app/MacOS

vim portfw.rb

#!/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"

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/HostPort" #{ARGV[2]}`

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/GuestPort" #{ARGV[3]}`

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/Protocol" TCP`

This simple script will make it easy to port forward local ports to a NATed virtualbox.

I recommend adding local aliases for ssh and scp

i.e.

# ~/.bashrc
alias sshl='ssh -p 2222'
alias scpl='scp -p 2222'

so you can just type

sshl localhost

So the IT people told me my harddrive on my macbookpro was dead, I assured them, that the hardrive was fine, and the real problem was that the motherboard had died. However, somewhere in the process I of trying to recover osx I managed to corrupt the partition table.

I tried a variety of tricks to recover the machine including: testdisk (do a google search you’ll find it right away), the OSX Installer Disk (both 10.4 and 10.5), and using the block numbers from testdisk to rewrite the partition table (testdisk won’t write HFS+ / MAC partitians for you).

Finally after fooling around with testdisk and fdisk after mounting the drive in my ubuntu box, I fired up gparted. Gparted could see my partitions just fine, but warned me that something weird was going on.

Somewhere in this process I tried to mount my drive using:

mount -t hfsplus /dev/sda1 /mnt/other

I got a bad superblock, which lead me to believe that I either needed to fsck — (a really bad idea if my partition boundaries were wrong) — or my partition boundaries were wrong, and all I had to do was find the right boundaries).

So I launched parted the command line program that gparted wraps. parted could see my partitions, but fdisk couldn’t. After much fooling around I deleted my partition table using parted (hey it wasn’t working anyway), and then used the parted, rescue command with the partition boundaries that were printed in parted when I typed “print”, but not mountable. In my case I typed

rescue 120M [some big block number]

.

Parted ran for a little bit, found my partition, and mounted it — no problem!

Success!

Key things to remember:
1) Don’t Reformat
2) Don’t run repair disk or check disk, or anything that might mess up your data
3) Every time something gives you a partition boundary (OSX / fdisk / pdisk / testdisk / disk utility) –> WRITE IT DOWN
4) I am pretty sure I burned the EFI partition at the beginning of the disk somewhere in this process, so for me it was essential to have an ubuntu computer to put my drive in, with enough disk space to back everything up. [luckily EFI takes up 120M or so at the beginning of the disk, so overwriting bits and pieces of it here and there weren’t a big deal, if all I was looking for was my main osx partition.

KEY = "asdasdjkdfgjk443534kjsdfs"
class Heart < ActiveResource::Base
    self.site = "http://localhost:3000/"
    self.element_name = "heart"
end
Heart.create({:key => KEY})

I just wanted to lay claim to this quote, because right now it’s not coming up in google, and I want credit :-)

I needed to copy a bunch of zone files over to slicehost, and I really hate doing work I can automate. I wrote a quick script that will import a zone file from a BIND definition into slicehost.

You can find it at: http://pastie.org/357680

On another note, ActiveResource is REALLY cool.

It’s been a while since I last posted, but I thought I should update the ‘world’ (i.e. myself) on some of the more recent accomplishments I have made towards the replay and ubicomp testbed systems I am working on.

1) I have successfully created easy methods of getting content from real live data streams and mocked up datastreams using eventheap as my tuplespace of choice.

2) I successfully built a bunch of ‘middle-ware’ so that my python code can talk to jython code and which in turn talks to the EventHeap over it’s native binary protocol. I am confident I could write a Python wrapper, but for the time-being this works fine, and also sufficiently abstracts publishing sensor information from the platform where sensor data is to be published.

3) I have been playing a lot with Pyro (http://pyro.sourceforge.net ) as a really simple replacement for XMLRPC. It solves a few problems I had using XMLRPC for example provides a name-server system so that services can ‘just run’ and you don’t have to worry about matching up ports to service names, and using ‘connections’ with a binary protocol reducing the overhead of parsing XML and using HTTP to manage connections.  It also created new problems, like requiring all exported objects to inherit from a common base-class, and not being as compatible with other RPC mechanisms in other languages, Pyro is still unstable for Jython.

And I think with that I’ll call it a night, there’s a lot of interesting discoveries to share.  I’ve leave you with this.  If your running the latest Jython or even 2.5a3 you better be running the latest java JRE, I had a problem where my jython RPC server took a few minutes to load ate up 100% CPU and timed out responding to connections.  I tried a variety of approaches to solve this problem, and finally just installed the lasted JDK and JRE (I was using the built in Sun distributed ubuntu java packages..)  — Note to others — Just get the JDK off of sun’s website, trying to debug something because the JRE is buggy is not the problem you want to run into.

Follow

Get every new post delivered to your Inbox.