个人工具

UbuntuHelp:XenVirtualMachine/XenOnUbuntuFeisty

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月24日 (四) 14:11的版本 (新页面: {{From|https://help.ubuntu.com/community/XenVirtualMachine/XenOnUbuntuFeisty}} {{Languages|UbuntuHelp:XenVirtualMachine/XenOnUbuntuFeisty}} Note: If you only use Xen for desktop usage i...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索


Note: If you only use Xen for desktop usage in order to run windows programs, you should seriously consider using KVM instead. KVM is integrated to the feisty fawn kernel and the is no need for special drivers (such as nvidia proprietary drivers).

Installing packages

Desktop Version

1. Enable universe in your /etc/apt/sources.list.

2. `sudo apt-get install ubuntu-xen-desktop` for a 32-bit system OR `sudo apt-get install ubuntu-xen-desktop-amd64` for a 64bit (AMD amd64 or Intel EM64T) system (the ubuntu-xen-desktop package wasn't found when I tried installing it on an x64 system). This will install and configure the software necessary to run Xen on the desktop.

Server Version

1. Enable universe in your /etc/apt/sources.list.

2. `sudo apt-get install ubuntu-xen-server` This will install and confgiure the software necessary to run Xen on a "server".

Configuring the Virtual Machine

After install and reboot the machine, you can be able to get one list of VM's runing:

 $ sudo xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      864     2 r-----    651.1 

Now you will have to adjust the network settings that XEN will use. The xend daemon is configured in `/etc/xen/xend-config.sxp`. Add the following line to `xend-config.sxp`:

(network-script network-bridge)

And the restart the xend:

$ sudo xend stop
$ sudo xend start 

And you can see one `xenbr0` on the output of `ifconfig` command.

Using loopback-mounted-file

  • Generate loopback file as sparse file (not written entirely to disk but filled on demand) (replace 'edgy.ext3' with whatever name you want for it, ie. 'system1.ext3':
sudo dd if=/dev/zero of=/usr/local/edgy.ext3 bs=1024k seek=4096 count=0 
  • Create filesystem within (replace 'edgy.ext3' with what the name you used in step 1):
sudo mkfs.ext3 /usr/local/edgy.ext3 

Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless. (so say Yes)

  • Loopback mount filesystem (replace 'edgy' and 'edgy.ext3' with the name you used in step 1):
sudo mkdir /mnt/edgy
sudo mount /usr/local/edgy.ext3 /mnt/edgy -o loop 
  • Install debootstrap:
sudo apt-get install debootstrap 
  • Install edgy base into it (replace 'edgy' with the release-name (version) of ubuntu you want (dapper, edgy, feisty, etc), replace '/mnt/edgy' with the name you used in step 1):

32bit Host O/S & 32bit virtual host sudo debootstrap edgy /mnt/edgy

64bit Host O/S & 64bit virtual host sudo debootstrap --arch amd64 edgy /mnt/edgy

  • Give it the kernel modules (the module name depends on whether you use the desktop or server edition) (this implies you are installing the same release of ubuntu as you are currently running on the system as the host O/S, which is edgy throughout this example) (replace '/mnt/edgy' with what you used in step 1):

32bit Host OS & 32bit Virtual host: sudo cp -a /lib/modules/2.6.19-4-generic/ /mnt/edgy/lib/modules/

64bit Host OS & 64bit Virtual host: sudo cp -a /lib/modules/2.6.19-4-generic-amd64/ /mnt/edgy/lib/modules/

  • Change whatever you want to be changed before the first boot. Examples:

The network example below is somewhat confusing. Basically, whatever your Host O/S's (pre-existing) IP address is, put that in for the gateway, and make sure that the 'netmask' and 'address' put the virtual host into the same broadcast group as the host o/s (simpler example: address: 192.168.1.222 netmask: 255.255.255.0 gateway: 192.168.1.111, the 222 is the virtual host, the 111 is the host o/s's actual IP).

cat /mnt/edgy/etc/network/interfaces 
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.44.247
netmask 255.255.252.0
gateway 192.168.47.254 
cat /mnt/edgy/etc/hosts
127.0.0.1       localhost
127.0.1.1       edgyvm 
cat /mnt/edgy/etc/hostname 
edgyvm 
cat /mnt/edgy/etc/fstab
proc            /proc           proc    defaults        0       0
/dev/hda1       /               ext3    defaults,errors=remount-ro 0       1
  • Umount the loopback partition
 
sudo umount /mnt/edgy 
  • Configure the guest, create /etc/xen/edgy-guest.cfg
kernel = "/boot/vmlinuz-2.6.19-4-generic"
ramdisk = "/boot/initrd.img-2.6.19-4-generic"
builder='linux'
memory = 128
name = "edgy-guest"
vcpus = 1
vif = [ 'bridge=xenbr0' ]
disk = [ 'file:/usr/local/edgy.ext3,ioemu:hda1,w' ]
root = "/dev/hda1 ro"

Note: Change hda1 by sda1 if you are using some SATA or SCSI Controller

Note that root points to the virtual root partition of the domU and not of dom0. It is recommended to give each domU a swap partition, in such case your cfg-file may look as follows (don't forget to add it to the /etc/fstab of the virtual host, so it mounts it on boot-up):

disk = [ 'file:/usr/local/edgy.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']
  • Now you can create your xen domain
 
sudo xm create edgy-guest.cfg 
  • You can connect to the guest using the command below or any network based access that you install later on (openssh-server, vncserver, remote-X11, ...)
 
sudo xm console edgy-guest 

Use crtl + ] to get out of console.

Using FluxBox on domU guest OS

  • Get console/ or ssh on gust (domU) machine
  • Install the X packages (I've installed the ubuntu-desktop to get all dependencies, but GNOME don't work for me)
# apt-get install ubuntu-desktop 
  • Install the fluxbox
# apt-get install fluxbox 
  • Install the vncserver (make sure that you have repositories like universe and multiverse!)
# apt-get install vncserver 
  • Configure the fuxbox to start as default for you user:
$ cat ~/.xsession
exec fluxbox 
  • Configure and start the VNCServer as common user
$ vncpasswd
$ vncserver 
  • Get out of domU (or go to another machine), and connect using vncviewer using DISPLAY 1:
$ vncviewer 192.168.44.247:1 
  • To kill one VNCServer:
$ vncserver -kill :1 

Using GNOME on domU guest OS

Now I'm able to get gnome running as guest OS, doing some dirty tricks :)

    • 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

    • Try to up Xvnc "on hand" and fix all the errors:

/usr/bin/Xvnc -geometry 800x600 -depth 24

Some errors that I've found:

` Fatal server error: could not open default font 'fixed' `

Solution:

cd /usr/X11R6/lib/X11/fonts
mkfontdir misc 

And anothers erros with fonts. I've read that "Current VNC releases are built against the XFree86 X server. Recent versions of Xorg, as used by Fedora Core 6, have changed the locations of a few files, although I'm not sure why"

So, I did a lot of links on `/usr/X11R6/lib/X11/fonts` pointing to one real path that vncserver was expecting:

lrwxrwxrwx 1 root root   28 2007-03-30 15:19 100dpi -> /usr/share/fonts/X11/100dpi/
drwxr-xr-x 2 root root 4.0K 2007-03-30 15:20 75dpi
drwxr-xr-x 3 root root 4.0K 2007-03-29 09:38 encodings
-rw-r--r-- 1 root root   33 2007-03-30 14:30 fonts.cache-1
drwxr-xr-x 2 root root  20K 2007-03-30 15:07 misc
lrwxrwxrwx 1 root root   26 2007-03-30 15:21 Speedo -> /usr/share/fonts/X11/misc/
lrwxrwxrwx 1 root root   27 2007-03-30 15:18 Type1 -> /usr/share/fonts/X11/Type1/

More information:

http://www.mail-archive.com/[email protected]/msg24961.html

http://openvz.org/pipermail/users/2007-January/000521.html

After this, just start gdm and get the session using display 0 like:

vncviewer 192.168.44.247:0 

This is not the better way, but was working :)