Showing posts with label virtualbox. Show all posts
Showing posts with label virtualbox. Show all posts

Wednesday, October 18, 2017

Creating a Network Topology using VMs in VirtualBox


In my earlier posts, I covered How to - Create a Ubuntu VM in Virtualboxtopics related that and Networking for VirtualBox VMs.

In this post, I will provide steps to create the following simple network topology using VirtualBox VMs:

                     H1  <----->  R1  <----->  R2  <----->  H2

As we need only interconnectivity among the VMs, we can use "Internal Networking" mode as detailed in Networking for VirtualBox VMs. Also, I am going to leave the default NAT mode enabled VM adapters as-is. Instead, I will use the remaining VM adapters to create the above topology.
  • Right click VM H1, select "Settings", select "Network" tab, select "Adapter2", check "Enable Network Adapter", choose "Internal Network" in "Attached to". Then provide a name in "Name" field. This name & the name we provide in VM R1's Adapter should match. The VM adapters with matching names will be connected.

             

  • Right click VM R1, select "Settings", select "Network" tab, select "Adapter2", check "Enable Network Adapter", choose "Internal Network" in "Attached to". Then provide a name in "Name" field. This name & the name we provide in VM H1's Adapter should match. The VM adapters with matching names will be connected.

             

  • Now the link "H1  <----->  R1" is established.
  • Similarly, I established the other two links: "R1  <----->  R2" & "R2  <----->  H2"


Now, I booted my VMs, configured IP addresses & ran ping tests to check whether work fine. Here, I am providing screenshots of H1 & R1 VM bash terminals:
              
             


References:



Networking for VirtualBox VMs


In my earlier posts, I covered How to - Create a Ubuntu VM in Virtualbox and topics related that. In this post, I will cover basics of networking techniques for VirtualBox VMs.

