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
Taste of Training, Summit 2015
This year, I had a chance to help out with the training labs at Red Hat Summit, something I had never done before. As a solutions architect, Its always good to interact with customers and see our products in action. The learning labs were a lot of fun and a resounding success.
RHEL7 notes
Below are some helpful tips when working with RHEL7. They are not always recommended however sometimes helpful, especially when new to RHEL7…..
Disable dynamic network interface naming:
# vim /etc/default/grub
add the following to GRUB_CMDLINE_LINUX line
“biosdevname=0 net.ifnames=0”
# grub2-mkconfig –output=/boot/grub2/grub.cfg
reboot
Set Hostname:
# hostnamectl set-hostname “hostname”
Disable network manager and firewalld:
# systemctl stop NetworkManager
# systemctl disable NetworkManager
# systemctl stop firewalld
# systemctl disable firewalld
Register with subscription-manager:
# subscription-manager list –available
# subscription-manager attach –pool=
# subscription-manager repos –list
# subscription-manager repos –disable=*
# subscription-manager repos –enable <repo-name>
# subscription-manager repos –enable=rhel-7-server-rpms –enable=rhel-7-server-extras-rpms
HUFFISLAND back up
After being down for a bout a year we are back up and running. I have imported some old tech post and have more to come, stay tuned…..
Hello world!
sup