个人工具

“UbuntuHelp:Xen”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/Xen}} {{Languages|UbuntuHelp:Xen}} == Introduction == Xen is a virtual machine for linux that allows you to run multiple operating systems on a...)
 
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/Xen}}
 
{{From|https://help.ubuntu.com/community/Xen}}
 
{{Languages|UbuntuHelp:Xen}}
 
{{Languages|UbuntuHelp:Xen}}
 
 
 
== Introduction ==
 
== Introduction ==
 
 
Xen is a virtual machine for linux that allows you to run multiple operating systems on a single hardware machine.
 
Xen is a virtual machine for linux that allows you to run multiple operating systems on a single hardware machine.
 
 
=== Terms ===
 
=== Terms ===
 
* Dom0: The host machine OS, also called host. You know, the OS of the actual physical server that you have.
 
* Dom0: The host machine OS, also called host. You know, the OS of the actual physical server that you have.
 
* DomU: A Xen guest domain, also called guest. A DomU is a single Xen virtual machine. The “U” stands for “unprivileged”.
 
* DomU: A Xen guest domain, also called guest. A DomU is a single Xen virtual machine. The “U” stands for “unprivileged”.
 
* HVM: HVM is a way of running Windows in Xen.
 
* HVM: HVM is a way of running Windows in Xen.
 
 
Note: This guide is written for Feisty. It will be updated for Gutsy. Older versions are not really a concern, but if you really want to, please merge older information in here cleanly.
 
Note: This guide is written for Feisty. It will be updated for Gutsy. Older versions are not really a concern, but if you really want to, please merge older information in here cleanly.
 
 
Note: If you just want to run a virtual instance of windows, it is recommended to try [[UbuntuHelp:KVM]] or [http://www.virtualbox.org VirtualBox] instead.
 
Note: If you just want to run a virtual instance of windows, it is recommended to try [[UbuntuHelp:KVM]] or [http://www.virtualbox.org VirtualBox] instead.
 
 
There is a developing ubuntu-xen irc community on #ubuntu-xen at freenode.
 
There is a developing ubuntu-xen irc community on #ubuntu-xen at freenode.
 
 
For development information with the ubuntu xen community, see https://wiki.ubuntu.com/Xen
 
For development information with the ubuntu xen community, see https://wiki.ubuntu.com/Xen
 
 
== Installation ==
 
== Installation ==
 
 
=== Install from packages (recommended) ===
 
=== Install from packages (recommended) ===
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo aptitude install ubuntu-xen-server
 
sudo aptitude install ubuntu-xen-server
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Note: There is also a ubuntu-xen-desktop, and a ubuntu-xen-desktop-amd64. The purpose of these is a bit ambiguous, but they install firefox and all kinds of gnome libs. They may also not be PAE enabled... compiled for systems with more then 4GB of RAM. Even if you are on a 64 bit system, you should still install ubuntu-xen-server.
 
Note: There is also a ubuntu-xen-desktop, and a ubuntu-xen-desktop-amd64. The purpose of these is a bit ambiguous, but they install firefox and all kinds of gnome libs. They may also not be PAE enabled... compiled for systems with more then 4GB of RAM. Even if you are on a 64 bit system, you should still install ubuntu-xen-server.
 
 
More package details here: http://packages.ubuntu.com/feisty/base/ubuntu-xen-server
 
More package details here: http://packages.ubuntu.com/feisty/base/ubuntu-xen-server
 
 
The AMD64 version of ubuntu doesn't have a ubuntu-xen-server metapackage so far. Instead, use this.
 
The AMD64 version of ubuntu doesn't have a ubuntu-xen-server metapackage so far. Instead, use this.
 
 
For Feisty:
 
For Feisty:
 
<pre><nowiki>
 
<pre><nowiki>
第42行: 第27行:
 
sudo aptitude install linux-image-xen bridge-utils libxen3.1 python-xen-3.1 xen-docs-3.1 xen-hypervisor-3.1 xen-ioemu-3.1 xen-tools xen-utils-3.1
 
sudo aptitude install linux-image-xen bridge-utils libxen3.1 python-xen-3.1 xen-docs-3.1 xen-hypervisor-3.1 xen-ioemu-3.1 xen-tools xen-utils-3.1
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Maybe install xenman too, but it installs all kinds of gnome stuff.
 
Maybe install xenman too, but it installs all kinds of gnome stuff.
 
 
Next you need to enable networking. [Gutsy: I had to reboot the xen kernel before I could run the xend script]
 
Next you need to enable networking. [Gutsy: I had to reboot the xen kernel before I could run the xend script]
 
<pre><nowiki>
 
<pre><nowiki>
 
vim /etc/xen/xend-config.sxp
 
vim /etc/xen/xend-config.sxp
 
 
#(network-script network-dummy)
 
#(network-script network-dummy)
 
(network-script network-bridge)
 
(network-script network-bridge)
 
 
then
 
then
 
sudo /etc/init.d/xend restart  # for the change to take effect
 
sudo /etc/init.d/xend restart  # for the change to take effect
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
 
Its also a good idea to increase the default number of loop mounts allowed. Not really needed if you are going to use LVM, but it also wont break anything if you do it anyways.
 
Its also a good idea to increase the default number of loop mounts allowed. Not really needed if you are going to use LVM, but it also wont break anything if you do it anyways.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
vim /etc/modules
 
vim /etc/modules
 
 
loop max_loop=64
 
loop max_loop=64
 
</nowiki></pre>
 
</nowiki></pre>
 
 
This is probably a good point to reboot your machine so that you use the xen kernel.
 
This is probably a good point to reboot your machine so that you use the xen kernel.
 
 
After reboot is a good chance to check your network and ensure it works.  Both Feisty and Gutsy may have network problems with certain hardware.  If you are experiencing network problems, check out [http://ubuntuforums.org/showthread.php?t=535309 this] potential solution
 
After reboot is a good chance to check your network and ensure it works.  Both Feisty and Gutsy may have network problems with certain hardware.  If you are experiencing network problems, check out [http://ubuntuforums.org/showthread.php?t=535309 this] potential solution
 
 
==== ACPI ====
 
==== ACPI ====
 
 
If - after reboot - you see a kernel oops in dmesg or suggestion to boot with irqpoll, then try disabling ACPI and Plug 'n Play OS options in your BIOS. If you have no access to these options from the BIOS, then you may need to boot your kernel with acpi=off option. The reason is that there is no ACPI in the Xen kernel. Edit /boot/grub/menu.list and find a module line:
 
If - after reboot - you see a kernel oops in dmesg or suggestion to boot with irqpoll, then try disabling ACPI and Plug 'n Play OS options in your BIOS. If you have no access to these options from the BIOS, then you may need to boot your kernel with acpi=off option. The reason is that there is no ACPI in the Xen kernel. Edit /boot/grub/menu.list and find a module line:
 
<pre><nowiki>
 
<pre><nowiki>
第80行: 第52行:
 
module          /boot/initrd.img-2.6.22-14-xen
 
module          /boot/initrd.img-2.6.22-14-xen
 
</nowiki></pre>
 
</nowiki></pre>
 
 
change the one module line with options above to:
 
change the one module line with options above to:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
module          /boot/vmlinuz-2.6.22-14-xen root=UUID=your-uuid-here ro console=tty0 acpi=off
 
module          /boot/vmlinuz-2.6.22-14-xen root=UUID=your-uuid-here ro console=tty0 acpi=off
 
</nowiki></pre>
 
</nowiki></pre>
 
 
==== Initrd ====
 
==== Initrd ====
 
 
Most people can skip this section. This is just in case you get a kernel panic at reboot, then you probably have SCSI or SATA modules that need to be included in an initrd. Do this to create an initrd:
 
Most people can skip this section. This is just in case you get a kernel panic at reboot, then you probably have SCSI or SATA modules that need to be included in an initrd. Do this to create an initrd:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo depmod -a xen-3.0-i386.gz
 
sudo depmod -a xen-3.0-i386.gz
 
sudo mkinitramfs -o /boot/xen-3.0-i386.initrd.img 2.6.19-4-generic
 
sudo mkinitramfs -o /boot/xen-3.0-i386.initrd.img 2.6.19-4-generic
 
</nowiki></pre>
 
</nowiki></pre>
 
 
And then add this as a second module line in the Xen section of your menu.lst file.
 
And then add this as a second module line in the Xen section of your menu.lst file.
 
<pre><nowiki>
 
<pre><nowiki>
 
module      /boot/xen-3.0-i386.initrd.img
 
module      /boot/xen-3.0-i386.initrd.img
 
</nowiki></pre>
 
</nowiki></pre>
 
 
This recommendation might be wrong. Please correct it if so. See [http://wiki.xensource.com/xenwiki/InstallationNotes?highlight=%28grub%29 here] and [http://wiki.xensource.com/xenwiki/GettingStarted?highlight=%28initrd%29 and here] for more details.
 
This recommendation might be wrong. Please correct it if so. See [http://wiki.xensource.com/xenwiki/InstallationNotes?highlight=%28grub%29 here] and [http://wiki.xensource.com/xenwiki/GettingStarted?highlight=%28initrd%29 and here] for more details.
 
 
 
=== Prebuilt Binaries install ===
 
=== Prebuilt Binaries install ===
 
 
This section has not yet been written.
 
This section has not yet been written.
 
 
http://xen.xensource.com/download/dl_31tarballs.html
 
http://xen.xensource.com/download/dl_31tarballs.html
 
 
http://www.howtoforge.com/xen_3.0_ubuntu_dapper_drake
 
http://www.howtoforge.com/xen_3.0_ubuntu_dapper_drake
 
 
 
== Guest Templates ==
 
== Guest Templates ==
 
 
 
=== LVM partitioning ===
 
=== LVM partitioning ===
 
 
xen-tools can create lvm volumes for you, so you can skip this section. If you need to make lvm volumes yourself you can use these commands. I just used the ubuntu installer to setup my LVM volume group initially. If you are using local .img files for your xen guests, then you dont need lvm.
 
xen-tools can create lvm volumes for you, so you can skip this section. If you need to make lvm volumes yourself you can use these commands. I just used the ubuntu installer to setup my LVM volume group initially. If you are using local .img files for your xen guests, then you dont need lvm.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo lvdisplay                        # To see existing lvm volumes.
 
sudo lvdisplay                        # To see existing lvm volumes.
第125行: 第79行:
 
lvcreate -n myguest-swap -L +4G  my_volume_group    # To create another volume
 
lvcreate -n myguest-swap -L +4G  my_volume_group    # To create another volume
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Using loopback-mounted-file ===
 
=== Using loopback-mounted-file ===
 
 
<pre><nowiki>
 
<pre><nowiki>
 
dd if=/dev/zero of=/home/xen/guest_base.img bs=1024k seek=1000 count=0
 
dd if=/dev/zero of=/home/xen/guest_base.img bs=1024k seek=1000 count=0
 
dd if=/dev/zero of=/home/xen/guest_base-swap.img bs=1024k seek=500 count=0
 
dd if=/dev/zero of=/home/xen/guest_base-swap.img bs=1024k seek=500 count=0
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
=== DomU using xen-tools (recommended) ===
 
=== DomU using xen-tools (recommended) ===
 
 
First you need to edit some of the default values in xen-tools.conf . Go through the file and set them to what you want. I've mentioned the more important ones below. Make sure you set a gateway and netmask or networking wont work.
 
First you need to edit some of the default values in xen-tools.conf . Go through the file and set them to what you want. I've mentioned the more important ones below. Make sure you set a gateway and netmask or networking wont work.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# vim /etc/xen-tools/xen-tools.conf
 
# vim /etc/xen-tools/xen-tools.conf
 
 
gateway  = 192.168.0.1
 
gateway  = 192.168.0.1
 
netmask  = 255.255.255.0
 
netmask  = 255.255.255.0
第148行: 第95行:
 
mirror = http://archive.ubuntu.com/ubuntu/
 
mirror = http://archive.ubuntu.com/ubuntu/
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Create a new image.
 
Create a new image.
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo xen-create-image --hostname=xen1.example.com --ip=192.168.1.10 --ide --force
 
sudo xen-create-image --hostname=xen1.example.com --ip=192.168.1.10 --ide --force
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Someone said that if you don't use --ide, it wont work. So I took their advice.
 
Someone said that if you don't use --ide, it wont work. So I took their advice.
 
man xen-create-image says " --ide  Use IDE names for virtual devices (hda not sda)"
 
man xen-create-image says " --ide  Use IDE names for virtual devices (hda not sda)"
 
 
Start a xen host.
 
Start a xen host.
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo xm create /etc/xen/xen1.example.com.cfg
 
sudo xm create /etc/xen/xen1.example.com.cfg
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Other DomU Setups ===
 
=== Other DomU Setups ===
 
 
Stuff goes here.
 
Stuff goes here.
 
 
== Other DomU Guest Configurations ==
 
== Other DomU Guest Configurations ==
 
 
=== Stuff to check when converting a disk image to a Dom U ===
 
=== Stuff to check when converting a disk image to a Dom U ===
 
 
/etc/fstab
 
/etc/fstab
 
 
/etc/conf.d/net or /etc/network/interfaces
 
/etc/conf.d/net or /etc/network/interfaces
 
 
/etc/resolv.conf
 
/etc/resolv.conf
 
 
/lib/modules/kernel-modules ( copy them to the guest if needed )
 
/lib/modules/kernel-modules ( copy them to the guest if needed )
 
 
on gentoo fix the /sbin/rc bug that causes /sys and /proc errors.
 
on gentoo fix the /sbin/rc bug that causes /sys and /proc errors.
 
 
Make sure you setup an empty /sys, /proc, and setup a skeleton /dev.
 
Make sure you setup an empty /sys, /proc, and setup a skeleton /dev.
 
 
set root passwd
 
set root passwd
 
 
hostname
 
hostname
 
 
 
=== Using debootstrap ===
 
=== Using debootstrap ===
 
 
sudo apt-get install debootstrap
 
sudo apt-get install debootstrap
 
 
mount the guest partition and   
 
mount the guest partition and   
 
sudo cp -a /lib/modules/2.6.19-4-server/ /mnt/myguest/lib/modules/
 
sudo cp -a /lib/modules/2.6.19-4-server/ /mnt/myguest/lib/modules/
 
 
add more info here.
 
add more info here.
 
 
=== Gentoo Guest ===
 
=== Gentoo Guest ===
 
 
http://bugs.gentoo.org/show_bug.cgi?id=192436
 
http://bugs.gentoo.org/show_bug.cgi?id=192436
 
 
=== Windows HVM Guests ===
 
=== Windows HVM Guests ===
 
 
Make sure you have HVM support turning on in the BIOS.
 
Make sure you have HVM support turning on in the BIOS.
 
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo xm dmesg | grep VMX
 
sudo xm dmesg | grep VMX
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* Windows XP and Xen. See: http://lists.xensource.com/archives/html/xen-users/2006-06/msg00599.html
 
* Windows XP and Xen. See: http://lists.xensource.com/archives/html/xen-users/2006-06/msg00599.html
 
 
For the initial install you can mount a iso as a cdrom. A vnc server will be started on localhost. To get the server to run on the machines public facing ips, make this change.
 
For the initial install you can mount a iso as a cdrom. A vnc server will be started on localhost. To get the server to run on the machines public facing ips, make this change.
 
 
 
<pre><nowiki>
 
<pre><nowiki>
 
vim /etc/xen/xend-config.sxp
 
vim /etc/xen/xend-config.sxp
 
 
#(vnc-listen '127.0.0.1')
 
#(vnc-listen '127.0.0.1')
 
(vnc-listen '0.0.0.0')
 
(vnc-listen '0.0.0.0')
 
 
and dont forget  sudo /etc/init.d/xend restart
 
and dont forget  sudo /etc/init.d/xend restart
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Your xen guest config file should look like this:
 
Your xen guest config file should look like this:
 
<pre><nowiki>
 
<pre><nowiki>
第230行: 第145行:
 
memory  = '512'
 
memory  = '512'
 
disk    = [ 'phy:barracudas/winxp01-disk,ioemu:hda,w', 'file:/home/steven/winxp.iso,ioemu:hdc:cdrom,r' ]
 
disk    = [ 'phy:barracudas/winxp01-disk,ioemu:hda,w', 'file:/home/steven/winxp.iso,ioemu:hdc:cdrom,r' ]
 
 
#  Hostname and Networking
 
#  Hostname and Networking
 
name    = 'winxp01'
 
name    = 'winxp01'
 
vif  = [ 'type=ioemu, bridge=xenbr0' ]
 
vif  = [ 'type=ioemu, bridge=xenbr0' ]
 
 
#  Behaviour
 
#  Behaviour
 
boot='d'  #d is cdrom boot, c is disk boot.
 
boot='d'  #d is cdrom boot, c is disk boot.
第240行: 第153行:
 
vncviewer=1
 
vncviewer=1
 
sdl=0
 
sdl=0
 
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
This works for booting a Windows 2003 HVM guest:
 
This works for booting a Windows 2003 HVM guest:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
#  -*- mode: python; -*-
 
#  -*- mode: python; -*-
 
 
import os, re
 
import os, re
 
arch = os.uname()[4]
 
arch = os.uname()[4]
第255行: 第163行:
 
else:
 
else:
 
arch_libdir = 'lib'
 
arch_libdir = 'lib'
 
 
kernel = "/usr/lib/xen/boot/hvmloader"
 
kernel = "/usr/lib/xen/boot/hvmloader"
 
builder='hvm'
 
builder='hvm'
第264行: 第171行:
 
disk = [ 'phy:/dev/vm-disks/win2k3,ioemu:hda,w', 'file:/root/en_win_srv_2003_r2_standard_cd1.iso,hdc:cdrom,r' ]
 
disk = [ 'phy:/dev/vm-disks/win2k3,ioemu:hda,w', 'file:/root/en_win_srv_2003_r2_standard_cd1.iso,hdc:cdrom,r' ]
 
boot = "d"
 
boot = "d"
 
 
device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'
 
device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'
 
vnc=1
 
vnc=1
第270行: 第176行:
 
serial='pty'
 
serial='pty'
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
 
 
=== GNOME as domU guest ===
 
=== GNOME as domU guest ===
 
+
# Configure GDM to start VNC, editing the `/etc/X11/gdm/gdm.conf`
** Configure GDM to start VNC, editing the `/etc/X11/gdm/gdm.conf`
+
 
+
 
Under [servers] heading, add this line, and comment out others like it:  
 
Under [servers] heading, add this line, and comment out others like it:  
 
 
<pre><nowiki>
 
<pre><nowiki>
 
0=VNC </nowiki></pre>
 
0=VNC </nowiki></pre>
 
 
Before the [server-Standard] section, add:  
 
Before the [server-Standard] section, add:  
 
 
<pre><nowiki>
 
<pre><nowiki>
 
[server-VNC]
 
[server-VNC]
第290行: 第187行:
 
command=/usr/bin/Xvnc -geometry 800x600 -depth 24
 
command=/usr/bin/Xvnc -geometry 800x600 -depth 24
 
flexible=true </nowiki></pre>
 
flexible=true </nowiki></pre>
 
 
More info: http://wiki.xensource.com/xenwiki/XenDemoLaptop
 
More info: http://wiki.xensource.com/xenwiki/XenDemoLaptop
 
More information:
 
More information:
 
 
http://www.mail-archive.com/[email protected]/msg24961.html
 
http://www.mail-archive.com/[email protected]/msg24961.html
 
 
http://openvz.org/pipermail/users/2007-January/000521.html
 
http://openvz.org/pipermail/users/2007-January/000521.html
 
 
 
== Troubleshooting ==
 
== Troubleshooting ==
 
 
If you are getting errors on your guest that look like this,
 
If you are getting errors on your guest that look like this,
 
 
<pre><nowiki>
 
<pre><nowiki>
 
perl: warning: Setting locale failed.
 
perl: warning: Setting locale failed.
第311行: 第201行:
 
are supported and installed on your system.
 
are supported and installed on your system.
 
perl: warning: Falling back to the standard locale ("C").
 
perl: warning: Falling back to the standard locale ("C").
 
 
</nowiki></pre>
 
</nowiki></pre>
 
 
then just run this command: locale-gen en_US.UTF-8
 
then just run this command: locale-gen en_US.UTF-8
 
 
Of course replace your own local name there.
 
Of course replace your own local name there.
 
 
 
Other issues:
 
Other issues:
 
 
See the older wiki entry [https://help.ubuntu.com/community/XenVirtualMachine XenVirtualMachine] for additional suggestions to try.  
 
See the older wiki entry [https://help.ubuntu.com/community/XenVirtualMachine XenVirtualMachine] for additional suggestions to try.  
 
 
Also try out this guide for xen on feisty: http://www.howtoforge.com/ubuntu_7.04_xen_from_repositories
 
Also try out this guide for xen on feisty: http://www.howtoforge.com/ubuntu_7.04_xen_from_repositories
 
 
 
 
 
 
 
 
== Great, its setup. Now how do I use it? ==
 
== Great, its setup. Now how do I use it? ==
 
 
Here are the most important Xen commands:
 
Here are the most important Xen commands:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
xm create -c /path/to/config - Start a virtual machine.
 
xm create -c /path/to/config - Start a virtual machine.
第343行: 第217行:
 
xm help - List of all commands.
 
xm help - List of all commands.
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
 
 
 
== Links ==
 
== Links ==
 
 
=== Sister Wiki's ===
 
=== Sister Wiki's ===
 
 
* [http://wiki.debian.org/Xen]
 
* [http://wiki.debian.org/Xen]
 
 
* [http://gentoo-wiki.com/HOWTO_Xen_and_Gentoo]
 
* [http://gentoo-wiki.com/HOWTO_Xen_and_Gentoo]
 
 
* [http://gentoo-wiki.com/HOWTO_Virtual_Xen_Servers_and_Gentoo]
 
* [http://gentoo-wiki.com/HOWTO_Virtual_Xen_Servers_and_Gentoo]
 
 
* [http://www.gentoo.org/doc/en/xen-guide.xml]
 
* [http://www.gentoo.org/doc/en/xen-guide.xml]
 
 
* [http://wiki.centos.org/TipsAndTricks/Xen]
 
* [http://wiki.centos.org/TipsAndTricks/Xen]
 
 
* [http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU]
 
* [http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU]
 
 
* [http://wiki.centos.org/HowTos/Xen/InstallingHVMDomU]
 
* [http://wiki.centos.org/HowTos/Xen/InstallingHVMDomU]
 
 
* [http://wiki.centos.org/HowTos/Xen/MoveNative2DomU]
 
* [http://wiki.centos.org/HowTos/Xen/MoveNative2DomU]
 
 
 
=== Learning Sites ===
 
=== Learning Sites ===
 
 
* [http://virt.kernelnewbies.org/] - A wiki dedicated to documenting the different virtualization technologies available in Linux.
 
* [http://virt.kernelnewbies.org/] - A wiki dedicated to documenting the different virtualization technologies available in Linux.
 
 
 
=== Other Reference ===
 
=== Other Reference ===
 
 
* [http://www.howtoforge.com/ubuntu_7.04_xen_from_repositories]
 
* [http://www.howtoforge.com/ubuntu_7.04_xen_from_repositories]
 
 
* [http://www.howtoforge.com/perfect_xen_setup_debian_ubuntu]
 
* [http://www.howtoforge.com/perfect_xen_setup_debian_ubuntu]
 
 
* [http://www.howtoforge.com/perfect_setup_xen3_debian]
 
* [http://www.howtoforge.com/perfect_setup_xen3_debian]
 
 
* [http://www.howtoforge.com/xen_3.0_ubuntu_dapper_drake]
 
* [http://www.howtoforge.com/xen_3.0_ubuntu_dapper_drake]
 
 
* [http://www.howtoforge.com/xen_tools_xen_shell_argo]
 
* [http://www.howtoforge.com/xen_tools_xen_shell_argo]
 
 
 
* [http://wiki.xensource.com/xenwiki/ Xen Wiki]
 
* [http://wiki.xensource.com/xenwiki/ Xen Wiki]
 
 
* [http://www.xensource.com/xen/documentation/ The Xensource Documentation]
 
* [http://www.xensource.com/xen/documentation/ The Xensource Documentation]
 
 
* [http://www.xensource.com/files/xen_user_manual.pdf Xen User's Manual] PDF
 
* [http://www.xensource.com/files/xen_user_manual.pdf Xen User's Manual] PDF
 
 
* [http://wiki.xensource.com/xenwiki/InstallationNotes]  
 
* [http://wiki.xensource.com/xenwiki/InstallationNotes]  
 
 
* [http://xen-tools.org/software/xen-tools/]
 
* [http://xen-tools.org/software/xen-tools/]
 
 
 
 
* [http://wiki.kartbuilding.net/index.php/Main_Page#Virtual_Server_.28XEN.29_set-up_and_Associated_Details] - Xen Server on Debian, lots of detail
 
* [http://wiki.kartbuilding.net/index.php/Main_Page#Virtual_Server_.28XEN.29_set-up_and_Associated_Details] - Xen Server on Debian, lots of detail
 
 
* [http://www.debian-administration.org/articles/304 Installing Xen 3.0 upon Debian Sarge]
 
* [http://www.debian-administration.org/articles/304 Installing Xen 3.0 upon Debian Sarge]
 
 
* [http://www.cl.cam.ac.uk/research/srg/netos/xen/readmes/user/user.html] Xen Users Guide
 
* [http://www.cl.cam.ac.uk/research/srg/netos/xen/readmes/user/user.html] Xen Users Guide
 
 
* http://blog.codefront.net/2007/06/26/installing-xen-on-ubuntu-feisty-fawn-the-complete-newbies-guide/
 
* http://blog.codefront.net/2007/06/26/installing-xen-on-ubuntu-feisty-fawn-the-complete-newbies-guide/
 
 
 
* [http://cosi.clarkson.edu/docs/installingxen/xen-tutorial.html Installing Xen] from the Clarkson Open Source Institute, mostly about using Ubuntu
 
* [http://cosi.clarkson.edu/docs/installingxen/xen-tutorial.html Installing Xen] from the Clarkson Open Source Institute, mostly about using Ubuntu
 
 
* [http://www.dalouche.com/wordpress/2006/11/26/howto-use-more-than-3-virtual-interfaces-with-xen-by-using-ip-aliasing/]
 
* [http://www.dalouche.com/wordpress/2006/11/26/howto-use-more-than-3-virtual-interfaces-with-xen-by-using-ip-aliasing/]
 
 
* [http://www.debian.org/releases/stable/i386/apcs04.html.en Installing Debian GNU/Linux from a Unix/Linux System] - this page has a trick of chrooting into the semi-installed system image to complete its setup
 
* [http://www.debian.org/releases/stable/i386/apcs04.html.en Installing Debian GNU/Linux from a Unix/Linux System] - this page has a trick of chrooting into the semi-installed system image to complete its setup
 
 
 
 
 
 
----
 
----
 
[[category:CategoryDocumentation]]
 
[[category:CategoryDocumentation]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 22:34的版本

Introduction

Xen is a virtual machine for linux that allows you to run multiple operating systems on a single hardware machine.

Terms

  • Dom0: The host machine OS, also called host. You know, the OS of the actual physical server that you have.
  • DomU: A Xen guest domain, also called guest. A DomU is a single Xen virtual machine. The “U” stands for “unprivileged”.
  • HVM: HVM is a way of running Windows in Xen.

Note: This guide is written for Feisty. It will be updated for Gutsy. Older versions are not really a concern, but if you really want to, please merge older information in here cleanly. Note: If you just want to run a virtual instance of windows, it is recommended to try UbuntuHelp:KVM or VirtualBox instead. There is a developing ubuntu-xen irc community on #ubuntu-xen at freenode. For development information with the ubuntu xen community, see https://wiki.ubuntu.com/Xen

Installation

Install from packages (recommended)

sudo aptitude install ubuntu-xen-server

Note: There is also a ubuntu-xen-desktop, and a ubuntu-xen-desktop-amd64. The purpose of these is a bit ambiguous, but they install firefox and all kinds of gnome libs. They may also not be PAE enabled... compiled for systems with more then 4GB of RAM. Even if you are on a 64 bit system, you should still install ubuntu-xen-server. More package details here: http://packages.ubuntu.com/feisty/base/ubuntu-xen-server The AMD64 version of ubuntu doesn't have a ubuntu-xen-server metapackage so far. Instead, use this. For Feisty:

sudo aptitude install xen-image-2.6.19-4-generic-amd64 bridge-utils libxen3.0 python-xen3.0 xen-docs-3.0 xen-hypervisor-3.0 xen-ioemu-3.0 xen-tools xen-utils-3.0

For Gutsy: (gutsy may have the package now. Look for ubuntu-xen-server.

sudo aptitude install linux-image-xen bridge-utils libxen3.1 python-xen-3.1 xen-docs-3.1 xen-hypervisor-3.1 xen-ioemu-3.1 xen-tools xen-utils-3.1

Maybe install xenman too, but it installs all kinds of gnome stuff. Next you need to enable networking. [Gutsy: I had to reboot the xen kernel before I could run the xend script]

vim /etc/xen/xend-config.sxp
#(network-script network-dummy)
(network-script network-bridge)
then
sudo /etc/init.d/xend restart  # for the change to take effect

Its also a good idea to increase the default number of loop mounts allowed. Not really needed if you are going to use LVM, but it also wont break anything if you do it anyways.

vim /etc/modules
loop max_loop=64

This is probably a good point to reboot your machine so that you use the xen kernel. After reboot is a good chance to check your network and ensure it works. Both Feisty and Gutsy may have network problems with certain hardware. If you are experiencing network problems, check out this potential solution

ACPI

If - after reboot - you see a kernel oops in dmesg or suggestion to boot with irqpoll, then try disabling ACPI and Plug 'n Play OS options in your BIOS. If you have no access to these options from the BIOS, then you may need to boot your kernel with acpi=off option. The reason is that there is no ACPI in the Xen kernel. Edit /boot/grub/menu.list and find a module line:

title           Xen 3.1 / Ubuntu 7.10, kernel 2.6.22-14-xen
root            (hd0,0)
kernel          /boot/xen-3.1.gz
module          /boot/vmlinuz-2.6.22-14-xen root=UUID=your-uuid-here ro console=tty0
module          /boot/initrd.img-2.6.22-14-xen

change the one module line with options above to:

module          /boot/vmlinuz-2.6.22-14-xen root=UUID=your-uuid-here ro console=tty0 acpi=off

Initrd

Most people can skip this section. This is just in case you get a kernel panic at reboot, then you probably have SCSI or SATA modules that need to be included in an initrd. Do this to create an initrd:

sudo depmod -a xen-3.0-i386.gz
sudo mkinitramfs -o /boot/xen-3.0-i386.initrd.img 2.6.19-4-generic

And then add this as a second module line in the Xen section of your menu.lst file.

module      /boot/xen-3.0-i386.initrd.img

This recommendation might be wrong. Please correct it if so. See here and and here for more details.

Prebuilt Binaries install

This section has not yet been written. http://xen.xensource.com/download/dl_31tarballs.html http://www.howtoforge.com/xen_3.0_ubuntu_dapper_drake

Guest Templates

LVM partitioning

xen-tools can create lvm volumes for you, so you can skip this section. If you need to make lvm volumes yourself you can use these commands. I just used the ubuntu installer to setup my LVM volume group initially. If you are using local .img files for your xen guests, then you dont need lvm.

sudo lvdisplay                         # To see existing lvm volumes.
lvcreate -n myguest-disk -L +100G my_volume_group    # To create a volume 
lvcreate -n myguest-swap -L +4G   my_volume_group    # To create another volume

Using loopback-mounted-file

dd if=/dev/zero of=/home/xen/guest_base.img bs=1024k seek=1000 count=0
dd if=/dev/zero of=/home/xen/guest_base-swap.img bs=1024k seek=500 count=0

DomU using xen-tools (recommended)

First you need to edit some of the default values in xen-tools.conf . Go through the file and set them to what you want. I've mentioned the more important ones below. Make sure you set a gateway and netmask or networking wont work.

# vim /etc/xen-tools/xen-tools.conf
gateway   = 192.168.0.1
netmask   = 255.255.255.0
passwd = 1
kernel = /boot/vmlinuz-2.6.19-4-server
initrd = /boot/initrd.img-2.6.19-4-server
mirror = http://archive.ubuntu.com/ubuntu/

Create a new image.

sudo xen-create-image --hostname=xen1.example.com --ip=192.168.1.10 --ide --force

Someone said that if you don't use --ide, it wont work. So I took their advice. man xen-create-image says " --ide Use IDE names for virtual devices (hda not sda)" Start a xen host.

sudo xm create /etc/xen/xen1.example.com.cfg

Other DomU Setups

Stuff goes here.

Other DomU Guest Configurations

Stuff to check when converting a disk image to a Dom U

/etc/fstab /etc/conf.d/net or /etc/network/interfaces /etc/resolv.conf /lib/modules/kernel-modules ( copy them to the guest if needed ) on gentoo fix the /sbin/rc bug that causes /sys and /proc errors. Make sure you setup an empty /sys, /proc, and setup a skeleton /dev. set root passwd hostname

Using debootstrap

sudo apt-get install debootstrap mount the guest partition and sudo cp -a /lib/modules/2.6.19-4-server/ /mnt/myguest/lib/modules/ add more info here.

Gentoo Guest

http://bugs.gentoo.org/show_bug.cgi?id=192436

Windows HVM Guests

Make sure you have HVM support turning on in the BIOS.

sudo xm dmesg | grep VMX

For the initial install you can mount a iso as a cdrom. A vnc server will be started on localhost. To get the server to run on the machines public facing ips, make this change.

vim /etc/xen/xend-config.sxp
#(vnc-listen '127.0.0.1')
(vnc-listen '0.0.0.0')
and dont forget  sudo /etc/init.d/xend restart

Your xen guest config file should look like this:

#Kernel and memory size
kernel = '/usr/lib/xen-ioemu-3.0/boot/hvmloader'
device_model = "/usr/lib/xen-ioemu-3.0/bin/qemu-dm"
builder = 'hvm'
memory  = '512'
disk    = [ 'phy:barracudas/winxp01-disk,ioemu:hda,w', 'file:/home/steven/winxp.iso,ioemu:hdc:cdrom,r' ]
#  Hostname and Networking
name    = 'winxp01'
vif  = [ 'type=ioemu, bridge=xenbr0' ]
#  Behaviour
boot='d'  #d is cdrom boot, c is disk boot.
vnc=1
vncviewer=1
sdl=0

This works for booting a Windows 2003 HVM guest:

#  -*- mode: python; -*-
import os, re
arch = os.uname()[4]
if re.search('64', arch):
arch_libdir = 'lib64'
else:
arch_libdir = 'lib'
kernel = "/usr/lib/xen/boot/hvmloader"
builder='hvm'
memory = 756
shadow_memory = 8
name = "Windoze"
vif = [ 'type=ioemu, bridge=xenbr0' ]
disk = [ 'phy:/dev/vm-disks/win2k3,ioemu:hda,w', 'file:/root/en_win_srv_2003_r2_standard_cd1.iso,hdc:cdrom,r' ]
boot = "d"
device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'
vnc=1
vncpasswd=''
serial='pty'

GNOME as domU guest

  1. Configure GDM to start VNC, editing the `/etc/X11/gdm/gdm.conf`

Under [servers] heading, add this line, and comment out others like it:

0=VNC 

Before the [server-Standard] section, add:

[server-VNC]
name=VNC server
command=/usr/bin/Xvnc -geometry 800x600 -depth 24
flexible=true 

More info: http://wiki.xensource.com/xenwiki/XenDemoLaptop More information: http://www.mail-archive.com/[email protected]/msg24961.html http://openvz.org/pipermail/users/2007-January/000521.html

Troubleshooting

If you are getting errors on your guest that look like this,

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

then just run this command: locale-gen en_US.UTF-8 Of course replace your own local name there. Other issues: See the older wiki entry XenVirtualMachine for additional suggestions to try. Also try out this guide for xen on feisty: http://www.howtoforge.com/ubuntu_7.04_xen_from_repositories

Great, its setup. Now how do I use it?

Here are the most important Xen commands:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown <name> - Stop a virtual machine.
xm destroy <name> - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console <name> - Log in on a virtual machine.
xm help - List of all commands.

Links

Sister Wiki's

Learning Sites

  • [9] - A wiki dedicated to documenting the different virtualization technologies available in Linux.

Other Reference