Networking is necessary to connect the VM to/from internet or establish connectivity among the VMs. The following are different ways of networking (copy-pasted from https://www.virtualbox.org/manual/ch06.html#networkingmodes):

"
VirtualBox provides up to eight virtual PCI Ethernet cards for each virtual machine. We can configure only four of these form GUI. CLI allows to configure all the eight interfaces.

Each of the eight networking adapters can be separately configured to operate in one of the following modes:
Not attached
In this mode, VirtualBox reports to the guest that a network card is present, but that there is no connection -- as if no Ethernet cable was plugged into the card. This way it is possible to "pull" the virtual Ethernet cable and disrupt the connection, which can be useful to inform a guest operating system that no network connection is available and enforce a reconfiguration.
Network Address Translation (NAT)
If all you want is to browse the Web, download files and view e-mail inside the guest, then this default mode should be sufficient for you, and you can safely skip the rest of this section. Please note that there are certain limitations when using Windows file sharing (see Section 6.3.3, “NAT limitations” for details).
NAT Network
The NAT network is a new NAT flavour introduced in VirtualBox 4.3. See 6.4 for details.
Bridged networking
This is for more advanced networking needs such as network simulations and running servers in a guest. When enabled, VirtualBox connects to one of your installed network cards and exchanges network packets directly, circumventing your host operating system's network stack.
Internal networking
This can be used to create a different kind of software-based network which is visible to selected virtual machines, but not to applications running on the host or to the outside world.
Host-only networking
This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface (similar to a loopback interface) is created on the host, providing connectivity among virtual machines and the host.
Generic networking
Rarely used modes share the same generic network interface, by allowing the user to select a driver which can be included with VirtualBox or be distributed in an extension pack.
At the moment there are potentially two available sub-modes:
UDP Tunnel
This can be used to interconnect virtual machines running on different hosts directly, easily and transparently, over existing network infrastructure.
VDE (Virtual Distributed Ethernet) networking
This option can be used to connect to a Virtual Distributed Ethernet switch on a Linux or a FreeBSD host. At the moment this needs compiling VirtualBox from sources, as the Oracle packages do not include it.
The following table provides a quick overview of the most important networking modes:

Table 6.1. Overview
VM ↔ HostVM1 ↔ VM2VM → InternetVM ← Internet
Host-only++
Internal+
Bridged++++
NAT+Port forwarding
NAT Network++Port forwarding

"

After creating the VM, the default mode is NAT. So, I was able to connect to internet without any additional configuration. Select a VM & Right click, select "Settings", "Network" tab to see the VM's default networking config:
             



References:

Tuesday, October 17, 2017

How to manage VM groups in VirtualBox - Create/Rename/Delete Groups, Add/Delete VMs


In this post, I will provide steps to create and manage VM groups in VirtualBox. If I call for a VM creation in this post, please refer to my earlier blog: How to - Create a Ubuntu VM in Virtualbox

Why do we need a VM group?
I recently started creating a few network topologies & so grouping VMS belonging to one topology into one group made it easy for me to manage my topologies and VMs. Simply, grouping helps you organize your VMs better.

How to create a VM group?
  • Select the VMs to be grouped, right click & select "Group":
             

  • The above steps names the group as "New Group":
             

How to add a new VM to an existing VM group?
  • Drag and drop the VM into the new group.

How to delete a VM from an existing VM group?
  • Drag and drop the VM from the group to an empty place in the VM list menu

How to rename a VM group?
  • Right click on the group name & select "Rename Group":
             

How to ungroup a VM group?
  • Right click on the group name & select "Ungroup":
             


References:



"VirtualBox Guest Additions" Installation error - Unable to insert the virtual optical disk


To copy paste from Virtualbox guest to host & vice versa, I typically follow the steps listed in my earlier blog post - How to - copy/paste from VirtualBox guest to host & viceversa. Though it worked for me many times, I got the following error pop up recently when I clicked on the "Devices" in top bar menu and clicked on "Insert Guest Additions CD image...":
             

In this post, I will provide steps to install the "VirtualBox Guest Additions" in an alternate way.
  • Shut down the VM
  • I right clicked on my VM in Virtualbox Manager, clicked on the "Settings" displayed menu, selected "Storage" tab, right clicked on "VBoxGuestAdditions" & clicked on "Remove attachment":
             
  • Clicked the "+" icon next to "Controller: IDE" to add a new optical drive. Choose "Leave Empty --> Okay":
             
             



References:


Tuesday, September 9, 2014

VirtualBox Error - Kernel driver not installed


I have been VirtualBox in my macbook pro. But, I stopped using it in last 3-4 months. And when I tried to use it today again, it threw up the following errors:


Error in Virtual Box window:
Failed to open a session for the virtual machine MyUbuntu.
Virtual machine 'MyUbuntu' has terminated unexpectedly during startup. 

NS_ERROR_FAILURE (0x80004005)
Machine
IMachine {<<<some big number here>>>}

Error in an additional popup window:
Kernel driver not installed (rc=-1908)
Make sure the kernel module has been loaded successfully.


Instead of debugging how to fix this issue, I just updated the virtualbox with an available newer version (Virtual Box on top left --> Check for updates). 

After update the error went away. None of my existing VMs or config was impacted due to the upgrade.


Hope this helps.

Wednesday, April 16, 2014

kdb: Debugging Virtualbox VM's linux kernel with built-in debugger interface


In my earlier post - Linux kernel debuggers: Overview - I covered the basic features of kdb. In this post, I will provide steps to use kdb. 


kdb usage - HowTo


Here are the steps that worked for me to debug a VirtualBox Ubuntu VM.



  • Recompile the kernel in the VM with kgdb & kdb options enabled. We can find out whether they are already compiled in by grep-ing for KDB & KGDB compile macros: 

root@babu-VirtualBox:~# egrep "(KDB|KGDB)" /boot/config-3.13.5
CONFIG_SERIAL_KGDB_NMI=y
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
# CONFIG_KGDB_TESTS is not set
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_KDB=y
CONFIG_KDB_KEYBOARD=y
CONFIG_KDB_CONTINUE_CATASTROPHIC=0
root@babu-VirtualBox:~# 


  • Boot the VM with keyboard based kdb front end enabled in boot parameters. To do so, add "kgdboc=kbd" to the boot options.

                     
    • kdb front end can also be used over a serial port. To do so, add "kgdboc=ttyS0,115200" to the boot options.
    • kdb frontend can be enabled on keyboard as well as serial port. To do so, add "kgdboc=kbd,ttyS0,115200" to the boot options.
  • Then, allow the booting process to continue & let the VM completely boot.
  • Get into text mode from GUI mode: Ctrl+Alt+F1 (fn+Ctrl+Option+F1 in Mac)
  • Even if kdb is not enabled in boot parameters, kdb can be enabled at run time in sysfs interface.

  • To enable kdb at run-time:
    root@babu-VirtualBox:~# cat /sys/module/kgdboc/parameters/kgdboc
    ttyS0,115200
    root@babu-VirtualBox:~# 

    To disable kdb at run-time:
    root@babu-VirtualBox:~# echo "" > /sys/module/kgdboc/parameters/kgdboc
    root@babu-VirtualBox:~# 

    To check whether kdb is enabled/disabled:
    root@babu-VirtualBox:~# cat /sys/module/kgdboc/parameters/kgdboc
    ttyS0,115200
    root@babu-VirtualBox:~# 

  • Now, to bring the control to kdb, type "echo g > /proc/sysrq-trigger" 


                     
  • You can now place breakpoints, single stepping, read/write memory, print backtrace, etc.
  • For testing purposes, I then crash the system. In case of crash, the debugger automatically gets the control for further inspection.

                                    


Hope this helps.

Monday, April 14, 2014

kgdb: Debugging Virtualbox VM's linux kernel at source code level


In my earlier post - Linux kernel debuggers: Overview - I covered the basic features of kgdb. In this post, I will provide steps to use kgdb. 


kgdb usage - HowTo

Here are the steps that worked for me to debug a VitualBox Ubuntu VM. I used two VMs: VMDebugged - the VM that is being debugged & VMDebugger - The VM that helps debug VMDebugged.


  • Recompile the kernel in VMDebugged with kgdb options enabled. We can find out whether its already compiled in by grep-ing for KGDB compile macros: 



                           VMDebugged

root@babu-VirtualBox:~# grep KGDB /boot/config-3.13.5
CONFIG_SERIAL_KGDB_NMI=y
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
# CONFIG_KGDB_TESTS is not set
CONFIG_KGDB_LOW_LEVEL_TRAP=y
CONFIG_KGDB_KDB=y
root@babu-VirtualBox:~# 


  • Copy the vmlinux file from VMDebugged to VMDebugger.
  • To establish debugging using kgdb, we need to configure console redirection from VMDebugged to VMDebugger - create host pipe based serial ports as described in my other blog post - http://techvolve.blogspot.com/2013/11/how-to-redirect-console-output-of-one.html.
  • Boot VMDebugger. VMDebugger should be started before VMDebugged so that pipe is created by VMDebugger & it is attached to by VMDebugged.
  • gdb the vmlinux file & start debugging over serial port. Here, the debugger just waits as the VMDebugged is still not up.

                           VMDebugger

root@babu-VirtualBox:/media/sf_Linux_Code# gdb ./vmlinux 
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /media/sf_Linux_Code/vmlinux...done.
(gdb) set remotebaud 115200
(gdb) target remote /dev/ttyS0 (or target remote <terminal_server_ip>:<port> if debugging via terminal server)
Remote debugging using /dev/ttyS0

  • Rather than edit boot options as mentioned in the above blog post, edit boot options of VMDebugged to enable kgdb, let debugging control via serial port, wait kernel initialization until requested by debugger in VMDebugger. To do so, add "kgdboc=ttyS0,115200 kgdbwait" to the boot options of VMDebugged. 
    • kgdboc stands for kgdb over console. This config parameter allows us to set the interface mechanism with kgdb/gdb: <serial_port>[,<baud_rate>]
    • kgdbwait config parameter allows us to enable early debugging. If this is specified, the kernel waits as early as possible and waits until the front end requests to resume.

                           VMDebugged

              

  • Boot VMDebugged.
  • Now, VMDebugged stops before kernel initialization. And the debugger terminal in VMDebugged gets debugger control.
                           VMDebugged

         


                           VMDebugger



0xc11bca3f in arch_kgdb_breakpoint ()
    at /usr/src/linux-3.13.5/arch/x86/include/asm/kgdb.h:80
80 asm("   int $3");
(gdb) 

  • Then, just allow the booting process to continue in VMDebugger & let VMDebugged completely boot:

                           VMDebugger
(gdb) c
Continuing.
[New Thread 2327]

                           VMDebugged

           

  • Even if kgdb is not enabled in boot parameters, kgdb can be enabled at run time in sysfs interface.

To enable kgdb at run-time:
root@babu-VirtualBox:~# cat /sys/module/kgdboc/parameters/kgdboc
ttyS0,115200
root@babu-VirtualBox:~# 

To disable kgdb at run-time:
root@babu-VirtualBox:~# echo "" > /sys/module/kgdboc/parameters/kgdboc
root@babu-VirtualBox:~# 

To check whether kgdb is enabled/disabled:
root@babu-VirtualBox:~# cat /sys/module/kgdboc/parameters/kgdboc
ttyS0,115200
root@babu-VirtualBox:~# 

  • Now, to bring the control back to debugger, type "echo g > /proc/sysrq-trigger" in VMDebugged. 

                           VMDebugged

root@babu-VirtualBox:~# echo g > /proc/sysrq-trigger 

                           VMDebugger

Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 2327]
0xc11bca3f in arch_kgdb_breakpoint ()
    at /usr/src/linux-3.13.5/arch/x86/include/asm/kgdb.h:80
