You can create, delete, run, stop, and manage your virtual machines graphically. The tool virt-manager allows you to use a graphical interface to interact with KVM.
Installation
Install virt-manager on your desktop:
- From a Command Line
sudo apt-get install virt-manager
- Or from the Ubuntu Software Center:
-
Applications -> Ubuntu Software Center -> Search for “virt-manager”
- Install “Virtual Machine Manager”
-
Launching
To launch KVM/VirtManager:
-
Applications -> System Tools -> Virtual Machine Manager
To manage virtual machines on the local system:
- Double-click on “localhost (System)”
Or to connect to any other virtual machine host (running libvirt-bin and openssh-server):
-
File -> Add Connection
-
Hypervisor: QEMU/KVM
-
Connection: Remote tunnel over SSH
-
Hostname: hostname or IP address of the remote host. For a user other than root use the format username@hostname and make sure the user is part of the libvirtd on the remote server.
Creating a Virtual Machine
- First, download an ISO cd image of some OS you want to run. For Ubuntu, you can find these at:
-
Double click on the name of the host. The Status column should read Active
-
Right click on the name of the host, and select New
- This will start a wizard to guide you through the rest of your VM creation
- Enter your virtual machine details
-
Name: foo
-
Choose Local install media (ISO image or CDROM), or you can use another method if you know what you’re doing
-
Forward
-
- Locate your install media
-
Use ISO image
-
Browse to find the ISO you downloaded earlier
-
Optional: Select the matching OS Type
-
Optional: Select the matching Version
-
Forward
-
- Choose Memory and CPU settings
-
Memory (RAM): 512MB (your choice)
-
CPUs: 1 (your choice)
-
Forward
-
-
Select Enable storage for this virtual machine
-
Select Create a disk image on the computer’s hard drive
-
8 GB is the default
-
To speed up VM creation, you can unselect Allocate entire disk now
-
Forward
-
- Ready to begin installation
- Confirm the details
-
Finish
- You should now see the OS installation proceed within a virt-manager window. Complete the installation and reboot.
- Enter your virtual machine details
Working with a Running Virtual Machine
If you double-click on any machine in Virtual Machine Manager, a new window will open, with functions unique to that virtual machine.
From this window, you apply several actions to this VM:
- Run
- Pause
- Shutdown (cleanly shuts down the VM OS)
- Reboot (cleanly reboots the VM OS)
- Force off (equivalent to yanking the power, could yield data loss in the VM)
- Fullscreen
Console
The Console tab in the main window provides access to the VM’s desktop and tty consoles.
- The desktop is accessed over a VNC connection to the guest. When you are “inside” the guest, the keyboard and mouse are “locked” to the guest. To release the keyboard and mouse, press the buttons Ctrl-Alt at the same time.
- The tty console can been accessed by:
-
Send Key -> Ctrl-Alt-F1
-
Details
The Details tab provides a view of the resources assigned to this virtual machine. Here, you can see:
- the number of processors allocated
- the amount of memory assigned
- the default boot device (CDROM or Hard Disk)
- a listing of the storage devices attached to the VM and their type (CDROM, IDE, SCSI, Virtio)
- the network adapter and its model
- the emulated mouse, display, serial, and sound hardware
Deleting a Virtual Machine
To delete a virtual machine:
- Shutdown or force off the VM.
- In Virtual Machine Manager, highlight the VM you want to delete
-
Click Delete at the bottom of the panel
- You can optionally delete the associated disk file for the VM. If you don’t want or need the data within the VM itself, you should delete the storage file, as these are usually very large.
in UBUNTU CENTOS, LINUX KVM, REDHAT AND FRIENDS
The virsh command can be used to mange local or remote guest operating systems. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains.
in terminal type
#virsh
List Running VMS
Type the following command:
virsh# list
Sample outputs:
Id Name State ---------------------------------- 1 ncomputesrv running 2 win2k8SRV running
List all VMS (including shutoff )
virsh# list –all
Shut Down A Guest
virsh# shutdown dominName (eg:ncomputesrv or Id name)
virsh# shutdown 2
Start A Guest
virsh# start domainname or ID
Rebooting A Guest
virsh# list
virsh# reboot domaiName
virsh# reboot 3
virsh# reboot win2008biz
Forcefully Stop A Guest
Force a guest to stop with the virsh command if it is not responding or crashed
virsh# list
virsh# destroy domainName
virsh# destroy openbsd.nixcraft.in
Note:it will take some time to be back normal mode.
Get Information About Guest
virsh# list
virsh# dominfo dominName
virsh# dominfo 2
virsh# dominfo freebsd
Sample outputs:
Id: 2 Name: freebsd UUID: 6b7f44df-b67a-b1e1-0f9a-40c9ad760b0a OS Type: hvm State: running CPU(s): 1 CPU time: 26.3s Max memory: 524288 kB Used memory: 524288 kB Autostart: disable
Get Information About Node
virsh# nodeinfo
Sample Outputs:
CPU model: x86_64 CPU(s): 4 CPU frequency: 2394 MHz CPU socket(s): 1 Core(s) per socket: 4 Thread(s) per core: 1 NUMA cell(s): 1 Memory size: 8181332 kB
Quit from the Virsh
virsh# quit
Conclusion
The first part in this series covered KVM installation, KVM bridged based networking, KVM guest setup using virt-install, virt-manager, kickstart based guest installation and troubleshooting KVM with log files. Stay tunned for next part of series which will cover other advanced topics such as:
- VM storage configuration using NFS and iSCSI
- VM live migration
- VM security and firewall
- VM load balancing
- VM instillation using Cobbler
Source: http://www.cyberciti.biz/faq/linux-kvm-stop-start-guest-virtual-machine/
Q:1 What is Virtualization ?
Ans: Virtualization is a technique for creating virtual resources (rather than the actual) such as server, storage device, network and Operating system. Virtualization is dis-associating the tight bond between software and hardware.
Q:2 What are the different types of Virtualization ?
Ans: Virtualization can be used in different ways and can take many different forms. Some of them are listed below :
- Server Virtualization
- Network Virtualization
- Hardware virtualization
- Application virtualization
- Desktop virtualization
- User virtualization
Q:3 What is the difference between full virtualization & para virtualization ?
Ans: Full virtualization & para virtualization both comes under the Hardware virtualization. Some of the difference between them are listed below :
Full Virtualization : It is a virtualization in which guest machine(virtual machines) is unware that it is in virtualized environment therefore hardware is virtualized by the host operating system so that the guest can issue commands to what it thinks is actual hardware but really are just simulated hardware devices created by the host
Para Virtualization : It is a virtualization in which guest machine is aware that it is in virtualized environment . If guest machine require resources like memory & cpu , it issues command to guest operating system instead of directly communication with actual hardware.
Q:4 What is hypervisor ?
Ans: Hypervisor is a peace of a software that is being install on the physical machine , which then further creates and run virtual machines. Virtual machine are known as guest machines and host machine is the hypervisor on which different virtual machines are created.
Q:5 What are different hypervisors available in Linux ?
Ans: Xen & KVM are two hypervisor available in linux.
Q:6: What is the difference between Xen & KVM ?
Ans: For Xen hypervisor first we have to install Xen kernel and have to boot the machine with Xen kernel where as KVM is kernel based Virtualization , we don’t need any extra kernel for KVM. KVM is a module in Kernel. Xen hypervisor by default doesn’t support full virtualization whereas KVM supports Full virtualization.
Q:7 What is Type-1 and Type-2 hypervisor ?
Ans: Type-1 hypervisor is bare metal hypervisor runs on bare metal of hardware. Hyper-V and ESXI Server are the examples of type-1 hypervisor. Type-2 hypervisor is hosted by operating system. Examples of type-2 hypervisor are Microsoft Virtual Server & VMware Server.
Q:8 What is Dom0 in Xen ?
Ans: Dom0 or Domain0 is the initial domain started by xen hypervisor. It has the special rights like to start new domain and access the hardware directly. Dom0 is responsible for running all of the device drivers for the hardware.
Q:9 How to verify Virtualization Technology (VT) is enabled in your server’s BIOS or not ?
Ans : grep -E ‘svm|vmx’ /proc/cpuinfo
- vmx is for Intel processors
- svm is for AMD processors
Q:10 What is the use of virsh command ?
Ans: virsh is the interface or command for managing the virtual machines based on KVM & Xen hypervisor. On virsh interface virtual machines are identified by their domain names , so virsh is generally used to list current domains , to create , pause & shutdown domains.
Q:11 How to identify the KVM version ?
Ans: To find the KVM version use the command ‘virsh version’
Q:12 Which command is used to list all virtual machine running on the KVM hypervisor ?
Ans: Using the command ‘virsh list –all’ we can list all virtual machines irrespective of their states.
Q:13 How to forcefully shutdown the KVM based virtual machine from the command line ?
Ans: We can forcefully shutdown the VM using the command ‘virsh destroy machine_name’.This command should only be used in a case where VM is in Hung state because forcefully shutdowm may cause filesystem corruption.
Q:14 What are the basic requirements of VM live migration in KVM ?
Ans: Some of the basic requirements are listed below :
- The guest image or virtual machine image must be located on a shared storage and it must be accessible using iSCSI, NFS, GFS2 or Fibre Channel.
- The shared storage must be mounted on the same path on both the hypervisors / hosts.
- Both hypervisors / hosts must run the same version of KVM.
- Both guests or VMs must have the same network configuration & bridging configuration (their IPs must be different)
Q:15 Which command is used in KVM for VMs live migration ?
Ans: ‘virsh migrate –live machine_name qemu+ssh://destination_server/system’
Q:16 What are the different states of a VM in Xen hypervisor ?
Ans: A VM can have different states like
- r – Running
- b – Blocked
- c – crashed
- s – Shutdown
- p – Paused
Q:17 How to get the console of guest or virtual machine in Xen ?
Ans: xm console <domain-id>
Q:18 How to shutdown,reboot & start VMs ( domain-ids) in Xen ?
Ans: Use xm command :
# xm shutdown [domain-id]
# xm reboot [domain-id]
# xm start [domain-id]
Q:19 How to get hardware information of KVM guest machine ?
Ans: Use the command ‘virsh dominfo <domain-name / VM Name>’
Q:20 How to connect a particular VM using virt-viewer ?
Ans: virt-viewer -c qemu:///system <VM_Name>