Guest machine: CentOS 6.2, 64-bit
This is a quick run through of the commands and steps necessary for the setup to work on a headless (no GUI) machine. But even so, we will use a remote VNC client to access the server to setup and configure the guest machine.
I assume that
- virtualization is enabled in the BIOS of the host machine (important!)
- root privileges is available
- the base system is up and running somewhere remotely and can be accessed via SSH
- opening a port on the firewall(s) to allow access to the VNC server on the host machine.
- a copy of "CentOS-6.2-x86_64-minimal.iso" or similar has been downloaded and placed on the host machine at "/var/lib/libvirt/images"
- selinux is configured in "enforcing" mode.
- your host machine has sufficient resources to run your guests (remember to live enough ram for your host server)
- the person trying this is not a newbie system administrator. If your remote box do go down, ensure you are able to reboot it (physically or by calling the data center staff).
1. Install the tools required
yum install kvm libvirt python-virtinst
You will also require the dmidecode package if you are using the minimal edition of CentOS 6.2.
yum install dmidecode
(noticed that this was missing by observing /var/log/libvirt/libvirtd.log)
2. Check that kvm is installed
lsmod | grep kvm
The above command should output 2 entries, for example "kvm_intel" or "kvm_amd" and "kvm"
3. Create a secure location for your live images
Assuming we are creating /vm which is only accessible by root.
Selinux only allows libvirt to store images in /var/lib/libvirt/images but we don't want to mix the ISO images with live/running virtual guests.
yum install policycoreutils-python
semanage fcontext -a -t virt_image_t "/vm(./*)?"
restorecon -R /vm
If you can't do this, you can always host your guest images next to your ISO files in /var/lib/libvirt/images.
4. Network reconfiguration
We will need to create a bridged network that will route the host and guest network traffic seamlessly. This step can be skipped if the guest machines do not require network access.
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0
Edit /etc/sysconfig/network-scripts/ifcfg-eth0 to something like the following:
HWADDR=00:1D:09:EF:F7:04 (make sure this corresponds to your actual MAC address)
BRIDGE=br0 (important! make sure this entry goes in)
IPV6INIT=no (prevent IPv6 from starting)
If it works, you know you will be able to reboot your machine remotely as many times as you like because it works. Better to fail now than to fail when you have multiple live guests running and you need to do some maintenance. :P
9. Start your vnc (ultravnc or tightvnc viewer)
connect to the IP:Port on the host machine
in our example 192.168.1.11:7601
You will see the familiar but customized (minimal edition) CentOS installer. If you are fast enough, you might even be able to catch the bootup screen. Please note that the VNC server for this guest OS does not start until you perform the virt-install command. You can check this by looking for the process listening on port 3764. Perform a "netstat -pant | grep 7601" and you should see something like
tcp 0 0 0.0.0.0:7601 0.0.0.0:* LISTEN 3109/qemu-kvm
10. Start it up again, for real
Once done, it will not reboot even though you click on the "reboot" button. You will need to start it up manually.
virsh start myguest
You can do a "virsh list" to look at the status of your guest machines.
Reconnect your vnc client to see if there are errors in the booting up process.
Can you login via the VNC client to the root account which you defined during the installation process? If ok, then you can kill the VNC client.
Remember to disable the firewall rule for TCP port 7601 or whichever port you have chosen.
Patch / update the software on your base guest image, you might want use it as a base for cloning more guest OS, thus saving you lots and lots of time.
Hope this helps.