80 asm("   int $3");
(gdb) bt
#0  0xc11bca3f in arch_kgdb_breakpoint ()
    at /usr/src/linux-3.13.5/arch/x86/include/asm/kgdb.h:80
#1  kgdb_breakpoint () at kernel/debug/debug_core.c:1041
#2  0xc11bcb09 in sysrq_handle_dbg (key=<optimized out>)
    at kernel/debug/debug_core.c:801
#3  0xc179b85f in __handle_sysrq (key=103, check_mask=check_mask@entry=false)
    at drivers/tty/sysrq.c:535
#4  0xc179ba9c in write_sysrq_trigger (file=file@entry=0xf33e5e40, 
    buf=buf@entry=0x83e1c08 "g\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    count=count@entry=2, ppos=ppos@entry=0xf4523f98)
    at drivers/tty/sysrq.c:1083
#5  0xc139fc0e in proc_reg_write (file=file@entry=0xf33e5e40, 
    buf=buf@entry=0x83e1c08 "g\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    count=count@entry=2, ppos=ppos@entry=0xf4523f98) at fs/proc/inode.c:224
#6  0xc12f9989 in vfs_write (file=file@entry=0xf33e5e40, 
    buf=buf@entry=0x83e1c08 "g\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    count=count@entry=2, pos=pos@entry=0xf4523f98) at fs/read_write.c:473
