Address: http://blog.csdn.net/ariesjzj/article/details/8570566
Xen, as a widely used virtual machine solution, plays a huge role in both industrial and educational fields. Xen not only has its proud Implementation of paravirtualization, but also hvm implementation based on hardware support. For xen, there is a ready-made solution in Ubuntu, as long as some apt-Get install (Ubuntu-xen-desktop, xen-hypervisor-4.1-amd64, xen-tools, xen-utils) commands can be silly installation. But in reality, for various reasons (for example, the source version is not new enough, or we have installed our own patches), we are still inclined to DIY.
The environment in this article is virtualbox 4.2.6 + xen 4.1.2 + Ubuntu 12.04 (64-bit ).
I. Compile and install xen
1. install some software before compiling xen
# Apt-Get install BCC bin86 gawk bridge-utils iproute libcurl3 libcurl4-openssl-dev Bzip2 module-init-tools transfig TGIF texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive- fonts-recommended pciutils-dev mercurial build-essential
Make GCC libc6-dev zlib1g-dev Python-dev Python-twisted libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg62-dev IASL libbz2-dev e2fslibs-dev Git-core UUID-dev ocaml-findlib libx11-dev libc6-xen gcc-multilib xz- utils
Note that some are not required. If xen 4.2 is compiled, run configure first to know what is missing.
2. Download the source code package of xen.org/download/index_4.1.2.html at http://xen.org/download/index_4.1.2.html, and install readmecompilation:
# Tar zxvf xen-4.1.2.tar.gz
# Cd xen-4.1.2
# Make World
# Make install
Use make DIST to deploy on another server.
The source code is downloaded from the Internet through git or Hg during compilation, so make sure that the network is connected (if it is through proxy Internet Reference http://blog.csdn.net/ariesjzj/article/details/8573872 ).
3. For xen management tools, the trend after xen 4.1 is that XL gradually replaces XM. Which one can be set in the configuration file:
/Etc/default/xen
Toolstack = "XM"
4. Set the startup Service
# Update-rc.d xencommons defaults 19 18
# Update-rc.d xend defaults 20 21
# Update-rc.d xendomains defaults 21 20
# Update-rc.d xen-watchdog defaults 22 23
And the startup module, add the following to/etc/modules:
Xen-evtchn
Xen-gntdev
Xen-netback
Xen-blkback
Xenfs
Blktap
5. Install xen-Tools
Download the source code xen-tools 4.3.1 from http://xen-tools.org/software/xen-tools/releases.html, decompress the package, and run:
# Make install
This tool includes xen-create-image and other tools, which makes it easier to create domu.
Ii. Compile and install dom0
1. The xen-oriented kernel source code mainly includes the Konrad and Jeremy versions. Of course, their changes will also be merge to the mainline of torvalad. The following uses the Jeremy version as an example:
$ Git clone git: // git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git linux-2.6-xen
$ Linux-2.6-xen CD
$ Git checkout-B xen/next-2.6.32 origin/xen/next-2.6.32
Compile and configure the kernel:
# Make oldconfig
# Make menuconfig
With the xen compilation option (refer to compiler), the following is the compilation and installation:
# Make
# Make modules_install
# Make install
By default, initrd. IMG is generated. If not, mkinitramfs will be used for manual generation.
2. Set grub
Assuming that the previously compiled image file is the vmlinuz-2.6.32.57 and initrd. img-2.6.32.57, add the following to/etc/grub. d/40_custom:
Menuentry "xen-Linux 2.6.32.57 "{
Insmod ext2
Set root = '(hd0, msdos1 )'
Multiboot/boot/xen.gz dummy = dummy
Module/boot/vmlinuz-2.6.32.57 dummy = dummy root = UUID = 323d1960-8f62-4bb4-9b92-81e7c835cb07 Ro dom0_mem = 512 M nomodeset
Module/boot/initrd. img-2.6.32.57
}
Note that the system generates/boot/GRUB/grub. cfg Based on the file in/etc/grub. d/, and/etc/default/grub is used to set its default options, timeout and other parameters.
Restart and press shift to bring up the GRUB menu. Select the newly added item and enter dom0.
Create domu.
3. Install domu
1. Create the logical volume of the guest
# Apt-Get install lvm2
Because LVM cannot create logical volumes on the partitions being used, first create a virtual disk in virtualbox (refer to the http://howtobi.wordpress.com/2010/10/30/adding-a-additional-hard-disk-in%C2%A0virtualbox ).
Enter the system again after setting. Assume that the newly added virtual disk is/dev/sdb. Generate a file system on it:
# Mkfs-T ext3/dev/SDB
Create physical volume and volumn group (named vg0 ):
# Pvcreate/dev/SDB
# Vgcreate vg0/dev/SDB
If you use xen-create-image, you do not need to manually use lvcreate to create a logical volumn.
If you want to create a new one, you can delete the original one:
# Lvremove/dev/vg0/xxxx
2. Install the domu kernel and generate the configuration file.
For example, create domu named mylucid, use the volumn group named vg0 just created, and use pygrub (domu uses a separate grub ):
# Xen-create-image -- hostname = mylucid -- Dist = lucid -- LVM = vg0 -- mirror = http://cn.archive.ubuntu.com/ubuntu -- Role = udev -- force -- verbose -- pygrub -- DHCP
Download from the network in the middle./etc/xen/mylucid. cfg is generated after the download is complete.
3. Set the network
It is not necessary to allow the system in the virtual machine to access the external network. Refer to the following Network Settings section:
Http://wiki.xen.org/wiki/Xen_Beginners_Guide#Creating_a_Debian_PV_.28Paravirtualized.29_Guest
Http://wiki.xen.org/wiki/Xen_Beginners_Guide
4. Start guest
# XM list, which appears similar:
Root @ jzj-LAPTOP:/home/jzj # XM list
Name ID mem vcpus state time (s)
Domain-0 0 1896 1 R ----- 97.6
Possible problems:
1) importerror: libxenctrl. so.4.0: cannot open shared object file: no such file or directory
In a 64-bit environment, the xen compiler generates libxenctrl. so.4.0, and put it in/usr/lib64. In order for the system to find it, you need to go to/etc/lD. so. conf. d/libc. add in Conf
/Usr/lib64
Then
# Ldconfig
2) Can't Find module xxxx
Many xen management tools are written in Python. In ubuntu,/usr/lib/python2.7/Site-packages are not put into the module search path by default. A simple method is to add
Export pythonpath =/usr/lib/python2.7/Site-packages
3) error: Unable to connect to xend: no such file or directory. Is xend running?
Try restarting xend:
# Xend restart
Of course, this problem may occur in many cases, such as incorrect versions or incorrect settings.
Now you can start Guest:
# XM create-F/etc/xen/mylucid. cfg-C
Use the password given by xen-create-image to log on to the root user.
CTRL +] You can exit the console and return to the available console:
# XM console mylucid
Disable Guest:
# XM shutdown mylucid