Notes on Working with Ubuntu in VirtualBox

Note: This content may be moving. If you have bookmarked it, please update your record to point to http://vdir.us/go/ubuntu-git-vbox.

I have been working with Ubuntu in VirtualBox for a week or two now. At first it was merely an exercise in learning Java, Eclipse and Git but it turns out that with Mono, Linux gets a lot more attractive. More on this later, though! Here are a few notes that I have compiled that would be helpful to those running Ubuntu inside a VirtualBox virtual machine (primarily on a Windows host).

Networking, SSH

If you plan on using Ubuntu as a server of any kind, I suggest using the Bridged network adapter so that the VM looks like a regular PC on the network. Otherwise you will end up fudging with the port forwarding in VBox and inevitably failing (perhaps that is just me). Here is how I set up my Ubuntu VM to enable SSH.

  1. With the VM off, open the Networking settings in VBox…
  2. Use Bridged Networking, and the AMD PCNet Fast III adapter. See Chapter 06 of the VBox manual for more info.
  3. Boot the VM, log on
  4. Run sudo gedit /etc/network/interfaces. Your file should look like the following. Change your address and gateway IP’s to represent your personal network’s specifics.
    auto lo
    iface lo inet loopback
    address 127.0.0.1
    netmask 255.0.0.0
    
    auto eth0
    iface eth0 inet static
    address 192.168.1.118
    netmask 255.255.255.0
    gateway 192.168.1.1
  5. Run sudo gedit /etc/resolv.conf to edit your nameservers. Mine has a single entry: the router.
  6. Edit your hosts file to add your computer to the IP address. Run sudo nano -w /etc/hosts. I commented out the automatic one and added my own.
    # 10.0.2.15  JSUbuntu-Virtual # Added by Network Manager
    192.168.1.118   JSUbuntu-Virtual
  7. Run sudo /etc/init.d/networking restart to apply your changes.
  8. Run ifconfig to see your changes.
  9. Check that your configuration works by browsing to a site.
  10. Now to install SSH, run sudo apt-get install ssh. Note that you may have to run a sudo apt-get update to update the available packages.
  11. If you have a firewall enabled, configure port 22 to be open. This is the default SSH port.
  12. If you want it to be public, enable port forwarding on your physical/network router for port 22 and your Ubuntu’s IP.
  13. On your host machine, download PuTTY
  14. Run PuTTY, enter IP, smash the enter key.
  15. Enter your credentials!

Next I will show you how to get up and running with git.

Running a Git Server

This portion of this post assumes that you have SSH running, and git installed. It took me a while to find a recent version but eventually found git-core 1.7.2.3 which has been stable. I will update this later with more info (though I will say the git website could do a little better with making the latest release clearly visible for downloading for all systems).

Because git is distributed, it doesn’t have to really rely on some core server software. If you have git installed, you can just create a repository and start committing against it locally or remotely. That is, of course, provided you have access through a protocol such as SSH.

I decided to house my repositories right off the root directory, which is probably stupid but simple to maintain. I did this since Visual SVN server throws its repos into a directory right off of the C drive on Windows. To get a repository, we need to setup a group that will have access to making commits. I chose to create a developers group and added myself to the group.

sudo groupadd developers
sudo usermod -a jsedlak -G developers

Next, I setup a repos directory off the root and give myself and developers read, write and execute access to it. I apologize beforehand if the lack of my command line experience is displayed here.

cd /
sudo mkdir repos
sudo chown jsedlak /repos
sudo chgrp developers repos
sudo chmod 770 repos
cd repos

Once the basic repository bucket is created, we can get started by making a repo to make commits against. First we make the directory, then initialize a git repo inside it and give developers access.

mkdir sample.git
cd sample.git
git init --bare --shared=group
sudo chgrp -R developers .

You should now be able to use this as a repository. But note that we created an empty repo – we should make a commit to get the master branch started. It is a good idea to take this step and use it to test out your new source control server. I hopped on a second machine, made sure I could SSH and then opened a local terminal.

cd ~/Projects
git clone ssh://jsedlak@ubuntuvm.local/repos/sample.git
# Enter password
# Output here...
nano test.txt
git add .
git commit -m Initial
git push origin master

If all went well – you should have a working server! Below is more information including resources I used to create this little post and get my setup running.

References

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

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