Sie sind auf Seite 1von 4

Creating an image

The first step is to create an image that will hold the domU virtual disk. Since this can just be a raw zero-filled file, our usual friend dd becomes handy. In this howto we will put images in /srv/xen, although the semi-officially sanctioned location seems to be /var/lib/xen/images. If you would like to allocate disk blocks as the file grows, you can create a file with a hole. The following command will create a /srv/xen/mailserver.img file of 2048MB, although the actual data blocks are allocated in a lazy fashion:
# dd if=/dev/zero of=/srv/xen/mailserver.img oflag=direct bs=1M seek=2047 count=1

If you want to reserve all the data blocks right away, you can also do that:
# dd if=/dev/zero of=/srv/xen/mailserver.img oflag=direct bs=1M count=2048

###############################

Create a Xen image.


19/02/2009 by JuanLu Leave a Comment I have just created my first Xen image.
1. 2. 3. 4. 5. 6. Create a disk image (dd if=/dev/zero of=somefile.img bs=1 count=1 seek=8G) Format disk image (mkfs.ext2 somefile.img) Mount disk image (mount -o loop somefile.img looppoint) Copy your files (tar -zxSf yourtarballingzformat -C looppoint) Unmount your loop (umount loop) Create your swap file (if you want) (dd if=/dev/zero of=xen-swap.img bs=1M count=256) < no sparse file for this 7. Create your xen.conf file for that image.

xen.conf
name = myvm memory = 256 disk = [ 'tap:aio:/xen/myvm/somefile.img,sda1,w', 'tap:aio:/xen/myvm/xen-swap.img,sda2,w', ] root = /dev/sda1 ro vif = [ 'mac=00:16:3e:22:10:f8,bridge=eth0' ] on_reboot = restart on_crash = restart vcpus =2 kernel = /xen/centos_boot/vmlinuz-2.6.18-92.1.18.el5xen ramdisk = /xen/centos_boot/2.6.18-92.1.18.el5xen.img

You just need to change the kernel and ramdisk according to your host computer settings and play it. ##########################################3333

To address physical disk devices from the configuration file of a virtual machine, you need the following syntax in the disk definition:
phy:,,[r|w] For example: disk=[ 'phy:/dev/system/mainserver,xvda,w', 'phy:/dev/cdrom,xvdb,r', ]

Using Xen disk image files When installing a virtual machine on SUSE or Red Hat, by default Xen disk image files are used. This is an image file that is created using the dd utility, so basically there is nothing special to it. A dd disk image file doesn't compare to a file in the virtual hard disk (VHD) format, since there is no metadata associated to this type of disk image file; it's just ones and zeroes. To create a disk image file, you need the dd utility to copy zeroes from the /dev/zero device to your disk image file. For example, if you want to create a 4 GB file with the name /var/lib/xen/images/disk1, use the following command:
dd if=/dev/zero of=/var/lib/xen/images/disk1 bs=1M count=4096

Apart from creating empty image files using the dd utility, you can also use ISO files as an alternative for your physical optical drives. The usage is the same as the usage of a disk image file created with dd. Don't have an ISO file yet? Then we have good news for you; it's easy to create one. If the cd-rom of which you want to create an ISO file is in your optical drive, use the following to copy it to a file with the name cdrom.iso:
dd if=/dev/cdrom of=/isos/cdrom.iso

After creating either a disk image file or an ISO file, you need to include the disk image file in your virtual machine configuration using the file option in the disk definition:
disk=[ 'file:/var/lib/xen/images/disk1,hda,w', 'file:/isos/cdrom.iso,hdc,r', ]

Working with image files from other sources In some cases, you want to install a new virtual machine and create an image file to start with. In other situations you'll use with a disk image file from another virtualization environment. This can be a vmdk-file from a VMware environment, a qcow file from q Qemu environment or anything else. To work with these, you need the "tap" disk image. In the following line you see the syntax that you need to work with a vmdk-file from a VMware environment:
disk=[ 'tap:vmdk:/var/lib/xen/server1.vmdk,hda,w', ]

A special kind of tap device, is the Xen disk image file that uses the xen blktap kernel module. This module allows you to address a disk image file in a full virtualized environment as a para virtual device. To use this module, you need the aio device type. The disk image file itself can be an ordinary disk image file that is created with the dd command. The syntax to use in the configuration file for devices like that, would be as in the following:
disk=[ 'tap:aio:/var/lib/xen/server2.img,xvda,w', ]

The advantage of working with tap disk images is that you can use just any type of disk image. There is however also a disadvantage. In the current state management utilities such as virtual manager don't support tap devices. This means that you have to configure machine using this device manually. Network block devices The last disk type that you can use in a virtual machine, is the network disk type. This can be either a network block device such as a DRBD device, or an iSCSI device. This offers excellent possibilities to address a LUN on your iSCSI SAN directly, but do remember to start the iSCSI initiator in Domain0 first. This disk image type is not portable, that means that you need to take the appropriate precautionary measures on the SAN to protect this type of disk image file. Think for example of making SAN level snapshots to protect these. To make a connection to an iSCSI LUN, you need to include the complete iSCSI Qualifying Name (iqn) in the configuration file of your Xen virtual machine. For example, if the iqn you need to use is iqn.2007-08.nl.example:xendata, you would need the following configuration line:
disk=[ 'iscsi:2007-08.nl.example:xendata,xvda,w', ]

In this article, you have read about the different options that exist to address disk devices in virtual machines. Even if in most scenarios the file and phy devices are used, other device types offer useful possibilities as well, in special the tap device type that allows you to communicate to almost any disk image file. About the author: Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. Vugt is also a technical consultant for high-availability

(HA) clustering and performance optimization, as well as an expert on SLED 10 administration.

Das könnte Ihnen auch gefallen