Updated: Running a virtual machine in virtualbox 3.1 from the command line

Posted in Ubuntu, VirtualBox, linux on February 2nd, 2010 by alex – Be the first to comment

After upgrading to VirtualBox 3.1.2 I noticed some changes in the command line interface when it comes to creating and managing virtual machines. Because of that, I decided to update my previous post.

Some terms in this post:
host – machine on which VirtualBox runs, your “real” server
guest – virtual machine running in VirtualBox, your virtual server

  1. Install or Update VirtualBox:
  2. Create the virtual machine and register it with VBox. The name of the vm is vbuntu.
    user@host:~$ VBoxManage createvm --name vbuntu --ostyle "Ubuntu" --register
  3. Create a SATA controller which we will use to control the disk image.
    user@host:~$ VBoxManage storagectl vbuntu --name "SATA Controller" --add sata --controller IntelAhci
  4. Create and register the virtual disk image, basically the virtual disk from which the vm runs. Give it a filename and a size in MB, here my virtual disk image is name vbuntu.vdi and it has 30,000 MB.
    user@host:~$ VBoxManage createhd --filename vdesktop.vdi --size 30000 --variant Standard
  5. Link the vdi to the vm’s SATA controller we previously created. Connect it to the first port and make it the first device, basically sda1
    user@host:~$ VBoxManage storageattach vbuntu --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium vdesktop.vdi
  6. Create an IDE controller which we will use to control the virtual dvd drive from which we will install the OS.
    user@host:~$ VBoxManage storagectl vbuntu --name "IDE" --add ide
  7. Register the install disk image of ubuntu server with VBox and mount the install disk on your vm.
     user@host:~$ VBoxManage storageattach vbuntu --storagectl "IDE" --port 0 --device --0 --type dvddrive --medium /path/to/ubuntu-9.04-server-amd64.iso
  8. Modify the boot order for the virtual machine so it boots from the install dvd first.
     user@host:~$ VBoxManage modifyvm vbuntu --boot1 dvd --boot2 disk
  9. Modify the default options for the vm. I gave the vm 1GB of ram, turned on ACPI for power control, turned on PAE (ubuntu server requires it, it enabled 32bit hosts to use more than 4GB of ram) and I also turned on Enable VT-x/AMD-V which are the technologies Intel and AMD processors use for hardware virtualization extensions. To use these extensions your host must have a processor supporting them and then enable them from the BIOS.
    user@host:~$ VBoxManage modifyvm vbuntu --memory 1024MB --acpi on --pae on --hwvirtex on
  10. For networking I’m using bridged networking. First set the vm nic to bridged mode, then bridge it with one of the host’s nic. Here I bridged it over my host’s eth1 nic.
    user@host:~$ VBoxManage modifyvm vbuntu --nic1 bridged
    user@host:~$ VBoxManage modifyvm vbuntu --bridgeadapter1 eth1
  11. I also changed the port for the remote desktop protocol to 33891 because I’m running multiple vm’s, so each vm has its own port.
    user@host:~$ VBoxManage modifyvm vbuntu --vrdpport 33891
  12. Start the vm in the background, so remember to add the ampersand at the end of the command. After that you can RDP into the vm by connecting to the IP of your host system on the above set port. Now you can install the guest OS.
    user@host:~$ VBoxHeadless -startvm vbuntu &
  13. To shut off the vm use this command.
    user@host:~$ VBoxManage controlvm vbuntu poweroff
  14. Once done with the install, you can unregister the install disk and have the vm boot from its own hdd.
    user@host:~$ VBoxManage storageattach vbuntu --storagectl "IDE Controller" --port 0 --device 0 --medium none
    user@host:~$ VBoxManage modifyvm vbuntu --boot1 disk --boot2 none
  15. Optionally here are the steps to get rid of the vm and its disk image if you don’t need it anymore.
    user@host:~$ VBoxManage modifyvm vbuntu --boot1 none
    user@host:~$ VBoxManage unregistervm --delete vbuntu
    user@host:~$ VBoxManage unregisterimage disk "vbuntu.vdi"

Let me know if you have any suggestions or comments as to the process I just described.

  • Share/Bookmark

Check temperature of HDD in a 3ware RAID card

Posted in Hardware, Monitoring, RAID, Storage, Ubuntu, linux on December 20th, 2009 by alex – Be the first to comment

