Tuesday Oct 28, 2008

Using Virtual Box's shared folders

I have taken advantage of Virtual Box's shared folder feature. I used the GUI to define one of the windows host folders as readable and then issue a mount command

mkdir /public
mount -t vboxsf ${vbox_folder_name} /public

proving this works, I then insert a line into /etc/fstab,

import    /public    vboxsf

issue the mount -a command. There are no errors reported and df shows the file system as mounted. I have rebooted the VM and the filesystem mounts fine.

tags:

Virtual Box 2.0.4

I have taken the opportunity to upgrade to Virtual Box 2.0.4. The upgrade for Ubuntu 8 goes fine, although EZ-Web is barfing on the upgrade; I have forgotten some password I need. (Hmm, I wonder if I should try the command line, or closing the postgres service first.)

I have amended my proxy set up script. I had not read the documentation carefully enough and tried to set up the proxied ports while the VM was running. This is bad. The new script now displays the parameters set,


case $2 in
make)   echo $0 make proxy
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/Protocol" TCP
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/GuestPort" ${port}
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/HostPort" ${port}
         ;;
show|list|display) echo $0 list parameters for $key
        for property in Protocol GuestPort HostPort
        do
           ./VBoxManage.exe getextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/${property}"
        done
        ;;
rm|remove) echo $0 remove proxy
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/Protocol"
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/GuestPort"
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/${key}/HostPort"
        ;;
esac

I set the key variable earlier in the program. As you can see I have used two idioms now, i.e. iteration and sequence and I am sure a horrendous function could make the code much more economic. However it would have a non real name like act or do which is a clue to a design error. I wonder what it would look like in Python. Mind you, another reason this code is so repetitive is that the shell interpreter doesn't do associative arrays. Boo!

The program now takes two arguments one to define the service and one to define the action. This is why the example above uses $2 as the case argument. The previous version of the code was published earlier this month here on this blog.

tags:

Wednesday Oct 15, 2008

Using a Virtual Box service

I want to run a web service inside a Virtual Box container and consume it from initially the host OS, but later from other systems. This article describes how I accessed an apache served page from and Ubuntu 8 VM.

Using Virtual Box 2.0.2, I read the manual version 2.0.2 chapter 6.4 which talks about allowing the host to utilise port services on a guest. I have a windows host, and a Ubuntu Linux guest.

Despite the problems I have with the IT provided build, fortunately I have cygwin on the machine and so have an easy to use scripting language. Most importantly I have a rigourius 'cd' command with directory completion, my tcl and python shells are a lot fussier about the windows xp 16/32 bit name translation. So in the folder containing the program VBoxManage.exe, I create a script containing the following code,

# need to force the shell, wonder how you do that

USAGE="$0 [make | [rm|remove] | help ]"

case $1 in
make)   echo $0 make proxy
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache2/Protocol" TCP
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache2/GuestPort" 80
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache2/HostPort" 80
         ;;
rm|remove) echo $0 remove proxy
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache2/Protocol"
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache2/GuestPort"
        ./VBoxManage.exe setextradata "Ubuntu 8" \\
                "VBoxInternal/Devices/pcnet/0/LUN#0/Config/apache2/HostPort"
        ;;
help)   echo $USAGE ;;
esac

exit

I run the script with the argument 'make'. The token "Ubuntu 8" agrees with the VM name, and the token apache2 is afaik, anything I want so long as it agrees. Having run the script, I can boot Firefox in the host OS instance and see the guests default web page, using the URL http://127.0.0.1. Oddly, http://localhost is resolved as something else, but I expect its the apache configuration file that does this.

What next, snipsnap?

tags:

About

DaveLevy

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today