====== KVM Command Line ====== "virsh" shell for KVM. === List All Domain on KVM === virsh list --all === Define or use .xml === virsh define === Start KVM === virsh start === Edit Guest .xml === virsh edit xyz === List VNC Information === virsh vncdisplay xyz [[http://libvirt.org/formatdomain.html|Domain Format in KVM]] ==== Test your bootable USB on kvm ==== In order to test your USB using KVM use following command. qemu-kvm -hdb In my case device was "/dev/sdb". ==== Converting Existing Image ==== === Converting VMWARE image for KVM === use following command. qemu-img convert own_Cloud.vmdk -O qcow2 ownCloud.qcow === Converting .ova to KVM image === what is ova - Open Virtualization Format [[http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/ovf | Download - Open Virtualization Format Tool ]] Install it, which give you command "ovftool". ovftool -tt=vmx Amazon-EC2-VM-Import-Connector.ova amazon_kvm converting .ova is just easy\\ some times ovftool failing\\ If Above does not work just do

tar -xvf Amazon-EC2-VM-Import-Connector.ova

Now follow [[ #Converting VMWARE image for KVM | Converting VMWARE image for KVM ]] ==== Create New KVM Guest using existing Image ==== virt-install --name=own_cloud --arch=x86_64 \ --vcpus=1 --ram=512 --os-type=linux --os-variant=sles11 \ --hvm --connect=qemu:///system --network bridge:br0 \ --import --disk path=/home/vmware/ownCloud_in_a_box-1.0.4/ownCloud.qcow \ --accelerate --vnc --noautoconsole --keymap=us ==== Backup ==== === Creating snapshot of Machine === **NOTE :** \\ - This will turn off your Guest.\\ - it will create snapshot in current working directory.\\ - Use `virsh pwd` to check your current working directory. virsh save ==== Quick Command Ref. ==== help Prints basic help information. list Lists all guests. dumpxml Outputs the XML configuration file for the guest. create Creates a guest from an XML configuration file and starts the new guest. start Starts an inactive guest. destroy Forces a guest to stop. define Outputs an XML configuration file for a guest. domid Displays the guest's ID. domuuid Displays the guest's UUID. dominfo Displays guest information. domname Displays the guest's name. domstate Displays the state of a guest. quit Quits the interactive terminal. reboot Reboots a guest. restore Restores a previously saved guest stored in a file. resume Resumes a paused guest. save Save the present state of a guest to a file. shutdown Gracefully shuts down a guest. suspend Pauses a guest. undefine Deletes all files associated with a guest. migrate Migrates a guest to another host. setmem Sets the allocated memory for a guest. setmaxmem Sets maximum memory limit for the hypervisor. setvcpus Changes number of virtual CPUs assigned to a guest. vcpuinfo Displays virtual CPU information about a guest. vcpupin Controls the virtual CPU affinity of a guest. domblkstat Displays block device statistics for a running guest. domifstat Displays network interface statistics for a running guest. attach-device Attach a device to a guest, using a device definition in an XML file. attach-disk Attaches a new disk device to a guest. attach-interface Attaches a new network interface to a guest. detach-device Detach a device from a guest, takes the same kind of XML descriptions as command attach-device. detach-disk Detach a disk device from a guest. detach-interface Detach a network interface from a guest. ==== FU Commands ==== === Create Disk === create disk of size 10G qemu-img create -f raw vdisk.img 10G OR dd if=/dev/zero of=vdisk.img bs=1G count=0 seek=[NUMBER_OF_GB] ==== How to allow network access to KVM Guest ==== Modify guest.xml file and listen variable. ==== Extract folder from KVM Guest Image ==== This appears to be the far easy solution than I thought.\\ [[http://libguestfs.org/virt-copy-out.1.html|Link to official Document]] For RHEL you require the following packages installed. * libguestfs-tools * libguestfs-xfs # if guest filesystem is XFS. mkdir test virt-copy-out -a machine2.qcow2 /metadata/testing/users test/ ==== Image File explorer ==== This is a simple way to extract or access files.\\ Scan and assign the dev node. losetup --partscan --find --show sdcard.img List all the block devices, including newly scanned. lsblk --fs Mounting the file system mount /dev/loop0p2 /mnt/sdcard Once unmounted remove the lo drive. losetup --detach-all