分类: LINUX
2013-02-25 20:47:27
The Linux kernel has merged three hypervisors into its mainline tree, starting with in 2.6.20, and continuing with and in the 2.6.23 release of the kernel. Hypervisors let users run multiple operating systems on a host system. Lguest is the simplest of the three in terms of usability and implementation, which makes it a good candidate for helping you learn how virtualization works.
Lguest is still relatively new software, and lacks some of the advance features of other mature virtualization platforms for Linux. It comprises two main parts: a kernel module and a client launcher. You can virtualize only another Linux guest on top of the Linux host, using the lguest launcher, and both must be running the same kernel version. Lguest lacks support for X output from guest OSes, and lacks the VM migration facilities, which let you move your guest OS to another instance of the hypervisor on a different machine across a network. But despite such significant drawbacks, lguest does have its uses, such as checking your kernel under different configurations without actually rebooting the system.
With a small code base of around 6,000 lines of code, the project offers tremendous opportunity for new kernel hackers and virtualization machine monitor developers to learn about the workings of a simple hypervisor. Also, since lguest lacks features that other hypervisors already have, it offers low-hanging fruit in terms of functionality implementation for developers in order to get their code into the mainline kernel.
Recompile your kernel, boot with it, and if you chose "m" instead of "y" in any of the kernel configuration options, make sure you install the modules using make modules_install.
The launcher program lguest.c is located in the kernel source tree at Documentation/lguest/lguest.c, and is used to set and configure the guest kernels. Use make in this directory to build it.
Lguest can't boot up a bootable CD or DVD and let you install a complete Linux distribution along with its X Window environment. You must install a Linux distribution on another primary partition on a hard drive, or using QEMU, after which you can use lguest to launch multiple instances of the second distribution in a virtualized environment.
To launch the guest kernel, run the following command from the Documentation/lguest directory of the kernel source tree:
./lguest 64m ../../vmlinux --block=rootfile root=/dev/lgba
Here, 64m specifies the amount of memory to use for the guest. ../../vmlinux is the kernel image found in the top of the build directory. rootfile is the file or block device which should become /dev/lgba in the guest's environment. This should either be the image which was installed using QEMU, or a primary partition on which your guest Linux distribution is installed. Finally, /dev/lgba is passed as a boot parameter to the guest kernel, telling it to use /dev/lgba as the root device.
If all goes well, you will be greeted by getty to log in to your guest OS.
There is just one README file in the drivers/lguest/ directory. At the end of the README file is a hint for lguest hackers. If you pay attention to the last two lines in this file, you'll notice it says, "make Preparation!" and there is a make target for "Preparation." Running make Preparation in the directory gives you the documentation from within the lguest source files and dumps it to the output console. This documentation takes you from first steps to the deep down inner details of the working of lguest.
Lguest is not an appropriate virtualization platform for business or scientific needs yet. It has a long way to go in terms of features and support for multiple guest platforms. But it does provide an excellent opportunity to you to play with hypervisors; how they work, what makes them tick. You are even welcome to fork lguest and make it into a fully blown hypervisor of your own.
Lguest is a paravirtualization hypervisor, which means you have to modify the guest kernel in order to let it know that it is being run in a virtualized environment, so that it won't try to access the resources of the system in an unauthorized way.
To use lguest, make sure you have the following options enabled in both your host and guest kernel configuration. It is easiest to use the same kernel as host and guest.