Posts tagged “virt

LibVirt notes….

This blog posts contains shortcuts for creating VM’s in libvirt. I use these commands all the time and constantly find my sell referring to these notes, so I thought I would post them here for everyone else to use as well. To give credit where credit is due alot of this comes from Rhys Oxenham, Thanks Rhys!!

Step one get an image….
https://www.rdoproject.org/resources/image-resources/

I usually download it to /var/lib/libvirt/images, the default location for libvirt, however you can stick it anywhere. For this example I used the latest (of this writing) rhel7 image form Red Hat.

Make sure the libvirt tools are installed
# dnf install libvirt qemu-kvm virt-manager virt-install libguestfs-tools libguestfs-xfs net-tools -y

I usually rename it something more manageable…
# mv rhel-guest-image-7.0-20140930.0.x86_64.qcow2 rhel7-guest-official.qcow2

Check the details of the image you downloaded:
# qemu-img info rhel7-guest-official.qcow2

Check the details of the image file system:
# virt-filesystems --long -h --all -a rhel7-guest-official.qcow2

Create new image, no data:
# qemu-img create -f qcow2 rhel7-guest.qcow2 40G

Re-size off official to new:
# virt-resize --expand /dev/sda1 rhel7-guest-official.qcow2 rhel7-guest.qcow2

Check that both the partition and the filesystem have been correctly resized
# virt-df -a rhel7-guest.qcow2

Turn this guest image into a backing file so we can use copy on write functionality to be space efficient with our new virtual machine:
# qemu-img create -f qcow2 -b rhel7-guest.qcow2 test-vm.qcow2

set the root password:
# virt-customize -a test-vm.qcow2 --root-password password:test

boot the machine:
# virt-install --ram 16384 --vcpus 4 --os-variant rhel7 \
--disk path=/var/lib/libvirt/images/test-vm.qcow2,device=disk,bus=virtio,format=qcow2 \
--import --noautoconsole --vnc \
--network network:default --name test

** if you want to connect to a bridge

  –network bridge=br-prov –network bridge=br-ext

Check that its running:
# virsh list --all

use arp to find out the IP that it has been allocated:
# VM_IP=$(arp | awk ' /virbr0/ {print $1}')
# echo $VM_IP

creating a passwordless SSH keypair:
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@$VM_IP

connect to VM
# ssh root@$VM_IP

Take a snapshot:
# virsh snapshot-create-as test test-snap-1

list all snapshots:
# virsh snapshot-list

If you ever need to restore VM you can execute the following command:
# virsh snapshot-revert --domain test

Advertisements

guestfish in 3 simple steps

libguestfs is a very handy library for manipulating image files. guestfis is a utility that uses libguestfs that allows you to mount an image file and make changes inside the image. One of the coolest features of libguestfs is that it does not require root prevelages to run or access an image file. The below example shows how to use guest fish to mount an make a change to a machine image.

1) install guestfish

# yum install guestfish

2) connect to the  image

guestfish –rw -a ~/Downloads/rhel-server-x86_64-kvm-6.4_20130130.0-4.qcow2

3) edit image

><fs> run
><fs> list-filesystems
><fs> mount /dev/vda1 /
><fs> vi /etc/fstab
 make any changes you need to
 ><fs> umount /
><fs> exit
 

Additional info:

Download machine images:

http://openstack.redhat.com/Image_resources

Documentation

http://libguestfs.org/guestfish.1.html


How to clean a LUN

RHEV 3.0 and earlier requires a clan LUN to create a new storage domain.  This is done intentionally so you do not overwrite existing data. However if you want to force RHEV to use a LUN with existing data you can wipe out the first 512 bytes of the lun to fool RHEV in to thinking the LUN is empty.

basically there are two steps………

1. Find the path to the LUN

Run the command “multipath -ll” on a host to see whether it “sees” the SAN luns or not, the output will look something like this if it “sees” the LUN:

mpath1 (3600d0230003228bc000339414edb8101) [size=100 GB][features=”0″][hwhandler=”0″]
\_ round-robin 0 [prio=1][active]
\_ 2:0:0:6 sdb 8:16 [active][ready]
\_ round-robin 0 [prio=1][enabled]
\_ 3:0:0:6 sdc 8:64 [active][ready]

If you do not see the LUN in the multipath output it means that the host can not access the LUN, ie its not presented correctly to the host. Check you SAN ACLS.  If you are using ISCSI  make sure you are logged in. see my post on ISCSI notes for more info.

2. “Clean” the LUN.  The LUN must be empty to add to the RHEV-M. You can use “dd” to wipe out the first 512 bytes of the lun to fool RHEV in to thinking the LUN is empty.

dd if=/dev/zero of=/dev/path/to/LUN bs=1024k count=10

doc:https://access.redhat.com/discussion/after-re-installation-rhev-lun-not-visible-rhevm-gui


Spice qxl drivers guest

To configure a virtual guest to use the qxl drivers for Video when using Spice create the file “/etc/X11/xorg.conf.d/01-qxl.conf” and add the following lines”

 Section "Device"
    Identifier "Viedocard0"
    Driver     "qxl"
EndSection

how-to Create Virtual Bridge

This is kinda old, but pretty helpful. I find myself referring to these notes often so I thought I would share

1. Create Virtual Bridge
# brctl addbr br0

verify with: brctl show

2. Create network script, edit /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes

3. Edit eth0 network script add…

BRIDGE=br0
4. Add your physical interface to the bridge
# brctl addif br0 eth0

verify with: brctl show

5. Restart your network services
# service network restart

References:

http://www.linux-kvm.com/content/using-bridged-networking-virt-manager

http://www.linux-kvm.com/content/tip-how-get-maximum-network-performance-using-paravirtual-drivers-and-bridged-networking