Virtualization With KVM On A Debian Squeeze Server
|
Submitted by falko (Contact Author) (Forums) on Thu, 2011-03-10 18:01. :: Debian | KVM | Virtualization
Virtualization With KVM On A Debian Squeeze ServerVersion 1.0 This guide explains how you can install and use KVM for creating and running virtual machines on a Debian Squeeze server. I will show how to create image-based virtual machines and also virtual machines that use a logical volume (LVM). KVM is short for Kernel-based Virtual Machine and makes use of hardware virtualization, i.e., you need a CPU that supports hardware virtualization, e.g. Intel VT or AMD-V. I do not issue any guarantee that this will work for you!
1 Preliminary NoteI'm using a machine with the hostname server1.example.com and the IP address 192.168.0.100 here as my KVM host. We also need a desktop system where we install virt-manager so that we can connect to the graphical console of the virtual machines that we install. I'm using an Ubuntu 10.10 desktop here.
2 Installing KVMDebian Squeeze KVM Host: First check if your CPU supports hardware virtualization - if this is the case, the command egrep '(vmx|svm)' --color=always /proc/cpuinfo should display something, e.g. like this: root@server1:~# egrep '(vmx|svm)' --color=always /proc/cpuinfo If nothing is displayed, then your processor doesn't support hardware virtualization, and you must stop here. To install KVM and virtinst (a tool to create virtual machines), we run apt-get install kvm qemu-kvm libvirt-bin virtinst Afterwards we must add the user as which we're currently logged in (root) to the groups libvirt and kvm: adduser `id -un` libvirt You need to log out and log back in for the new group membership to take effect. To check if KVM has successfully been installed, run virsh -c qemu:///system list It should display something like this: root@server1:~# virsh -c qemu:///system list If it displays an error instead, then something went wrong. Next we need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network. To do this, we install the package bridge-utils... apt-get install bridge-utils ... and configure a bridge. Open /etc/network/interfaces: vi /etc/network/interfaces Before the modification, my file looks as follows:
I change it so that it looks like this:
(Make sure you use the correct settings for your network!) Restart the network... /etc/init.d/networking restart ... and run ifconfig It should now show the network bridge (br0): root@server1:~# ifconfig
3 Installing virt-viewer Or virt-manager On Your Ubuntu 10.10 DesktopUbuntu 10.10 Desktop: We need a means of connecting to the graphical console of our guests - we can use virt-manager (see KVM Guest Management With Virt-Manager On Ubuntu 8.10) for this. I'm assuming that you're using an Ubuntu 10.10 desktop. Run sudo apt-get install virt-manager to install virt-manager.
4 Creating A Debian Squeeze Guest (Image-Based) From The Command LineDebian Squeeze KVM Host: Now let's go back to our Debian Squeeze KVM host. Take a look at man virt-install to learn how to use it. We will create our image-based virtual machines in the directory /var/lib/libvirt/images/ which was created automatically when we installed KVM in chapter two. To create a Debian Squeeze guest (in bridging mode) with the name vm10, 512MB of RAM, two virtual CPUs, and the disk image /var/lib/libvirt/images/vm10.img (with a size of 12GB), insert the Debian Squeeze Netinstall CD into the CD drive and run virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /dev/cdrom --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm Of course, you can also create an ISO image of the Debian Squeeze Netinstall CD (please create it in the /var/lib/libvirt/images/ directory because later on I will show how to create virtual machines through virt-manager from your Ubuntu desktop, and virt-manager will look for ISO images in the /var/lib/libvirt/images/ directory)... dd if=/dev/cdrom of=/var/lib/libvirt/images/debian-6.0.0-amd64-netinst.iso ... and use the ISO image in the virt-install command: virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.0-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm The output is as follows: root@server1:~# virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.0-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm
|




Recent comments
20 hours 16 min ago
20 hours 26 min ago
21 hours 13 min ago
22 hours 54 min ago
1 day 11 hours ago
1 day 13 hours ago
1 day 20 hours ago
2 days 6 hours ago
2 days 11 hours ago
2 days 13 hours ago