Installing Xen 3.3 With Kernel 2.6.27 On Ubuntu 8.10 (x86_64) - Page 3
4 Creating LVM-Based Virtual MachinesThis chapter explains how you can set up LVM-based virtual machines instead of virtual machines that use disk images. Virtual machines that use disk images are very slow and heavy on disk IO. In this example I'm using an Ubuntu 8.10 host with the LVM volume group /dev/vg0 that has about 465GB of space. /dev/vg0 contains two logical volumes, /dev/vg0/root and /dev/vg0/swap_1 that consume about 48GB of space - the rest is not allocated and can be used to create logical volumes for our virtual machines: vgdisplay root@server1:~# vgdisplay lvdisplay root@server1:~# lvdisplay We will use xen-tools to create virtual machines. xen-tools make it very easy to create virtual machines - please read this tutorial to learn more: http://www.howtoforge.com/xen_tools_xen_shell_argo. The xen-tools package got installed as a dependency when we installed the ubuntu-xen-server package, so we don't need to install it anymore. Now we edit /etc/xen-tools/xen-tools.conf. This file contains the default values that are used by the xen-create-image script unless you specify other values on the command line. I changed the following values and left the rest untouched: vi /etc/xen-tools/xen-tools.conf
In the kernel and initrd lines, we don't use our dom0 kernel that we built in the last chapter (2.6.27.5) because this kernel does not work in a domU. Please use one of the default Ubuntu kernels (take a look at the output of ls -l /boot ), e.g. 2.6.27-11-server! The default Ubuntu kernels are built to work in Xen guests, so there's no need to build a special domU kernel. Make sure that you uncomment the lvm line and fill in the name of your volume group (vg0 in my case). At the same time make sure that the dir line is commented out! dist specifies the distribution to be installed in the virtual machines (Debian Lenny) (there's a comment in the file that explains what distributions are currently supported). The passwd = 1 line makes that you can specify a root password when you create a new guest domain. In the mirror line specify a Debian mirror close to you. Make sure you specify a gateway, netmask, and broadcast address. If you don't, and you don't specify a gateway and netmask on the command line when using xen-create-image, your guest domains won't have networking even if you specified an IP address! It is very important that you add the line serial_device = hvc0 (not xvc0 or tty1!) because otherwise the console of your virtual machines might not work properly! Now let's create our first guest domain, xen1.example.com, with the IP address 192.168.0.101: xen-create-image --hostname=xen1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.101 --arch=amd64 --role=udev Options that you specify on the command line override the settings in /etc/xen-tools/xen-tools.conf. Options that are not specified on the command line are taken from /etc/xen-tools/xen-tools.conf. Please make sure that you add --role=udev, or your virtual machine might not boot properly! (To learn more about the available options, take a look at the xen-create-image man page: man xen-create-image ) The xen-create-image command will now create the xen1.example.com virtual machine for us. This can take a few minutes. The output should be similar to this one: root@server1:~# xen-create-image --hostname=xen1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.101 --arch=amd64 --role=udev As you see from the output, xen-create-image has created a new logical volume for our VM in the vg0 volume group, /dev/vg0/xen1.example.com-disk, for the VM's root filesystem. Take a look at lvdisplay and you will see that it has also created a second logical volume, /dev/vg0/xen1.example.com-swap, for the VM's swap: root@server1:~# lvdisplay There should now be a xen1.example.com configuration file - /etc/xen/xen1.example.com.cfg. Take a look at it to become familiar with virtual machine configuration files: vi /etc/xen/xen1.example.com.cfg
(If we had used disk images instead of logical volumes, the disk line would look similar to this one: disk = [ 'file:/path/to/xen1.example.com/disk.img,xvda1,w', 'file:/path/to/xen1.example.com/swap.img,xvda2,w' ] ) (Please note: if you have a dual-core or quad-core CPU and want the virtual machine to use all CPU cores, please add the line vcpus = '2' or vcpus = '4' to the configuration file.) Before we start the virtual machine for the first time, we must first mount its storage device and copy the domU kernel to it (the xen-create-image command copies the dom0 kernel 2.6.27.5 to the guest, but as I mentioned before, our domU kernel is different from the dom0 kernel (2.6.27-11-server in this example)): mount /dev/vg0/xen1.example.com-disk /mnt To start the virtual machine, run xm create /etc/xen/xen1.example.com.cfg Run xm console xen1.example.com to log in on that virtual machine (type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0), or use an SSH client to connect to it (192.168.0.101). To get a list of running virtual machines, type xm list The output should look like this: root@server1:~# xm list To shut down xen1.example.com, do this: xm shutdown xen1.example.com If you want xen1.example.com to start automatically at the next boot of the system, then do this: ln -s /etc/xen/xen1.example.com.cfg /etc/xen/auto Here are the most important Xen commands: xm create -c /path/to/config - Start a virtual machine. A list of all virtual machines that were created with the xen-create-image command is available under xen-list-images root@server1:~# xen-list-images To learn more about what you can do with xen-tools, take a look at this tutorial: http://www.howtoforge.com/xen_tools_xen_shell_argo
5 Links
|



Recent comments
13 hours 34 min ago
15 hours 10 min ago
19 hours 30 min ago
23 hours 21 min ago
1 day 11 hours ago
1 day 17 hours ago
1 day 19 hours ago
1 day 21 hours ago
1 day 21 hours ago
1 day 22 hours ago