#7  0xc12fa1f5 in SYSC_write (count=<optimized out>, 
    buf=0x83e1c08 "g\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
---Type <return> to continue, or q <return> to quit--- 
    fd=<optimized out>) at fs/read_write.c:522
#8  SyS_write (fd=1, buf=138288136, count=2) at fs/read_write.c:514
#9  <signal handler called>
#10 0xb776d424 in ?? ()
#11 0x083e1c08 in ?? ()
Cannot access memory at address 0xfbad2a89
(gdb)
  • For testing purposes, I then crash the VMDebugged. In case of crash, the debugger in VMDebugger automatically gets the control for further inspection.
                           VMDebugged

root@babu-VirtualBox:~# echo c > /proc/sysrq-trigger 

                           VMDebugger


Program received signal SIGSEGV, Segmentation fault.
sysrq_handle_crash (key=99) at drivers/tty/sysrq.c:140
140 *killer = 1;  <-- The line at which system crashed
(gdb) bt
#0  sysrq_handle_crash (key=99) at  drivers/tty/sysrq.c:140  <-- stack trace of the crash
#1  0xc179b85f in __handle_sysrq (key=99, check_mask=check_mask@entry=false)
    at drivers/tty/sysrq.c:535
#2  0xc179ba9c in write_sysrq_trigger (file=file@entry=0xf3a32240, 
    buf=buf@entry=0x83e1c08 "c\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    count=count@entry=2, ppos=ppos@entry=0xf4523f98)
    at drivers/tty/sysrq.c:1083
#3  0xc139fc0e in proc_reg_write (file=file@entry=0xf3a32240, 
    buf=buf@entry=0x83e1c08 "c\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    count=count@entry=2, ppos=ppos@entry=0xf4523f98) at fs/proc/inode.c:224
#4  0xc12f9989 in vfs_write (file=file@entry=0xf3a32240, 
    buf=buf@entry=0x83e1c08 "c\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    count=count@entry=2, pos=pos@entry=0xf4523f98) at fs/read_write.c:473
#5  0xc12fa1f5 in SYSC_write (count=<optimized out>, 
    buf=0x83e1c08 "c\nlgrind is /usr/bin/valgrind\ngrub-script-check\nbkdf2\ne\n", '\337' <repeats 143 times>, <incomplete sequence \337>..., 
    fd=<optimized out>) at fs/read_write.c:522
#6  SyS_write (fd=1, buf=138288136, count=2) at fs/read_write.c:514
#7  <signal handler called>
#8  0xb776d424 in ?? ()
---Type <return> to continue, or q <return> to quit---q
Quit
(gdb)


Hope this helps.



References:

http://sourceware.org/gdb/current/onlinedocs/gdb/

UA-48797665-1