Recently I bought a 3ware sata raid card and installed 3 hard disks in it for a raid 5 array (maybe that’ll be another blog post), but I noticed that hddtemp didn’t read the temperature correctly anymore.
I figured this had something to do with hddtemp having to read through the raid card to get the temperature, so this is how I got temperature readings for my hard disks in the 3ware raid card.
This is done on ubuntu, but smartctl works on most linux distros so you can use the same instructions on other distros, apart from installing smartctl.
The smartctl script on ubuntu is found in the smartmontools package, so install it:

user@server:~$ sudo apt-get install smartmontools

Once that is installed, you can try the help command to make sure it got installed correctly:

user@server:~$ smartctl -h

If that works correctly, now we’re ready to read some temperatures.
Depending on the series of the 3ware card you have, the care is accessed through either /dev/twa or /dev/twe
Now, to read the temperature of the hdd in slot 1, the command is:

user@server:~$ sudo smartctl -H -d 3ware,0 /dev/twa0

Note that after the comma in 3ware,0 comes the number of the hdd slot you’re trying to read, going from 0 up. For example, for the hdd in the second slot, it would be 3ware,1
Also, I had my 3ware raid card in /dev/twa0, which might not be the case for your setup.
You might also want to look through the smartctl tool’s manual page because it’s quite a powerful tool for monitoring hdd performance and kicking off SMART tests on the hdds.

  • Share/Bookmark

VirtualBox 3.1 new feature: Snapshots

Posted in Ubuntu, VirtualBox on December 1st, 2009 by alex – Be the first to comment

A new feature in VirtualBox 3.1 is the ability to take a snapshot of a VM.
Each snapshot saves the state of the VM and you’re able to go back to it, just like version control.
This means that if you go back to a snapshot, you will lose all the changes you made after the snapshot.
Snapshots can be taken while the VM is running, so you can take a snapshot before installing a new program to play around with.
If something goes wrong with the installation, just start the snapshot and you’re back in the game.
A snapshot does not create a separate VM, so you’re still using the original VM, just modifying what’s on it.
Remember that if you go back to a snapshot, all the changes you made since taking the snapshot will be lost, so before going back, take another snapshot of the current state.
Now for the practice part.

The scenario is this: you have a fresh install of ubuntu on a VM called vbuntu.
You want to install something on it, but want to create a snapshot in case something goes wrong.

Look at the previous posts to see how to create the initial VM.
Once that is done, this is how you create a snapshot of the original VM called vbuntu, and call the snapshot initial_install

user@server:~$ VBoxManage snapshot vbuntu take initial_install

Then you do your install. If something goes wrong, you want to go back to the initial_install snapshot, here’s how to

user@server:~$ VBoxManage snapshot vbuntu restore initial_install

If your install goes well and want to create another snapshot before you install another program, you should take another snapshot, like above.

For more information about VirtualBox 3.1 snapshots check out the VirtualBox site.

  • Share/Bookmark

Problems with ubuntu when upgrading to karmic koala: mysqld and dns resolution

Posted in Ubuntu, linux on November 8th, 2009 by alex – 1 Comment

After upgrading to Ubuntu 9.10, Karmic Koala, I noticed I had a couple of annoying problems.
First of all I was unable to connect to any outside site, so I tried to ping yahoo.com but I had an error say that the domain name could not be resolved. I tried pinging the IP address for yahoo.com (got that from using another computer to look it up) and that worked.
What this means is that the ubuntu machine can’t resolve domain names to their IP address, which it usually does through nameservers.
Apparently the upgrade process erased my nameserver configuration.
On ubuntu the nameserver configuration can be found in
/etc/resolv.conf
In that file, set your nameservers like this:

nameserver 192.168.1.1
nameserver 10.0.0.1

Those just examples, but the 192.168.1.1 IP address in my case was my router’s IP address since it acts as a relay for the ISP’s nameservers, the next one is just an example IP. Now try to bring your ethernet interface up, or just reboot your box.

Another annoying problem is that the mysql server would not start on the ubuntu machine. I checked in the dmesg error log and found this weird looking error:

[10360.109659] type=1503 audit(1256893798.480:502): operation=”open” pid=23026 parent=23025 profile=”/usr/sbin/mysqld” requested_mask=”r::” denied_mask=”r::” fsuid=0 ouid=0 name=”/sys/devices/system/cpu/”

After a couple Google searches I found some other people had the same problem and it stemmed from an option in the mysql configuration where it disabled berkley db support.
I went in the mysql configuration file, in ubuntu /etc/mysql/my.cnf and commented out the skip-bdb, just put a # in front of the option:

