Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, June 2, 2012

Compiling Happycoders libsocket in Ubuntu

 Happycoders libsocket is an object oriented and platform independent socket library for C++. It has a nice structure for both tcp and udp sockets. It runs like a charm if you want to connect a server and get the content as well as listen from a port and accept the connections.

Since package maintainers published a debian package mainly for Debian and Ubuntu distros, it can easly be installed on those systems. If you use another os the solutions is to compile it yourself. However, GCC throws an error message which can be easily solved. In order to compile the package and use it with your C++ applications, first open an console and type


so we have the source package downloaded. Extract the tar archive

gunzip libsocket-1.8.tar.gz
tar -xvf libsocket-1.8.tar 

Now we have a folder with a name of libsocket-1.8. Get in this folder and start the compilation process:


and then type


After getting some output, GCC throws an error:

make  all-recursive
make[1]: Entering directory `/tmp/socket/libsocket-1.8'
Making all in src
make[2]: Entering directory `/tmp/socket/libsocket-1.8/src'
Making all in tests
make[3]: Entering directory `/tmp/socket/libsocket-1.8/src/tests'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory `/tmp/socket/libsocket-1.8/src/tests'
make[3]: Entering directory `/tmp/socket/libsocket-1.8/src'
if /bin/bash ../libtool --mode=compile g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../src    -g -O2 -Wall -ansi -pedantic -MT socket.lo -MD -MP -MF ".deps/socket.Tpo" \
   -c -o socket.lo `test -f '' || echo './'`; \
 then mv -f ".deps/socket.Tpo" ".deps/socket.Plo"; \
 else rm -f ".deps/socket.Tpo"; exit 1; \
 g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../src -g -O2 -Wall -ansi -pedantic -MT socket.lo -MD -MP -MF .deps/socket.Tpo -c  -fPIC -DPIC -o .libs/socket.o In member function 'void Network::Socket::_write_str_bin(int, const string&) const': error: 'memcpy' was not declared in this scope
make[3]: *** [socket.lo] Error 1
make[3]: Leaving directory `/tmp/socket/libsocket-1.8/src'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/tmp/socket/libsocket-1.8/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/socket/libsocket-1.8'
make: *** [all] Error 2

When you look into to error message we can see the key point: In member function 'void Network::Socket::_write_str_bin(int, const string&) const': error: 'memcpy' was not declared in this scope

It is clear that, GCC needs memcpy to be declared before it is used. It is a function defined in the standar C package string.h and it cstring in C++. Simply open the and add the line

#include <string.h>

and compile again. After typing the make command you will get a new error message. A part of this error message is given below: In member function 'virtual std::string Network::UdpSocket::_read_line_bin(int, unsigned int)': error: 'memset' was not declared in this scope

and this is a similar error. memset is an other standard function defined in string.h in C++ and C. Simple edit the file udpsocket and add the same header

#include <string.h>

After compiling many times, GCC will throw similar errors. To cope with this
  • Include string.h in
  • Include string.h in
  • Include string.h in
  • Include string.h and stddef.h in
  • Include string.h in
After all, we you type make again, GCC compiles and produces binary outputs. Then type

sudo make install

if you want to install. Happycoders socket library is a static library by default and your application will not depent it externally. Have fun!

Wednesday, February 1, 2012

Making bootable Slax Usb in Ubuntu

It is a problem to make a bootable USB flash disk in Ubuntu as I see in the Slax Forums. Slax can be installed in a Fat formatted USB disk or a CD-Rom. However, for the need for compactness, people generally chooses the first option in order to use an "install once and use anywhere" operating system.

Unfortunately, if you are using an Ubuntu OS and you want to make a Slax Bootable USB, problem arises. Since the USB must be formatted as FAT, you can not change the owners and permissions of files and directories. So that, we can not set a file executable. And simply writing a

usbdisk/boot> bash

command cannot handle the problem. But the solution is easy.

First, download the Slax tar file for USB disks. Untar it. You have two folders. One of them is 'slax' and the other is 'boot'. Copy the 'boot' folder in your harddisk. Write

harddisk/some folder/boot> chmod -R a+x *

So, the copied boot folder is now fully executable. Suppose that  the 'some folder' is '/usr/local/bin'. Goto usb disk. Change directory to 'boot'. Edit the

usbdisk> vim

And change the content of the file as following:


set -e

