To test some problems usually I have to have two machines which is not easy to have. Especially if I have to configure it for each version, RHEL4, RHEL5, Fedora, etc.
Virtualzation comes here to solve those kinds of difficulty. But, just installing new operating system each time is also not a perfect solution. You should wait couple of hours before you can do test something. It’s also applied even though you already have that operating system because you need fresh system. Most easiest way is to use LVM’s snapshot feature.
Here are the steps I did to build my own test environment.
To use snapshot feature, you should make LVM partition first. There are many useful documentations for this steps. Easiest way to make room for virtual image is using ‘system-config-lvm’ if you use Fedora or RHEL. With GUI, you can resize the existing volume and make new volume on the free space. This new volume will be the space for the original operating system.
If you preper command line tools, you can use ‘lvreduce’ for reducing exsiting filesystem’s size and ‘lvcreate’ for creating new logical volume.
In my case, I created logical volume for RHEL5U4 with name rhel5u4. Following is the output from ‘lvdisplay’ command.
--- Logical volume --- LV Name /dev/VolGroup/rhel5u4 VG Name VolGroup LV UUID kkk383-IDE3-Lzh1-tKm4-a3YT-3k23-EIKFD5E LV Write Access read/write LV Status available # open 0 LV Size 20.00 GB Current LE 5120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
Create new virtual system with this volume. ‘virt-manager’ is a good tool to this. I’ll not describe how to install new operating system with ‘virt-manager’.
After installing new operating system and configured everything that will be necessary to work basically, you also need to edit ‘/etc/hosts’ file in this operating system if you want to make two different virtual machine easily communicate. I did it as following for my test environment.
192.168.122.100 station1.example.com station1 192.168.122.101 station2.example.com station2
If you want have more than two systems, you also add more lines with new IP address. I decided to use internal IP addresses but if you want the systems accessible from the outside, you should build bridge network first. I’ll not describe it here. After add above lines in to the ‘etc/hosts’ you need to shutdown the virtual machine and you will not use it until you want to install something common between each virtual machine.
It is time to create new volume for each virtual machine. I made simple script for this.
#!/bin/bash if [ /dev/VolGroup/rhel5u4_test1 ] then lvremove /dev/VolGroup/rhel5u4_test1 fi lvcreate --size 1g --snapshot --name rhel5u4_test1 /dev/VolGroup/rhel5u4 if [ /dev/VolGroup/rhel5u4_test2 ] then lvremove /dev/VolGroup/rhel5u4_test2 fi lvcreate --size 1g --snapshot --name rhel5u4_test2 /dev/VolGroup/rhel5u4
It will remove exsiting volume and will create new volume as a snapshot based on existing rhel5u4 volume with 1G of space for modification.
As a last step, you should fix IP address for each machine. If you do not, you can’t reach each machine with their name and always have to recheck current IP address for testing. Some documents says that it is necessary to restart dnsmasq because virtual machine get address from dnsmasq, but it it not true. Only thing you should have to do is stay on ‘virsh’ command.
Basic steps are as something like following.
1. cd /etc/libvirt/qemu/networks/
2. vi default.xml
3. virsh net-destroy default
4. virsh net-define default.xml
5. virsh net-start default
At the second step, you should add each virtual machine’s MAC address with desired IP address. As a result, mine is something like this.
You don’t need to restart dnsmasq or libvirtd at all. Just update this configuration file and restart each virtual machine is the enough step. From now, you have configured two systems and at any time you can restart with recreate snapshot.
Leave a Reply