#skip-bdb

That should do it, now restart mysql and it should work, if it doesn’t try to reboot and see if that does it.
user@host:~$ sudo /etc/init.d/mysqld restart
That’s all for now, let me know if you had any other problems when upgrading.

  • Share/Bookmark

Running a virtual machine in virtualbox 3.0 from the command line

Posted in Ubuntu, VirtualBox, linux on July 12th, 2009 by alex – Be the first to comment

VirtualBox has a great user interface but sometimes it’s just not necessary, especially if you want to create/start/stop virtual machines remotely or if you are just running a server without a windowing system.
Luckily VBox allows you to do everything from the command line interface (cli) that you can do from the user interface and it also allows you to remote desktop connect to the virtual machine.
In this post I’ll show you how to install VirtualBox on an ubuntu linux server, then set up and run a virtual machine from the cli.

Some terms in this post:
host – machine on which VirtualBox runs, your “real” server
guest – virtual machine running in VirtualBox, your virtual server

  1. Install VirtualBox:
  2. Create the virtual machine and register it with VBox. The name of the vm is vbuntu.
    user@host:~$ VBoxManage createvm -name vbuntu -register
  3. Change the boot adapter to the virtual dvd drive so we can boot the OS install disk.
    user@host:~$ VBoxManage modifyvm vbuntu --boot1 dvd
  4. Create and register the virtual disk image, basically the virtual disk from which the vm runs. Give it a filename and a size in MB, here my virtual disk image is name vbuntu.vdi and it has 30,000 MB.
    user@host:~$ VBoxManage createvdi -filename "vbuntu.vdi" -size 30000 -register
  5. Link the vdi to the vm, here hda is the hdd off which the vm boots.
    user@host:~$ VBoxManage modifyvm vbuntu -hda vbuntu.vdi
  6. Register the install disk image of ubuntu server with VBox. Then mount the install disk on your vm.
    user@host:~$ VBoxManage registerimage dvd /path/to/ubuntu-9.04-server-amd64.iso
    user@host:~$ VBoxManage modifyvm vbuntu -dvd /path/to/ubuntu-9.04-server-amd64.iso
  7. Modify the default options for the vm. I gave the vm 1GB of ram, turned on ACPI for power control, turned on PAE (ubuntu server requires it, it enabled 32bit hosts to use more than 4GB of ram) and I also turned on Enable VT-x/AMD-V which are the technologies Intel and AMD processors use for hardware virtualization extensions. To use these extensions your host must have a processor supporting them and then enable them from the BIOS.
    user@host:~$ VBoxManage modifyvm vbuntu --memory 1024MB --acpi on --pae on --hwvirtex on
  8. For networking I’m using bridged networking. First set the vm nic to bridged mode, then bridge it with one of the host’s nic. Here I bridged it over my host’s eth1 nic.
    user@host:~$ VBoxManage modifyvm vbuntu --nic1 bridged
    user@host:~$ VBoxManage modifyvm vbuntu --bridgeadapter1 eth1
  9. I also changed the port for the remote desktop protocol to 33891 because I’m running multiple vm’s, so each vm has its own port.
    user@host:~$ VBoxManage modifyvm vbuntu --vrdpport 33891
  10. Start the vm in the background, so remember to add the ampersand at the end of the command. After that you can RDP into the vm by connecting to the IP of your host system on the above set port. Now you can install the guest OS.
    user@host:~$ VBoxHeadless -startvm vbuntu &
  11. To shut off the vm use this command.
    user@host:~$ VBoxManage controlvm vbuntu poweroff
  12. Once done with the install, you can unregister the install disk and have the vm boot from its own hdd.
    user@host:~$ VBoxManage modifyvm vbuntu -dvd none
    user@host:~$ VBoxManage unregisterimage dvd /path/to/ubuntu-9.04-server-amd64.iso
    user@host:~$ VBoxManage modifyvm vbuntu -boot1 hda
  13. Optionally here are the steps to get rid of the vm and its disk image if you don’t need it anymore.
    user@host:~$ VBoxManage modifyvm vbuntu --hda none
    user@host:~$ VBoxManage unregistervm --delete vbuntu
    user@host:~$ VBoxManage unregisterimage disk "vbuntu.vdi"

Let me know if you have any suggestions or comments as to the process I just described.

  • Share/Bookmark