How-To: Using VBoxManage to Delete a Virtual Machine from VirtualBox

deleteOne common problem I see from people learning to manage Virtual Machines within VirtualBox using the VBoxManager command line is the error:

Cannot unregister the machine <Virtual-Machine-Name>  because it has 1 hard disks attached

Before a VM can be unregistered or deleted, all disks that have been “attached” need to first be disassociated from the VM. For this example, I’m using a virtual machine that I have set up and named “VNAS” that was used to test an OpenFiler NAS installation (which, by the way, worked great). Now that testing is complete, I am ready to remove it.

The removal for a standard VM install can be completed in a short list of steps.

Step one: Get the name or UUID and details of your VM

VBoxManage list vms

VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

“VNAS” {8a48759d-4e6d-473f-ab0f-8ff59aa727eb}

That command will return the names of all registered VMs and their UUID. Make sure you get the correct name or UUID for the VM you will be modifying.

Step two: Get the disc information for your VM

There are two methods you can use to the get the information for each virtual disk registered to a virtual machine. The first is to list the VM info for a specified VM which includes the Virtual Disks that are in use by it.

VBoxManage showvminfo <Virtual Machine Name or UUID>

VBoxManage showvminfo VNAS
VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Name: VNAS
Guest OS: Other/Unknown
UUID: 8a48759d-4e6d-473f-ab0f-8ff59aa727eb
Config file: /secondary/.Virtual/machines/VNAS/VNAS.xml
Memory size: 512MB
VRAM size: 8MB
Number of CPUs: 1
Boot menu mode: message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI: on
PAE: on

Primary master: /secondary/.Virtual/vdisks/OFInstallDisk (UUID: xxxxxxx)
Primary slave: /secondary/.Virtual/vdisks/VNASStore1 (UUID: xxxxxxx)
Secondary slave: /secondary/.Virtual/vdisks/VNASStore2 (UUID: xxxxxxx)

In this example you can see I have 3 disks registered with the vm.

  • Primary Master (hda)
  • Primary Slave (hdb)
  • Secondary Slave (hdd)

NOTE: You might be asking, Why does the sequence jump from hdb to hdd? What happened to hdc? The answer is, hdc is reserved for CD/DVD mounting, so you can’t add a virtual disk there.

The second, alternative method is to use the the VBoxManage command “list” with the “hdds” option to list all the Virtual Disks in the system. This will display a list of All the disks you have created and registered for ALL VMs. Information for each Virtual Disk and the VM it is registered to is displayed. Here you can see the three disks registered with my VNAS VM indicated by the “Usage” lines.

VBoxManage list hdds

UUID:         eebbb4c7-c539-4da4-b8ab-e5777b32520b
Format:       VDI
Location:     /secondary/.Virtual/vdisks/VNASStore1
Accessible:   yes
Usage:        VNAS (UUID: 8a48759d-4e6d-473f-ab0f-8ff59aa727eb)

UUID:         9f238d31-f794-420f-83a7-ccf811d52244
Format:       VDI
Location:     /secondary/.Virtual/vdisks/VNASStore2
Accessible:   yes
Usage:        VNAS (UUID: 8a48759d-4e6d-473f-ab0f-8ff59aa727eb)

UUID:         2ce976c9-0a37-49c1-8d34-3962c563a256
Format:       VDI
Location:     /secondary/.Virtual/vdisks/OFInstallDisk
Accessible:   yes
Usage:        VNAS (UUID: 8a48759d-4e6d-473f-ab0f-8ff59aa727eb)

In my opinion, method one the easiest quickest way to see what Virtual disks are assigned to a specific VM.

Step Three: Disassociate the Virtual Disk[s]

VBoxManage modifyvm <Virtual Machine Name or UUID> —hda none

VBoxManage modifyvm VNAS –hda none

If you have more than one disk registered with a vm as I do here, you’ll also need to disassociate those as well.

VBoxManage modifyvm VNAS —hdb none

VBoxManage modifyvm VNAS —hdd none

Step Four: Unregister and delete the VM

VBoxManage unregistervm <Virtual Machine Name or UUID> –delete

VBoxManage unregistervm VNAS –delete

Step Five: Confirm

VBoxManage list vms

VirtualBox Command Line Management Interface Version 3.0.8
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

[NOTE: there are no VMs listed]

This is the same command that was executed in step one. After running this command again you should no longer see your Virtual Machine listed.

Note: This process will only remove your VM from VirtualBox. It will not remove/delete the actual virtual disk file (.vdi). You can delete that manually, or save it to use with another virtual machine instance.

VirtualBox and Bridged Networking on a Headless Ubuntu Server Host

In the previous VirtualBox post, I explained how (and how not) to set up bridged networking with LAN access to a Virtual Machine running on a Windows XP Host. Today I will explain how to do the same thing (without the How Not To part) using a virtual Machine running on a Headless Ubuntu Server.

For this example we can assume a few things:

  1. You have already set up a headless VirtualBox server
  2. You have already created a Virtual Machine instance. For this sample, we will call the Virtual Machine “MyVM”.

Believe it or not, setting up bridged networking to allow your VM to access your network is pretty simple and completed by issuing the following VBoxManage command in a terminal window.