# Find out which partition or disk are we using
MYMNT=$(cd -P $(dirname $0) ; pwd)
while [ "$MYMNT" != "" -a "$MYMNT" != "." -a "$MYMNT" != "/" ]; do
   TARGET=$(egrep "[^[:space:]]+[[:space:]]+$MYMNT[[:space:]]+" /proc/mounts | cut -d " " -f 1)
   if [ "$TARGET" != "" ]; then break; fi
   MYMNT=$(dirname "$MYMNT")

if [ "$TARGET" = "" ]; then
   echo "Can't find device to install to."
   echo "Make sure you run this script from a mounted device."
   exit 1

if [ "$(cat /proc/mounts | grep "^$TARGET" | grep noexec)" ]; then
   echo "The disk $TARGET is mounted with noexec parameter, trying to remount..."
   mount -o remount,exec "$TARGET"

MBR=$(echo "$TARGET" | sed -r "s/[0-9]+\$//g")
cd "$MYMNT"

echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "                        Welcome to Slax boot installer                         "
echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
echo "This installer will setup disk $TARGET to boot only Slax."
if [ "$MBR" != "$TARGET" ]; then
   echo "Warning! Master boot record (MBR) of $MBR will be overwritten."
   echo "If you use $MBR to boot any existing operating system, it will not work"
   echo "anymore. Only Slax will boot from this device. Be careful!"
echo "Press any key to continue, or Ctrl+C to abort..."
read junk

echo "Flushing filesystem buffers, this may take a while..."

# setup MBR if the device is not in superfloppy format
if [ "$MBR" != "$TARGET" ]; then
   echo "Setting up MBR on $MBR..."
   /usr/local/bin/syslinux/lilo -S /dev/null -M $MBR ext # this must be here to support -A for extended partitions
   echo "Activating partition $TARGET..."
   /usr/local/bin/syslinux/lilo -S /dev/null -A $MBR $NUM
   echo "Updating MBR on $MBR..." # this must be here because LILO mbr is bad. mbr.bin is from syslinux
   cat /usr/local/bin/syslinux/mbr.bin > $MBR

echo "Setting up boot record for $TARGET..."
  /usr/local/bin/syslinux/syslinux -d boot/syslinux $TARGET

echo "Disk $TARGET should be bootable now. Installation finished."

echo "Read the information above and then press any key to exit..."
read junk 
Save the file. Exit to shell. Type

usbdisk/boot> sudo bash

By now, runs the needed commands from /usr/local/bin not from /usbdisk/boot.

Happy installs...

Tuesday, January 31, 2012

A tiny C library for client sockets

Sockets are everything in programming, especially, after the wide use of internet. Sockets are used for connecting two devices in a network using several low level protocols. At user level, those protocols are not transparent to user, that is, opening a connection and sending some string or binary data along a network is the whole thing for a general programmer.

Socket programming is not a difficult one in much of high level languages. I have used sockets in Java several times and the stuff were running like a charm. Unfortunately, same easiness is not current for C. However, it is the faster way of doing this work.

Last day, I needed to code a client socket for retrieving some data over the network. My Ubuntu was ready for the task with its installed C libraries. Since Linux sockets are a little bit detailed so there were too many terms (htons, inet_ntoa) which requires some low level knowledge of Linux sockets. For example, a C# programmer does not need to know how Windows converts an IP number to binary data and via versa. But Linux sockets are harder. But once you learn it, it is more fun.

Finally, I wrote a small library for a client socket task. The example of this code is shown below:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "ClientSocket.h"
  7. int main(int argc, char** argv) {
  8. /* We will store some text in this buffer */
  9. int bufsize=1024;
  10. char buffer[bufsize];
  11. char *hostname = "";
  12. int port = 80;
  13. /* Getting ip address of into buffer */
  14. getIPAddress("", buffer);
  15. printf("Connecting to (%s) %s\n", hostname, buffer);
  16. /* Creating socket */
  17. struct ClientSocket *socket = socket_create(buffer, port);
  18. /* Connecting */
  19. socket_connect(socket);
  20. /* Sending a http request */
  21. strcpy(buffer,"GET /\n\n");
  22. socket_send(socket, buffer, strlen(buffer));
  23. /* Receiving the first #bufsize elements */
  24. socket_receive(socket, buffer, bufsize);
  25. printf("%s",buffer);
  26. /* Do not read any more. Closing */
  27. socket_close(socket);
  28. return (EXIT_SUCCESS);
  29. }

