Ajitabh Pandey's Soul & Syntax

Exploring systems, souls, and stories – one post at a time

Tag: Virtualbox

  • Expanding HardDisk of VirtualBox Guest

    VirtualBox is a beautiful piece of virtualisation software created for users, first acquired by Sun and then by Oracle as a part of Sun acquisition. I have been using VirtualBox for quite a few testing projects, however until today have never needed to expand my hard drive on a guest. I am running a Windows 7 guest for some client side related tests. I started with a 25Gb disk for Windows 7, but after applying all security patches (I like my machines patched and upto-date), I realised that 25GB is all gone.

    This is where I love virtualisation. I do not need to buy a new disk if I need more space on my virtual machine (as far as my physical disk has enough space). I can just expand the existing virtual hard disk and get all the space I need. VirtualBox does not yet have a GUI option to do storage expansion work, but fortunately VirtualBox comes with an excellent command line, so I followed the following steps in order to increase my hard drive space.

    In order to see the virtual hard disk info, following command can be used.

    $ VBoxManage showhdinfo VirtualBox\ VMs/Win764/Win764.vdi
    UUID: e2272600-df31-4dbc-a71d-56af5f5714df
    Parent UUID: base
    State: created
    Type: normal (base)
    Location: /Users/ajitabhp/VirtualBox VMs/Win764/Win764.vdi
    Storage format: VDI
    Format variant: dynamic default
    Capacity: 25600 MBytes
    Size on disk: 25502 MBytes
    In use by VMs: Win764 (UUID: 1beda97f-4222-49ad-993e-342e1d44e288)
    

    To expand this to 50GB and then verify that the operation is done

    $ VBoxManage modifyhd --resize 50000 VirtualBox\ VMs/Win764/Win764.vdi
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    $ VBoxManage showhdinfo VirtualBox\ VMs/Win764/Win764.vdi
    UUID:           e2272600-df31-4dbc-a71d-56af5f5714df
    Parent UUID:    base
    State:          created
    Type:           normal (base)
    Location:       /Users/ajitabhp/VirtualBox VMs/Win764/Win764.vdi
    Storage format: VDI
    Format variant: dynamic default
    Capacity:       50000 MBytes
    Size on disk:   25502 MBytes
    In use by VMs:  Win764 (UUID: 1beda97f-4222-49ad-993e-342e1d44e288)
    

    Now so far we have only been able to expand the Hard disk drive, but the partition table still would say that the NTFS filesystem is still the original size. However, we can not use Windows to expand the partition table of the same partition wherein it is installed. The System Rescue CD came to help here. I attached the System Rescue CD ISO to the windows virtual machine and booted the system.

    In the command prompt, I used the GNU parted to expand the partition table (partition 2 in my case)

    % parted resizepart 2 50GB /dev/sda
    

    In case you want to check which is your NTFS partition, which you want to expand use the following command –

    % parted print /dev/sda
    

    After expanding the partition table, we need to expand the NTFS filesystem on it, which can be done by ntfsresize utility as below. First I ran the utility in info mode to find out the exact size to which to expand to and then in dry run (test) mode and finally actually ran it.

    % ntfsresize --info /dev/sda2
    % ntfsresize -n -s 52294093824 /dev/sda2
    % ntfsresize -s 52294093824 /dev/sda2
    

    Finally remove the the System Rescue CD ISO file and boot the system normally in windows, a check will be force and you are done.

  • Solaris10 on VirtualBox

    I installed Solaris10 11/06 on VirtualBox 1.5.6 OSE. The first problem immediately after installation I faced was that of mouse not being captured by virtual machine. So I open a terminal window and start the vold and then ran the volcheck command.

    /etc/init.d/volmgt start
    volcheck
    

    The mouse started working after this. The reason for this I guess is because I did not had the mouse inside the virtual machine while booting. I need to confirm this.

    Moving the home directory of root from / to /root:

    Changing the home directory of root using “usermod” command does not work as the root user is logged in. So edit the /etc/passwd file and change root’s home directory to /root. Logout and login again. After that remove all the /.* files and /Desktop directory.

    vi /etc/passwd
    rm -rf /.*pwd
    rm -rf /Desktop
    

    Installing third-party tools

    Next I need to install third party tools in the virtual machine. I downloaded the “pkg-get” as:

    pkgadd -d http://www.blastwave.org/pkg_get-3.8.4-SunOS5.8-all-CSW.pkg
    

    Next I downloaded the static version of the wget utility using mozilla from http://www.blastwave.org/wget-i386.bin and renamed it as wget.
    Next I put the directory containing the wget utility and the /opt/csw/bin directory in default PATH. The first thing installed was wget itself, so that I can get rid of the static version.

    pkg-get install wget
    

    Patch check advanced is a utility which I installed next to apply patches to the operating system.

    pkg-get install pca
    

    The gnupg program was needed to verify the signatures on the catalogue files. This can be installed as:

    pkg-get install gnupg
    

    To install the gpg key of the blastwave repository use the following commands:

    wget --output-document=/tmp/gpg.key http://www.blastwave.org/mirrors.php
    gpg --import /tmp/gpg.key
    
  • Interconnecting QEMU and VirtualBox Virtual Machines

    Sometime back I came across VirtualBox, an excellent replacement for commercial Vmware. I installed few OSes in VirtualBox and found the performance pretty good. In my opinion the performance of Windows virtual machines is much better in VirtualBox, perhaps because of the installed guest additions.

    Immediately a thought came into my mind. What if I want to create an internetwork of VirtualBox virtual machines and QEMU virtual machines.

    The default NAT networking in VirtualBox does not solve any purpose. The only useful networking option I found was the “Host Interface”. I went through several documents on VirtualBox website and realise that I needed to use bridging in order to do this. All the documents explained beautifully how to accompalish bridging with the ethernet interface on the host machine, but this is not what I wanted. I wanted the virtual machines to be in an isolated network connected together using VDE Switch as I was doing with QEMU. Searching on google for quite sometime did not help either, so I decided to give it a try.

    Following is what I did to accompalish this. After executing the following –

    1. QEMU virtual machines can talk to VirtualBox virtual machines and vice-versa.
    2. Host can talk to all virtual machines and vice-versa.
    3. All virtual machines can connect to internet via the hostmachine.

    As suggested on the VirtualBox website, in order to use bridging I need the uml-utilities and bridge-utilities packages:

    $ sudo apt-get install uml-utilities bridge-utils
    

    I need to load the tun/tap module and the kqemu module for QEMU

    $ sudo modprobe kqemu
    $ sudo modprobe tun
    

    Next I wanted to make the “tun” device writeable by the users, so I out myself into the “vboxusers” group and gave the group write permission on the device.

    $ sudo chgrp vboxusers /dev/net/tun 
    $ sudo chmod g+rw /dev/net/tun
    

    Then I created couple of persistent tap interfaces owned by an ordinary user:

    $ sudo tunctl -t tap0 -u ajitabhp
    $ sudo tunctl -t tap1 -u ajitabhp
    

    Next I started the VDE Switch connected to the tap0 interface and make the control file world writeable:

    $ vde_switch -tap tap0 -daemon
    $ chmod 666 /tmp/vde.ctl
    

    A bridge then needs to be created:

    $ sudo brctl addbr br0
    

    All interfaces which are connected to network segments to be bridged are to be put into promiscuous mode.

    $ sudo ifconfig tap0 0.0.0.0 promisc
    

    Add the tap0 interface to the bridge and start the DNSMASQ server to listen on br0 interface.

    $ sudo brctl addif br0 tap0
    $ sudo /usr/sbin/dnsmasq --log-queries --user=named --dhcp-leasefile=/var/lib/misc/vbox-dhcpd.leases --dhcp-range=10.111.111.100,10.111.111.199,255.255.255.0,10.255.255.255,8h --interface=br0 --domain=virtual.lan --addn-hosts=/etc/my-host
    

    Next configure the br0 interface with an ip address. This br0 interface will work as the gateway for the virtual machines.

    $ sudo ifconfig br0 10.111.111.254 netmask 255.255.255.0 up
    

    Now add the tap1 interface to the bridge and bring it up.

    $ sudo brctl addif br0 tap1 
    $ sudo ifconfig tap1 up
    

    Enable IP forwarding on the host machine and setup MASQUERADING:

    $ sudo su -
    # echo "1" > /proc/sys/net/ipv4/ip_forward
    $ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    

    Following is how various interfaces look like after finishing this setup.

    $ brctl show br0
    bridge name     bridge id               STP enabled     interfaces
    br0             8000.ae7729b64a80       no              tap0
    							tap1
    $ ifconfig 
    br0       Link encap:Ethernet  HWaddr 6E:EA:39:83:8C:D4  
              inet addr:10.111.111.254  Bcast:10.111.111.255  Mask:255.255.255.0
              inet6 addr: fe80::6cea:39ff:fe83:8cd4/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:106 errors:0 dropped:0 overruns:0 frame:0
              TX packets:82 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:10696 (10.4 KiB)  TX bytes:10165 (9.9 KiB)
    
    eth0      Link encap:Ethernet  HWaddr 00:12:F0:28:6E:C3  
              inet addr:192.168.0.176  Bcast:192.168.0.255  Mask:255.255.255.0
              inet6 addr: fe80::212:f0ff:fe28:6ec3/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:426 errors:32 dropped:32 overruns:0 frame:0
              TX packets:327 errors:0 dropped:0 overruns:0 carrier:1
              collisions:0 txqueuelen:1000 
              RX bytes:356289115 (339.7 MiB)  TX bytes:18085137 (17.2 MiB)
              Interrupt:11 Base address:0xa000 Memory:d0200000-d0200fff 
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:7425 errors:0 dropped:0 overruns:0 frame:0
              TX packets:7425 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:610482 (596.1 KiB)  TX bytes:610482 (596.1 KiB)
    
    tap0      Link encap:Ethernet  HWaddr 6E:EA:39:83:8C:D4  
              inet6 addr: fe80::6cea:39ff:fe83:8cd4/64 Scope:Link
              UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:81 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:500 
              RX bytes:0 (0.0 b)  TX bytes:10808 (10.5 KiB)
    
    tap1      Link encap:Ethernet  HWaddr B2:03:C1:BE:1E:4E  
              inet6 addr: fe80::b003:c1ff:febe:1e4e/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:106 errors:0 dropped:0 overruns:0 frame:0
              TX packets:46 errors:0 dropped:6 overruns:0 carrier:0
              collisions:0 txqueuelen:500 
              RX bytes:12180 (11.8 KiB)  TX bytes:4978 (4.8 KiB)
    $ sudo iptables -t nat -L
    Chain PREROUTING (policy ACCEPT)
    target     prot opt source               destination         
    
    Chain POSTROUTING (policy ACCEPT)
    target     prot opt source               destination         
    MASQUERADE  0    --  anywhere             anywhere            
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    

    Now start the QEMU virtual machines:

    $ vdeqemu -net vde,vlan=0 -net nic,vlan=0,macaddr=52:54:00:00:EE:01 -m 256 -hda ~/qemu/netbsd.img 1>~/logs/qemu-logs/netbsd.log 2>~/logs/qemu-logs/netbsd.error &
    

    In VirtualBox attach the network interface of all virtual machines to “Host Interface” and then select tap1 as the interface name.