Command: VBoxManage modifyvm “MyVM” –nic1 bridged –nictype1 82540OEM –bridgeadapter1 eth0

Break it down

To understand a bit more about what’s happening here, let’s break down the command string from the beginning.

VBoxManage – This is the command line utility used to access, control, configure and manage your VirtualBox Virtual Machines.

modifyvm – This command allows you to make changes to the properties of a Virtual Machine, including the amount of memory assigned, nic interfaces, Virtual device boot sequence, number of CPUs, etc. It can be compared to the Settings dialog of the VirtualBox Graphical user Interface. The command line version, however, offers additional advanced options not found in the GUI.

Note: the VM must be registered within VirtualBox, but must not be running

MyVM” – This is simply the name of the VM you want to modify.

–nic1 bridged – The –nic1 parameter is used to set the type of networking your VM should use for each of the it’s virtual network cards. You can have more than one network card in use for a VM so the paramater is written as –nicX where X is the network card being targeted. Here, “–nic1” is the first network interface, –nic2 would be the second and so on. This portion of the command string is setting the type of networking on the first interface to “bridged”.

–nictype1 82540OEM – The –nictype1 parameter allows you to specify which networking hardware VirtualBox should emulate for the VM’s virtual network cards. Here we set the networking hardware to emulate an Intel PRO/1000 MT Desktop card or 82540EM.

–nictypeX follows the same sequence numbering and –nicX for multiple interfaces where –nictype1 is the first virtual card, –nictype2 is the second and so on.

Note:  The following is a list of the available nic hardware types and the associated ID recognized in VirtualBox.

  • AMD PCNet PCI II = Am79C970A
  • AMD PCNet FAST III = Am79C973 (the default)
  • Intel PRO/1000 MT Desktop = 82540EM
  • Intel PRO/1000 T Server = 82543GC
  • Intel PRO/1000 MT Server = 82545EM
  • Paravirtualized network adapter = virtio-net

–bridgeadapter1 eth0 – Finally we have the –bridgeadapter paramater. This is the only part of the command string that references a part of the VirtualBox host and tells your VM which physical host adapter to pass it’s traffic through.

Again, this uses the same sequence numbering as nicX and nictypeX for multiple interfaces. Here, we are setting the bridgeadapter for our first virtual network card to use the eth0  interface on the host. Note that is eth zero, as in the number and not the letter O.

And that’s it. Restart your VM and you should now have a working bridged network interface for you VM with full network and internet access.

VirtualBox 3.0.4 and Bridged Networking on XP Host with GUI

Photo: Wally Gobetz
Photo: Wally Gobetz

Editors Note:

While I was writing this, the solution to my problem struck me unexpectedly. Click here to skip the drama and jump right ot the solution.

Originally, this article started out as a complete rant and cry for help. I started to write about the failure and frustration of the installation and network configuration of a virtual machine in VirtualBox 3.0.4.  It just would not work. The problem, as it turned out, was that I was over thinking the process. BUT, that is not completely my own fault.

Continue reading “VirtualBox 3.0.4 and Bridged Networking on XP Host with GUI”

Add a Network Printer to an Ubuntu Desktop – The Easy Way?

The Rant

It’s no secret that I am a fan of Ubuntu Linux. BUT.. one of the annoying things about using Ubuntu is trying to set up a network printer on a desktop or workstation. Regarding nearly all administrative tasks under most Linux systems that would require root permissions, Ubuntu has done a nice job of making it possible to operate a system as a “normal” user without elevated privileges, and then easily gain the elevated (root) privileges temporarily assigned to complete some specific administrative task. Ubuntu detects when a user is trying to do something requiring the elevated (root) privileges and pops up a small window asking for the current user’s password to gain the required permission. All the magic happens behind the scene and the user never has to issue a text command. It wasn’t long ago that users would have had to open a command terminal and issue all the instructions by hand. Well.. we’ve come a long way.. With the exception of installing a network printer. For some reason, when installing a printer in Ubuntu, the user is not prompted with the normal su password pop-up that presents itself for all other administrative tasks. Instead, the CUPS system prompts the user for the root password – and under Ubuntu, there is no root password by default meaning that root can not complete any direct action requiring a password. In fact, root can not log directly into the system at all. Fortunately, the solution is fairly easy.

The Solution

Do not try to install a printer from System > Administration > Printing menu. It won’t work. Sure, it will allow you to go through the wizard and give you the false impression that you’re actually accomplishing something – until you reach the point where a driver needs to be installed and you’re prompted for the root password. Instead, go to the Applications > Accessories menu and select Terminal.

Once the terminal window opens, issue the following command

sudo system-config-printer

The next line in the terminal window will ask for your password. Type in your user password and hit enter. If all is correct, the printer setup and configuration window will open with elevated privileges enabled and you can finish installing and setting up your new printer from comfort of an easy to use GUI.

Sample Setup

Lets take a few minutes and walk through the process. In this example, I will be setting up a Dell 1700 Laser Printer in my Home Office. Before you get started, you will need to know a few things about the printer first. Continue reading “Add a Network Printer to an Ubuntu Desktop – The Easy Way?”