The header file of out tiny library is here:(ClientSocket.h)
  1. /*
  2. * File: ClientSocket.h
  3. * Author: Practical Code Solutions
  4. *
  5. * Created on January 31, 2012, 9:56 AM
  6. */
  8. #ifndef CLIENTSOCKET_H
  9. #define CLIENTSOCKET_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  15. struct ClientSocket {
  16. int fd;
  17. char *ip;
  18. int port;
  19. int (*getIp)(const char *, char *);
  20. };
  22. int getIPAddress(const char *host, char *ip);
  24. struct ClientSocket *socket_create(char *ip, int port);
  26. int socket_connect(struct ClientSocket *sock);
  28. int socket_send(struct ClientSocket *sock, char *data, int len);
  30. int socket_receive(struct ClientSocket *sock, char *data, int len);
  32. int socket_close(struct ClientSocket *sock);
  36. #ifdef __cplusplus
  37. }
  38. #endif
  40. #endif /* CLIENTSOCKET_H */
The C source file of our tiny library is here: (ClientSocket.c)
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <arpa/inet.h>
  5. #include <sys/socket.h>
  6. #include <netdb.h>
  8. #include "ClientSocket.h"
  10. int getIPAddress(const char *host, char *ip){
  11. struct hostent *hh = gethostbyname(host);
  12. struct in_addr *add = hh->h_addr_list[0];
  13. strcpy(ip, inet_ntoa(add[0]));
  14. }
  16. struct ClientSocket *socket_create(char *ip, int port){
  17. struct ClientSocket *socket = malloc(sizeof(struct ClientSocket));
  18. socket->ip = ip;
  19. socket->port = port;
  20. socket->getIp = getIPAddress;
  21. return(socket);
  22. }
  24. int socket_connect(struct ClientSocket *sock){
  25. struct sockaddr_in addr;
  26. int result;
  27. sock->fd = socket(AF_INET, SOCK_STREAM, 0);
  28. memset((char *)&addr, 0, sizeof(addr));
  29. addr.sin_port = htons(sock->port);
  30. addr.sin_family = AF_INET;
  31. addr.sin_addr.s_addr = inet_addr(sock->ip);
  32. result = connect(sock->fd, (struct sockaddr *)&addr, sizeof(addr));
  33. return(result);
  34. }
  36. int socket_send(struct ClientSocket *sock, char *data, int len){
  37. return send(sock->fd, data, len, 0);
  38. }
  40. int socket_receive(struct ClientSocket *sock, char *data, int len){
  41. data[len-1] = '\0';
  42. return recv(sock->fd, (void *)data, len -1 , 0);
  43. }
  45. int socket_close(struct ClientSocket *sock){
  46. return close (sock->;fd);
  47. }

Friday, January 27, 2012

Creating virtual machines using VBoxManage command

Please visit to read "Installing VBox with extpack on ubuntu server 11.10" article. This article is explain to installation steps of ubuntu server 11.10 and virtualbox 4.1 with screenshots and videos from zero. If you don't know or don't sure "how to" install them, that's will be helpful..

We can use VBoxManage command to create and manage a virtual machine. If we execute the VBoxManage command alone, It will get an output with all parameters and options as below:

support@tester:~$ VBoxManage
Oracle VM VirtualBox Command Line Management Interface Version 4.1.8
(C) 2005-2011 Oracle Corporation
All rights reserved.


VBoxManage [-v|--version] print version number and exit
VBoxManage [-q|--nologo] ... suppress the logo

VBoxManage list [--long|-l] vms|runningvms|ostypes|hostdvds|hostfloppies|

VBoxManage showvminfo <uuid>|<name> [--details]
VBoxManage showvminfo <uuid>|<name> --log <idx>

VBoxManage registervm <filename>

VBoxManage unregistervm <uuid>|<name> [--delete]

VBoxManage createvm --name <name>
[--ostype <ostype>]
[--basefolder <path>]
[--uuid <uuid>]

