全部博文(163)
分类: LINUX
2009-06-15 15:06:48
Scientific Linux 5.0 has a couple of very nice RHEL tools that make the process of creating Xen disk images very easy. The "Virtual Machine Manager" application (virt-manager is the package name) is a desktop user interface for creating and managing virtual machines. The "Virt Install" tool (virtinst is the package name) is a command line tool that provides an easy way to create virtual machines.
The following instructions have been paraphrased from this with a couple of additions.
1. Go to Applications-->System Tools-->Virtual Machine Manager.
2. When the Virtual Machine Manager main window appears, go to File-->New machine.
3. Click Forward.
4. Enter name of Xen guest, eg. xen_guest
and click Forward.
5. Enter location of install media; eg.
ftp://ugdev09.phys.uvic.ca/scientific/45/i386
6. Install to either a physical disk partition or to a virtual file system within a file. We have been using the latter option; eg. /images/xen_guest.img. Specify size of the virtual disk and click Forward.
7. Specify memory to allocate to guest and number of virtual CPUs and click Forward.
8. Click Forward to open console and install should begin. This may take a bit to start.
9. Complete installation in the window provided.
NB. When it come time for defining the partition table if you use LVM (which will be the case if you use the default option) and are doing the install in graphics mode I would encourage you to change the name of the Volume Group to something other than the default. Only because if you want to later access the data on the image without booting it (as explained below) you will need to activate the disk image Volume Group. If the physical machine you are working on also has been installed using the default partition table then you may have two Volume Groups with the same name. Oops.
10. Then to boot the image use xm create -c xen_guest
.
I would suggest downloading the latest release of the virtinst package from the . The version included up until SL5.2 is quite old. This package contains several useful command line tools.
dd if=/dev/zero of=/images/tomcat_server1 bs=1024k count=10000
virt-install --paravirt --nographics --name=tomcat_server1 --ram=512 --vcpus=1 --file=/images/tomcat_server1.img --file-size=10000 --location=ftp://ugdev09.phys.uvic.ca/scientific/50/i386/
build a 10G sparse file
dd if=/dev/zero of=benchmarkVM_sl52_x86_64_0.img bs=1 count=1 seek=10G
virt-clone --original benchmarkVM_sl52_0 --file /images/benchmarkVM_sl52_7.img --name benchmarkVM_sl52_7 /images/benchmarkVM_sl52_0.imgThis tool will handle generating a new random MAC address and UUID and copying the disk image.
Most of this is covered at . First find an available loop device
losetup -f
and associate the image file with a loop device
losetup /dev/loop# /path/to/disk_image.img
.
Next create a device map from the partition table
kpartx -av /dev/loop#
To access just the /boot/ directory on the image
mount -o loop /dev/mapper/loop#p1 /mnt
Otherwise, scan for volume groups
vgscan
Now activate the logical volumes in the volume group from the
disk image. Make sure you can distinguish from the image volume group
and the dom0 volume group if lvm was used to partition dom0.
vgchange -ay Disk_Image_VolGroup
Find which logical volumes are active in Disk_Image_VolGroup
lvs
and mount the relevant logical volume
mount /dev/Disk_Image_VolGroup/LogVol## /mnt
Now you can access the data on the image. Remember to unmount the image, deactivate the logical volumes, remove the partitions and delete the loop device when you are done.
umount /mnt
vgchange -an Disk_Image_VolGroup
kpartx -d /dev/loop#
losetup -d /dev/loop#