Virtual Machines: Windows 7 host and Ubuntu 9.10 guest

I am trying out Sun’s Virtual Box this term. I’m going to be doing a fair amount of development in C and C++ which means using gcc on Ubuntu. I’m pretty invested in the software on my Windows 7 laptop and yes, I’ve got Cygwin, but I prefer working with C and C++ on Ubuntu. I tried dual booting Vista and Ubuntu before upgrading from Vista to Windows 7, and I generally didn’t like the whole dual-boot experience.

Enter Sun’s Virtual Box. I worked with virtual servers using VMWare while studying databases at BCIT last year, but I found VMWare was a real memory pig and I wanted to try something that was a) open source, b) free and c) free.

Setting up Ubuntu 9.10 as a guest on my Windows 7 host was almost too easy. The only problem? The Virtual Box User Manual doesn’t include a clear step-by-step recipe for installing Guest Additions, which is the Virtual Box “partner” we have to install on the virtual machine. It integrates the virtual machine with the host machine so you don’t have to do weird screen resize things or mouse captures or anything that offends the intuition. Here’s what I did:

  1. download and install Virtual Box
  2. download the iso for Ubuntu 9.10 and use your favourite iso mounting software to mount it in your host (I used VirtualCloneDrive)
  3. start Virtual Box and create a new Virtual Machine
  4. install Ubuntu in the Virtual Machine (Virtual Box’s wizard asks some set-up questions and you just point it to the iso and wait–go make a sandwich or something)
  5. once Ubuntu’s up and running, choose Devices/Install Guest Additions from the menu bar in the virtual machine’s window
  6. ignore the weird warning message Ubuntu spits out (check the app bar to find it if it’s not maximized)
  7. double-click the GUESTADDITION disc which appears on the Ubuntu desktop
  8. run the autorun.sh script
  9. reboot the Ubuntu machine.  Done.

It’s seriously that simple.  It’s completely moron-proof. I did this without any trouble at all. The Virtual Box wizards take over when you create a new virtual machine, and then when you open it the first time it cues you for the iso of the operating system (in my case Ubuntu 9.10) to install.

I have 2 partitions on my hard drive, a big Windows 7 partition and a smaller 25 GB docs folder which is mounted to my Windows as drive D called shared. I wanted to give the Ubuntu virtual machine read/write access to my D drive, and I did this in two steps:

  1. close the virtual machine and edit its Shared Folders (at the bottom of the virtual machine’s Details tab) to include shared
  2. reboot the virtual machine and use this command in a terminal window:
sudo mount -t vboxsf shared /home/christopher/shared

Again, crazy easy.

Talking about crazy easy, I made us new pajama bottoms during the Christmas break and started planning my next big art project.  I’ll post some pictures about it on orangewool once more work is done.

  • Share/Bookmark

Artifact C-1: Cdump Utility (Command Prompt)

Description

The following description of the cdump program is based on the documentation of the hexdump utility:

NAME
cdump – ascii, hexadecimal, octal dump
SYNOPSIS
cdump [-bcC] [-nlength] [-soffset] [file]
DESCRIPTION
The cdump utility is a filter which displays the specified file, or the standard input, if no file is specified, in a user specified format.The options are as follows:

-b
One-byte octal display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line.
-c
One-byte character display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line.
-C
Canonical hex+ASCII display. Display the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in “character” format enclosed in ‘|’ characters.
-nlength
Interpret only length bytes of input. Note that there is no space between -n and length.
-soffset
Skip offset bytes from the beginning of the input. Note that there is no space between -s and offset.

The default is to interpret length & offset as decimal numbers. If they start with 0x (zero x) or 0X (zero X), they are interpreted as hexadecimal numbers; otherwise, if they start with 0 (zero), they are interpreted as octal numbers.

The default format, when neither -b, -c nor -C is specified, is to use one-byte hexadecimal display — the input offset is displayed in hexadecimal, followed by sixteen space-separated, two column, zero-filled, bytes of input data, in hexadecimal, per line.

Technical Knowledge

I learned and applied my knowledge of:

  • procedural programming in C
  • command line argument validation
  • basic I/O.

Skills Applied

I developed these skills while making this artifact:

  • programming with C
  • working with octal and hexadecimal number systems
  • managing complex user requirements.

Notes

I wrote this for BCIT’s COMP 2510, Procedural Programming in C, in July 2008.

We were required to write logic accommodating complex requirements including special cases like:

  • if the file to dump has size 0, there should be no output
  • if the number of bytes to skip is more than the number of bytes in the file, there should be no output
  • if the number of bytes to dump exceeds the number of bytes available, dumping stops at the end of the file

The following shows the -C option. The output format is somewhat different from the other cases.

$ cdump -C hello.o
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF…………|
00000010 01 00 03 00 01 00 00 00 00 00 00 00 00 00 00 00 |…………….|
00000020 c0 00 00 00 00 00 00 00 34 00 00 00 00 00 28 00 |……..4…..(.|
00000030 0a 00 07 00 55 89 e5 83 ec 08 83 e4 f0 b8 00 00 |….U………..|
00000040 00 00 29 c4 83 ec 0c 68 00 00 00 00 e8 fc ff ff |..)….h……..|
… (40 lines omitted) …
000002d0 0e 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 |…………….|
000002e0 00 68 65 6c 6c 6f 2e 63 00 6d 61 69 6e 00 70 72 |.hello.c.main.pr|
000002f0 69 6e 74 66 00 00 00 00 14 00 00 00 01 05 00 00 |intf…………|
00000300 19 00 00 00 02 08 00 00 |……..|
00000308

Demonstration

Download a ZIP file containing the C source code here [4 KB]
Alternatively, you can download the Win Executable [16 KB] or Linux Executable [12 KB]

  • Share/Bookmark