Using Virtualization one is able to run a full computer operating system inside of an existing operating system. I’ve been using VirtualBox for years to virtualize many kinds of operating systems for many different reasons on my desktop computers. I first started using VirtualBox to run a Windows installation so I could do things I needed to do in Windows that I had not yet figured out how to do with a free/open source operating system (at that time Ubuntu). As I came to familiarity with *nix platforms, I wanted to try out new techniques I learned and I used VirtualBox to accomplish this. With this program I could have a sandbox where I could easily create, save, snapshot and destroy virtual desktops, servers, and networks. On my new FreeBSD server I wanted to use virtualization to create test servers that I could use while I learn about new software and refine what I know about system administration and computer programming.
The thing this time around is my server has no dedicated monitor. I’ve always used the GUI to interact with the VirtualBox software, but now I needed a way to do all the things I do with VirtualBox with a Command Line Interface (CLI). And that’s how I became introduced to
VBoxManage. If you have your system’s VirtualBox package installed you should have
VBoxManage installed as well:
Oracle VM VirtualBox Command Line Management Interface Version 4.3.10_OSE
(C) 2005-2014 Oracle Corporation
All rights reserved.
[-v|--version] print version number and exit
[-q|--nologo] suppress the logo
[--settingspw ] provide the settings password
[--settingspwfile ] provide a file containing the settings password
list [--long|-l] vms|runningvms|ostypes|hostdvds|hostfloppies|
VBoxManage every time I wanted to issue a command to VirtualBox did not appeal to me at all so I quickly made a
~$> echo "alias vbm='VBoxManage'" >> .bash_aliases && source .bash_aliases
Before we go any further, VirtualBox requires some kernel modules to be loaded.
~$ sudo kldload vboxdrv
~$ sudo kldload vboxnetadp
Okay, now we can get some work done. First create the VM and the virtual disk this machine will use.
~$ vbm createvm --name t0 --ostype FreeBSD --register
Settings file: '/home/jason/VirtualBox VMs/t0/t0.vbox'
~$ vbm createhd --filename VirtualBox\ VMs/t0/t0.vdi --size 2000
Disk image created. UUID: 1a1ff4fa-db67-4b1b-b597-fd0453ed82ac
We can now
list out the VMs to verify we created the device, then take a look at the profile of a virtual machine with the
~$ vbm list vms
~$ vbm showvminfo t0
~$ ls VirtualBox\ VMs/t0/
t0.vbox t0.vbox-prev t0.vdi
Now that the machine exists (virtually), we need to install a storage bus, and then add devices – namely a hard drive and a dvd drive – to it.
~$ vbm storagectl t0 --name sata_bus --add sata --portcount 4 --bootable on
~$ vbm storageattach t0 --storagectl sata_bus --port 1 --type hdd --medium VirtualBox\ VMs/t0/t0.vdi
~$ vbm storageattach t0 --storagectl sata_bus --port 2 --type dvddrive --medium downloads/FreeBSD-10.0-RELEASE-i386-disc1.iso
~$ vbm showvminfo t0|grep sata_bus
Storage Controller Name (0): sata_bus
sata_bus (1, 0): /usr/home/jason/VirtualBox VMs/t0/t0.vdi (UUID: 1a1ff4fa-db67-4b1b-b597-fd0453ed82ac)
sata_bus (2, 0): /usr/home/jason/downloads/FreeBSD-10.0-RELEASE-i386-disc1.iso (UUID: c277d5b5-e7e6-4172-9ea7-253a5a23d38e)
So there exists a virtual machine and it has a blank virtual hard drive and a dvd drive installed. Inside the dvd drive is the FreeBSD installation disc. At this point we could start the VM and install the OS, but how do we connect to the virtual server? Well we need to install a virtual network interface card and setup bridged networking. This will allow us to easily connect to the VM and give it access to the Internet so we can download any packages necessary for installation.
ath0: flags=8802 metric 0 mtu 2290
media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
status: no carrier
alc0: flags=8843 metric 0 mtu 1500
inet 192.168.200.8 netmask 0xfffffff0 broadcast 192.168.200.15
inet6 fe80::223:5aff:fee0:e42%alc0 prefixlen 64 scopeid 0x2
media: Ethernet autoselect (100baseTX )
lo0: flags=8049 metric 0 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
inet 127.0.0.1 netmask 0xff000000
~$ vbm modifyvm t0 --nic1 bridged --bridgeadapter1 alc0 --nictype1 82540EM
~$ vbm showvminfo t0 | grep NIC
NIC 1: MAC: 08002770C671, Attachment: Bridged Interface 'alc0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2: disabled
NIC 3: disabled
NIC 4: disabled
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
Above, the first thing that I did was list out the network interfaces of the physical machine (with
ifconfig). I did this to determine the which network interface I was going to bridge to (the one connect to the outside network). Each VM can have 8 NICs. With second command I set NIC 1 to be a bridged interface to
alc0, my wired ethernet, and to emulate an Intel 82540EM Gigabit Ethernet Controller. Now when the VM powers up it will have network connectivity.
Now we can install the operating system. Because the FreeBSD install disc does not establish an IP address without user interaction, I needed to forward X11 through my SSH connection. At first I received an error when I tried to do the X11 forwarding, but I followed this tutorial and cleared that error.
jason@desktop ~$ ssh -X jason@hostserver
~$ # I connected to host server with ssh -X for ssh forwarding
~$ # now I start the vm on the host server and I can interact
~$ # with it with the GUI on my desktop
~$ vbm startvm t0
With our setup the VM will boot the FreeBSD installation media in our dvd drive
After the OS is installed, you’ll want to eject the dvd drive so that when you reboot, you won’t reboot back into the install cd.
~$ vbm storageattach t0 --storagectl sata_bus --port 2 --medium none
Now the OS is installed and (if you set it up that way) it will obtain an IP address on boot and start the SSH server that you can connect to from another machine
~$ vbm startvm t0 --type headless
Waiting for VM "t0" to power on...
VM "t0" has been successfully started.