VBoxManage modifyvm <uuid|name>
[--name <name>]
[--ostype <ostype>]
[--memory <memorysize in MB>]
[--pagefusion on|off]
[--vram <vramsize in MB>]
[--acpi on|off]
[--pciattach 03:04.0]
[--pciattach 03:04.0@02:01.0]
[--pcidetach 03:04.0]
[--ioapic on|off]
[--pae on|off]
[--hpet on|off]
[--hwvirtex on|off]
[--hwvirtexexcl on|off]
[--nestedpaging on|off]
[--largepages on|off]
[--vtxvpid on|off]
[--synthcpu on|off]
[--cpuidset <leaf> <eax> <ebx> <ecx> <edx>]
[--cpuidremove <leaf>]
[--hardwareuuid <uuid>]
[--cpus <number>]
[--cpuhotplug on|off]
[--plugcpu <id>]
[--unplugcpu <id>]
[--cpuexecutioncap <1-100>]
[--rtcuseutc on|off]
[--monitorcount <number>]
[--accelerate3d on|off]
[--accelerate2dvideo on|off]
[--firmware bios|efi|efi32|efi64]
[--chipset ich9|piix3]
[--bioslogofadein on|off]
[--bioslogofadeout on|off]
[--bioslogodisplaytime <msec>]
[--bioslogoimagepath <imagepath>]
[--biosbootmenu disabled|menuonly|messageandmenu]
[--biossystemtimeoffset <msec>]
[--biospxedebug on|off]
[--boot<1-4> none|floppy|dvd|disk|net>]
[--nic<1-N> none|null|nat|bridged|intnet|hostonly|
[--nictype<1-N> Am79C970A|Am79C973|
[--cableconnected<1-N> on|off]
[--nictrace<1-N> on|off]
[--nictracefile<1-N> <filename>]
[--nicproperty<1-N> name=[value]]
[--nicspeed<1-N> <kbps>]
[--nicbootprio<1-N> <priority>]
[--nicpromisc<1-N> deny|allow-vms|allow-all]
[--nicbandwidthgroup<1-N> none|<name>]
[--bridgeadapter<1-N> none|<devicename>]
[--hostonlyadapter<1-N> none|<devicename>]
[--intnet<1-N> <network name>]
[--natnet<1-N> <network>|default]
[--nicgenericdrv<1-N> <driver>
[--natsettings<1-N> [<mtu>],[<socksnd>],
[--natpf<1-N> [<rulename>],tcp|udp,[<hostip>],
[--natpf<1-N> delete <rulename>]
[--nattftpprefix<1-N> <prefix>]
[--nattftpfile<1-N> <file>]
[--nattftpserver<1-N> <ip>]
[--natbindip<1-N> <ip>
[--natdnspassdomain<1-N> on|off]
[--natdnsproxy<1-N> on|off]
[--natdnshostresolver<1-N> on|off]
[--nataliasmode<1-N> default|[log],[proxyonly],
[--macaddress<1-N> auto|<mac>]
[--mouse ps2|usb|usbtablet
[--keyboard ps2|usb
[--uart<1-N> off|<I/O base> <IRQ>]
[--uartmode<1-N> disconnected|
server <pipe>|
client <pipe>|
file <file>|
[--guestmemoryballoon <balloonsize in MB>]
[--gueststatisticsinterval <seconds>]
[--audio none|null|oss|alsa|pulse]
[--audiocontroller ac97|hda|sb16]
[--clipboard disabled|hosttoguest|guesttohost|
[--vrde on|off]
[--vrdeextpack default|<name>
[--vrdeproperty <name=[value]>]
[--vrdeport <hostport>]
[--vrdeaddress <hostip>]
[--vrdeauthtype null|external|guest]
[--vrdeauthlibrary default|<name>
[--vrdemulticon on|off]
[--vrdereusecon on|off]
[--vrdevideochannel on|off]
[--vrdevideochannelquality <percent>]
[--usb on|off]
[--usbehci on|off]
[--snapshotfolder default|<path>]
[--teleporter on|off]
[--teleporterport <port>]
[--teleporteraddress <address|empty>
[--teleporterpassword <password>]

VBoxManage clonevm <uuid>|<name>
[--snapshot <uuid>|<name>]
[--mode machine|machineandchildren|all]
[--options link|keepallmacs|keepnatmacs|
[--name <name>]
[--basefolder <basefolder>]
[--uuid <uuid>]

VBoxManage import <ovf/ova>
[--options keepallmacs|keepnatmacs]
[more options]
(run with -n to have options displayed
for a particular OVF)

VBoxManage export <machines> --output|-o <ovf/ova>
[--vsys <number of virtual system>]
[--product <product name>]
[--producturl <product url>]
[--vendor <vendor name>]
[--vendorurl <vendor url>]
[--version <version info>]
[--eula <license text>]
[--eulafile <filename>]

VBoxManage startvm <uuid>|<name>...
[--type gui|sdl|headless]

VBoxManage controlvm <uuid>|<name>
keyboardputscancode <hex> [<hex> ...]|
setlinkstate<1-N> on|off |
nic<1-N> null|nat|bridged|intnet|hostonly|generic
[<devicename>] |
nictrace<1-N> on|off
nictracefile<1-N> <filename>
nicproperty<1-N> name=[value]
natpf<1-N> [<rulename>],tcp|udp,[<hostip>],
natpf<1-N> delete <rulename>
guestmemoryballoon <balloonsize in MB>]
gueststatisticsinterval <seconds>]
usbattach <uuid>|<address> |
usbdetach <uuid>|<address> |
vrde on|off |
vrdeport <port> |
vrdeproperty <name=[value]> |
vrdevideochannelquality <percent>
setvideomodehint <xres> <yres> <bpp> [display] |
screenshotpng <file> [display] |
setcredentials <username> <password> <domain>
[--allowlocallogon <yes|no>] |
teleport --host <name> --port <port>
[--maxdowntime <msec>] [--password password]
plugcpu <id>
unplugcpu <id>
cpuexecutioncap <1-100>

VBoxManage discardstate <uuid>|<name>

VBoxManage adoptstate <uuid>|<name> <state_file>

VBoxManage snapshot <uuid>|<name>
take <name> [--description <desc>] [--pause] |
delete <uuid>|<name> |
restore <uuid>|<name> |
restorecurrent |
edit <uuid>|<name>|--current
[--name <name>]
[--description <desc>] |
list [--details|--machinereadable]
showvminfo <uuid>|<name>

VBoxManage closemedium disk|dvd|floppy <uuid>|<filename>

VBoxManage storageattach <uuid|vmname>
--storagectl <name>
[--port <number>]
[--device <number>]
[--type dvddrive|hdd|fdd]
[--medium none|emptydrive|
[--mtype normal|writethrough|immutable|shareable|
[--comment <text>]
[--setuuid <uuid>]
[--setparentuuid <uuid>]
[--passthrough on|off]
[--tempeject on|off]
[--nonrotational on|off]
[--bandwidthgroup <name>]
[--server <name>|<ip>]
[--target <target>]
[--tport <port>]
[--lun <lun>]
[--encodedlun <lun>]
[--username <username>]
[--password <password>]

VBoxManage storagectl <uuid|vmname>
--name <name>
[--add ide|sata|scsi|floppy|sas]
[--controller LSILogic|LSILogicSAS|BusLogic|
[--sataideemulation<1-4> <1-30>]
[--sataportcount <1-30>]
[--hostiocache on|off]
[--bootable on|off]

VBoxManage bandwidthctl <uuid|vmname>
--name <name>
[--add disk|network]
[--limit <megabytes per second>

VBoxManage showhdinfo <uuid>|<filename>

VBoxManage createhd --filename <filename>
--size <megabytes>|--sizebyte <bytes>
[--format VDI|VMDK|VHD] (default: VDI)
[--variant Standard,Fixed,Split2G,Stream,ESX]

VBoxManage modifyhd <uuid>|<filename>
[--type normal|writethrough|immutable|shareable|
[--autoreset on|off]
[--resize <megabytes>|--resizebyte <bytes>]

VBoxManage clonehd <uuid>|<filename> <uuid>|<outputfile>
[--format VDI|VMDK|VHD|RAW|<other>]
[--variant Standard,Fixed,Split2G,Stream,ESX]

VBoxManage convertfromraw <filename> <outputfile>
[--format VDI|VMDK|VHD]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--uuid <uuid>
VBoxManage convertfromraw stdin <outputfile> <bytes>
[--format VDI|VMDK|VHD]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--uuid <uuid>

VBoxManage getextradata global|<uuid>|<name>

VBoxManage setextradata global|<uuid>|<name>
[<value>] (no value deletes key)

VBoxManage setproperty machinefolder default|<folder> |
vrdeauthlibrary default|<library> |
websrvauthlibrary default|null|<library> |
vrdeextpack null|<library> |
loghistorycount <value>

VBoxManage usbfilter add <index,0-N>
--target <uuid>|<name>|global
--name <string>
--action ignore|hold (global filters only)
[--active yes|no] (yes)
[--vendorid <XXXX>] (null)
[--productid <XXXX>] (null)
[--revision <IIFF>] (null)
[--manufacturer <string>] (null)
[--product <string>] (null)
[--remote yes|no] (null, VM filters only)
[--serialnumber <string>] (null)
[--maskedinterfaces <XXXXXXXX>]

VBoxManage usbfilter modify <index,0-N>
--target <uuid>|<name>|global
[--name <string>]
[--action ignore|hold] (global filters only)
[--active yes|no]
[--vendorid <XXXX>|""]
[--productid <XXXX>|""]
[--revision <IIFF>|""]
[--manufacturer <string>|""]
[--product <string>|""]
[--remote yes|no] (null, VM filters only)
[--serialnumber <string>|""]
[--maskedinterfaces <XXXXXXXX>]

VBoxManage usbfilter remove <index,0-N>
--target <uuid>|<name>|global

VBoxManage sharedfolder add <vmname>|<uuid>
--name <name> --hostpath <hostpath>
[--transient] [--readonly] [--automount]

VBoxManage sharedfolder remove <vmname>|<uuid>
--name <name> [--transient]

VBoxManage guestproperty get <vmname>|<uuid>
<property> [--verbose]

VBoxManage guestproperty set <vmname>|<uuid>
<property> [<value> [--flags <flags>]]

VBoxManage guestproperty enumerate <vmname>|<uuid>
[--patterns <patterns>]

VBoxManage guestproperty wait <vmname>|<uuid> <patterns>
[--timeout <msec>] [--fail-on-timeout]

VBoxManage guestcontrol <vmname>|<uuid>
--image <path to program>
--username <name> --password <password>
[--environment "<NAME>=<VALUE> [<NAME>=<VALUE>]"]
[--timeout <msec>] [--unix2dos] [--verbose]
[--wait-exit] [--wait-stdout] [--wait-stderr]
[-- [<argument1>] ... [<argumentN>]]

<source on guest> <destination on host>
--username <name> --password <password>
[--dryrun] [--follow] [--recursive] [--verbose]

<source on host> <destination on guest>
--username <name> --password <password>
[--dryrun] [--follow] [--recursive] [--verbose]

<director[y|ies] to create on guest>
--username <name> --password <password>
[--parents] [--mode <mode>] [--verbose]

<file element(s) to check on guest>
--username <name> --password <password>

[--source <guest additions .ISO>] [--verbose]

VBoxManage debugvm <uuid>|<name>
dumpguestcore --filename <name> |
info <item> [args] |
injectnmi |
log [--release|--debug] <settings> ...|
logdest [--release|--debug] <settings> ...|
logflags [--release|--debug] <settings> ...|
osdetect |
osinfo |
getregisters [--cpu <id>] <reg>|all ... |
setregisters [--cpu <id>] <reg>=<value> ... |
statistics [--reset] [--pattern <pattern>]

VBoxManage metrics list [*|host|<vmname> [<metric_list>]]

VBoxManage metrics setup
[--period <seconds>] (default: 1)
[--samples <count>] (default: 1)
[*|host|<vmname> [<metric_list>]]

VBoxManage metrics query [*|host|<vmname> [<metric_list>]]

VBoxManage metrics enable
[*|host|<vmname> [<metric_list>]]

VBoxManage metrics disable
[*|host|<vmname> [<metric_list>]]

VBoxManage metrics collect
[--period <seconds>] (default: 1)
[--samples <count>] (default: 1)
[*|host|<vmname> [<metric_list>]]

VBoxManage hostonlyif ipconfig <name>
[--dhcp |
--ip<ipv4> [--netmask<ipv4> (def:] |
--ipv6<ipv6> [--netmasklengthv6<length> (def: 64)]]
create |
remove <name>

VBoxManage dhcpserver add|modify --netname <network_name> |
--ifname <hostonly_if_name>
[--ip <ip_address>
--netmask <network_mask>
--lowerip <lower_ip>
--upperip <upper_ip>]
[--enable | --disable]

VBoxManage dhcpserver remove --netname <network_name> |
--ifname <hostonly_if_name>

VBoxManage extpack install [--replace] <tarball> |
uninstall [--force] <name> |

Let's create a sample virtual machine:

1-) The first step is the VM creation, (We are using a "Ubuntu OS + VBox" system that is installed in "" article. It is recommanded to read that article first.)

support@tester:~$ VBoxManage createvm --name testMachine --ostype Debian --register
Virtual machine 'testMachine' is created and registered.UUID: e2bfd530-14fb-4b8e-8dc2-8523c9bd045e
Settings file: '/home/support/VirtualBox VMs/testMachine/testMachine.vbox'

2-) At this point, we can start with checking existing Virtual machine with following command:

support@tester:~$ VBoxManage showvminfo testMachine

Actually, our virtual machine has just been created but It hasn't got any hard drives and some of those settings may not required. For example, the existing virtual machine memory size is 128 megabytes. Probably you want to increase it. You may not want to use NAT mode ethernet device. Right now, let's change some options on our virtual sample.

3-) Change memory and then check it:

support@tester:~$ VBoxManage modifyvm testMachine --memory 256
support@tester:~$ VBoxManage showvminfo testMachine | grep "Memory size"
Memory size: 256MB

4-) Change nic (ethernet interface) bridge mode. We need a bridge adapter for this and the bridge adapter needs a physical interface on base OS. I am checking the pysical interface on base OS:

support@tester:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:1a:64:5b:60:2c
inet addr: Bcast: Mask:
inet6 addr: fe80::21a:64ff:fe5b:602c/64 Scope:Link
RX packets:2932762 errors:0 dropped:0 overruns:0 frame:0
TX packets:1149518 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:936032419 (936.0 MB) TX bytes:89178513 (89.1 MB)
Interrupt:17 Memory:da000000-da012800

And I learned that my physical interface's name is "eth0". Right now, I can create a bridge adapter and check with these commands:

support@tester:~$ VBoxManage modifyvm testMachine --bridgeadapter1 eth0
support@tester:~$ VBoxManage modifyvm testMachine --nic1 bridged
support@tester:~$ VBoxManage showvminfo testMachine | grep "NIC 1"
NIC 1: MAC: 080027E31FFE, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny

5-) Create an HDD and attach to virtual machine using following commands:

support@tester:~$ VBoxManage createhd --filename testMachine.vdi --size 18000 --format
Disk image created. UUID: 970c500d-2476-44ef-b11b-5938b5150c91
support@tester:~$ VBoxManage storagectl testMachine --name "SATA Controller" --add sata --controller IntelAhci
support@tester:~$ VBoxManage storageattach "testMachine" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium testMachine.vdi

and you can find the related information in "VBoxManage showvminfo testMachine" command output:

VBoxManage showvminfo testMachine
Storage Controller Name (0): SATA Controller
Storage Controller Type (0): IntelAhci
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0): 30
Storage Controller Port Count (0): 30
Storage Controller Bootable (0): on
SATA Controller (0, 0): /home/support/testMachine.vdi (UUID: 970c500d-2476-44ef-b11b-5938b5150c91)

Also you can change some of those options on HDD specifications and controller type and all of them. For example, you can select IDE for SATA in my sample. Or size of disk or disk format (VDI, VMDK, VHD) etc.

If you need, you can use "VBoxManage createhd", "VBoxManage modifyhd" or "VBoxManage clonehd" to create a new one, modify the existing one or create a copy of existing one...

6-) We need to mount a cdrom or dvd to our virtual machine to start operation system installation. The following command will download a dvd image from the debian site and do that mounting progress:

support@tester:~$ wget
support@tester:~$ VBoxManage storagectl testMachine --name "IDE Controller" --add ide --controller PIIX4
support@tester:~$ VBoxManage storageattach testMachine --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium debian-6.0.3-amd64-i386-netinst.iso
When we execute 'VBoxManage showvminfo testMachine | grep "IDE Controller" ' command to check the last step, we should see following output:

support@tester:~$ VBoxManage showvminfo testMachine | grep "IDE Controller"
Storage Controller Name (1): IDE Controller
IDE Controller (1, 0): /home/support/debian-6.0.3-amd64-i386-netinst.iso (UUID: cbc77834-7434-4a3c-af96-858ae1af1731)

7-) Almost all mandatory steps are completed, except "remote display" one. We haven't got any GUI and we need a monitor to watch virtual machine output! We can use following first command to enable remote display feature and the second command to check the vrde option on our virtual machine.

support@tester:~$ VBoxManage modifyvm testMachine --vrde on
support@tester:~$ VBoxManage showvminfo testMachine | grep VRDE
VRDE: enabled (Address, Ports 3389, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE property: TCP/Ports = "3389"
VRDE property: TCP/Address = <not set>
VRDE property: VideoChannel/Enabled = <not set>
VRDE property: VideoChannel/Quality = <not set>
VRDE property: VideoChannel/Downscale Protection = <not set>
VRDE property: Client/DisableDisplay = <not set>
VRDE property: Client/DisableInput = <not set>
VRDE property: Client/DisableAudio = <not set>
VRDE property: Client/DisableUSB = <not set>
VRDE property: Client/DisableClipboard = <not set>
VRDE property: Client/DisableUpstreamAudio = <not set>
VRDE property: H3DRedirect/Enabled = <not set>
VRDE property: Security/Method = <not set>
VRDE property: Security/ServerCertificate = <not set>
VRDE property: Security/ServerPrivateKey = <not set>
VRDE property: Security/CACertificate = <not set>
VRDE Connection: not activesupport@tester:~$

We can boot testMachine but we have only one session right on VRDE. If we connect to virtual machine remote display from more than one clients, we have to change MultiConn option to "on". Also, if the port 3389 is used by another process we have to change it. Let's change the port and the multiConn option and then check it again,

support@tester:~$ VBoxManage modifyvm testMachine --vrdemulticon on --vrdeport 3390
support@tester:~$ VBoxManage showvminfo testMachine | grep VRDE
VRDE: enabled (Address, Ports 3390, MultiConn: on, ReuseSingleConn: off, Authentication type: null)
VRDE property: TCP/Ports = "3390"
VRDE property: TCP/Address = <not set>
VRDE property: VideoChannel/Enabled = <not set>
VRDE property: VideoChannel/Quality = <not set>
VRDE property: VideoChannel/DownscaleProtection = <not set>
VRDE property: Client/DisableDisplay = <not set>
VRDE property: Client/DisableInput = <not set>
VRDE property: Client/DisableAudio = <not set>
VRDE property: Client/DisableUSB = <not set>
VRDE property: Client/DisableClipboard = <not set>
VRDE property: Client/DisableUpstreamAudio = <not set>
VRDE property: H3DRedirect/Enabled = <not set>
VRDE property: Security/Method = <not set>
VRDE property: Security/ServerCertificate = <not set>
VRDE property: Security/ServerPrivateKey = <not set>
VRDE property: Security/CACertificate = <not set>
VRDE Connection: not activesupport@tester:~$

8-) Well. Our Virtual Machine is really ready to boot right now. Let's boot it.

support@tester:~$ VBoxHeadless --startvm testMachine
Oracle VM VirtualBox Headless Interface 4.1.8(C) 2008-2011 Oracle Corporation
All rights reserved.

VRDE server is listening on port 3390.

This command does not release the treminal and if we close terminal window or press "ctrl+c", the virtual machine will be aborted. We will come back to this boot issue again.

9-) Connect to virtual machine via RDP client:

ismail@ismail-ThinkPad-T410:~$ rdesktop
Autoselected keyboard map en-usWARNING: Remote desktop changed from 800x600 to 640x480.

and you can see something like this :

Ok. Everything is well. But we want to auto start this virtual machine when booting the base operating system that is an Ubuntu server 11.10. In this case we have to write a start-up shell script and apply with updare-rc.d to inittab.

10-) The most important step of writing the start-up shell script is to set the right ownership. Because, we did everything as support user. But root user will execute it, when the base operation system is booting.


u=`/usr/bin/id -u`

case "$1" in
if [ $u -eq 0 ]; then
/bin/su support -c '/usr/bin/VBoxHeadless --startvm prxySMS &'
/usr/bin/VBoxHeadless -startvm testMachine &
# something for shutdown virtual machine via vm OS, somehow ..
# commands for restarting will come here then...hah?
# May be shown running process with ps command with "| grep VBoxHeadless"
echo "Usage: /etc/init.d/prxySMS_starter :) [start|stop|restart|status]"
exit 1
exit 0

This file is recorded with the filename "testMachine_starter" in folder /etc/init.d. We give the execution permission using "chmod +x /etc/init.d/testMachine_starter". Now, we have to add it to startup with update-rc.d command like this,

ismail@ismail-ThinkPad-T410:~$  update-rc.d testMachine_starter defaults 95

I put a "95" option in command shown below because I want to start the virtual machine after others. This number part is not necessary.