XEN Virtualization –
Common XEN commands you may need you utilize, all are command line utilities.
1) SSH into the box vmbeta or vmalpha as root (on vmalpha you will need to log in as administrator first then su to the root account.)
To view the running virtual machines you have two options.
A)”xm list” will produce output similar to
B)”xentop” This will start an interactive command line application similar to top except that it is used to monitor virtual XEN machines. It will provide the same information as gained from “xm list” and additional information.
There will always be a domain0 that is the “host” OS or in this case as XEN is a hypervisor it is the control OS. That is what you are connected to in your SSH session, anything else listed are guest machines. In our example above, and since we are not using virtualization heavily, you see one machine running, this is noted as 2008sbs, you will see in the pictures above that the state of the SBS machine is “b”, this is normal when a machine is waiting on disk activity or in an idle state and not doing anything because there is nothing to do.
Machines that are automatically started at boot time are located in “/etc/xen/auto” this is the case with most of our virtual machines and therefore manually starting a virtual machine will not need to frequently be done. But if you need to for some reason the following command will start a virtual machine.
xm create /path/to/vm.cfg
example:
xm create /etc/xen/2008sbs.cfg
It will process for a moment then confirm that the virtual machine started. If there is an issue it will notify you that an error has occurred. You can check the log files located in /var/log/xen for information should an error occur starting the virtual machine.
You can also Pause a running VM, Save the state of a running VM, and control a VM like you were pressing the power button on a machine.
xm pause –pauses a VM
xm resume – resumes the VM from a paused state
xm save – saves the state of a VM including whatever is in RAM
xm restore – restores a VM from a saved state
xm reset – like pressing the reset button
xm reboot – like trying to perform an OS reboot
xm shutdown – tries to execute a graceful shutdown of the VM OS
xm destroy – kills the VM like you pulled the plug from the wall.
XEN uses VNC to connect to the console of a virtual machine. Depending on how the virtual machine configuration was setup the port that the VNC console is on will be 590 + the id of the virtual machine, 590 + whatever the next sequentially available VNC screen was, or an assigned VNC screen. In our case we have assigned 5902 as our VNC console session for the SBS 2008 VM. Depending on your VNC viewer it may be in the form of host:2 or host:5902 to view the console. The configuration is setup to listen to any connection from the LAN.
VirtualBox Virtualization
In addition to XEN we also use Virtualbox in some cases. VirtualBox is a full host based virtualization solution that does not require the hardware assists that XEN does in order to virtualize a machine. This can decrease performance slightly, but VirtualBox can also take advantage of the same processor based virtualization technology that XEN requires if the technology is available. VirtualBox allows us to virtualize on Windows and Linux machines, and on Desktops or Servers, it has both a GUI interface for running machines and a “headless” mode which can launch a VM from the command line and allow us to connect by RDP session to the console of the virtual machine.
Creating a Virtual machine configuration is most easily done with the GUI interface. Virtual machine configurations are held as XML files and associated resource files. They can be created from the CLI, but the GUI will simplify creation. If a VNC server for the Server is not all ready running start
It will tell you what “display” the vnc server is running on, in the example above it is started on display 2 also known as 5902. Log into the vnc session and start the VirtualBox management console. The password to log into the vnc session is the domain password all lower case.
The console will look like this
We can create machines by clicking “New” we can also get the status of running machines as well. The machine creation process is wizard driven and should be easy enough to follow. This is valuable if the machine configuration becomes corrupt, which may happen. It is very unlikely that a corruption of the virtual hard drive will occur unless the physical hard drive becomes corrupt. If this occurs you need to remove the old machine by discarding it and then creating a new one. You may have to manually remove the vestiges of the old machine from the configuration location. These files would be located at /home/administrator/.VirtualBox/Machines then delete the folder with the VM name you want to get rid of. When setting up a new machine, particularly one of our Debian based Linux machines you need to make sure you use the same MAC address for the network adapter in the VM setup, you will find this under the network setting of a newly created or existing VM. This is essential because otherwise the Operating system will detect the change and assign a new device ID to the adapter in the virtual environment. i.e. eth0 in a recreated VM with different MAC address for network adapter now becomes eth1 and as far as the OS is concerned eth0 still exists but isn’t connected to anything. An example of the network configuration screen is shown below, and the additional options screen is opened by clicking on a little yellow “gear” next to the attached to drop down.
The MAC address for our spam filter is: 08:00:27:f6:c4:e5 Leave the colons out as you can see from the screenshot.
DO NOT START A VM form the GUI console unless you plan to shut it down after. If the GUI session closes the server will close. You need to start a machine from the command line, starting it in the headless mode. The following commands are for controlling the virtual machine from the command line.
su administrator -c "VBoxHeadless -p 3310 -startvm spammy &"
change spammy to the VM as the case may be.
The su is required so that it is not spawned by the SSH session and will continue after log off, the & is required to tell it to move to the background after it starts up this was you can work on something else or logoff, etc… without the ampersand you would have to use ctrl + c to break the process and the VM would shutdown. After issuing the above command and receiving the feedback which says copyright Sun (or Oracle, now that Sun has been acquired) and listening on port press enter to return to command prompt.
Once you have issued the start command for the VM you can verify that all is going well by accessing it via RDP at vmalpha:3310 (For spammy in this case) this will connect you to it like you were sitting at a console.
Additionally I have created an auto VNC server on vmalpha to login via vnc for admin functions vnc to vmalpha:1 and enter the domain password. From here you can access GUI configuration of VMs if they are not running. DO NOT START A VM FROM VIRTUALBOX MANAGER IN GUI, USE CONSOLE OR A TERMINAL WINDOW FROM THE GUI AND ISSUE THE COMMAND ABOVE.
If you have to perform a restart of the physical machine or a VM you should also be able to perform this from the Webmin admin console accessed by HTTPS through port 10000, you can do this on any of the linux machines we have. Including the Virtual Ones like spammy.
SSH to vmalpha login as “administrator” with domain password
Shutdown running vms
First list running vms
VBoxManage list runningvms
Then shutdown running vms
VBoxManage controlvm “spammy” acpipowerbutton
If this fails, you can run The following command will kill it period like pulling the plug on it.
VBoxMange controlvm “spammy” poweroff
Alternatively you can SSH into spammy using the same credentials as the vm server and run
Shutdown now –h
To reboot the vmserver login via SSH or via console using credentials above then type
Su (all lower case)
Then enter domain password when asked for a password
Reboot (all lower case)
Troubleshooting
If a virtual machine will not start under VirtualBox it is likely due to a corrupt machine configuration, utilizing the information above delete the machine configuration, taking care to not delete the virtual hard drive. The recreate the virtual machine, taking care to reuse the same Mac address as the original virtual machine. You should be able to get this from the machine xml file before deleting the machine if you cannot access the configuration for network from the GUI console.
If a virtual machine does not start in XEN you will find the logs located in /var/log/xen very useful to figuring out the issue. Some of the more common issues that might be encountered are the network bridge not being up, or failure of qemu to emulate a device properly.
Additional troubleshooting items might be added in future revisions.