Chinaunix首页 | 论坛 | 博客
  • 博客访问: 178936
  • 博文数量: 42
  • 博客积分: 2185
  • 博客等级: 大尉
  • 技术积分: 455
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-11 21:32
文章分类

全部博文(42)

文章存档

2012年(5)

2011年(13)

2010年(6)

2009年(18)

我的朋友

分类: LINUX

2011-12-30 23:01:32

Gentoo xen dom0/domU nano howto
Table of Contents

    1 Prerequiresites
    2 Setting up tools
    3 dom0 configuration
        3.1 Xen configuration
        3.2 Network/bridge configuration
        3.3 Configure boot loaders
    4 domU configuration
    5 Start domU
        5.1 Create domU launcher script:
        5.2 Start xen services
        5.3 Launch domU
    6 Misc

1 Prerequiresites

    Kernel version: 3.1+ Kernel 3.1 have xen dom0 support, so we don't have to build xen dom0 kernel.
    Xen version: 4.1+

2 Setting up tools

  1. echo "app-emulation/xen-tools hvm qemu screen xend" >> /etc/portage/package.use

  2. emerge -av xen-tools xen xen-pvgrub

3 dom0 configuration
3.1 Xen configuration

edit /etc/xen/xend-config.sxp, make sure the belows lines are present:

  1. (network-script network-bridge)
  2. ...
  3. (vif-script vif-bridge bridge=xenbr0)


3.2 Network/bridge configuration

Please also note bridge xenbr0 should be the bridge interface being used. You need create this interface if you don't have. IE: by modify /etc/conf.d/net:

  1. config_eth0=( "null" )

  2. bridge_xenbr0="eth0"
  3. config_xenbr0=( "192.168.100.123/24" )
  4. RC_NEED_xenbr0="net.eth0"
  5. brctl_xenbr0=( "setfd 0" "sethello 1" "stp off" )
  6. routes_xenbr0=( "default gw 192.168.100.1" )


And add xenbr0 to start script like:

  1. cd /etc/init.d/
  2. ln -s net.lo net.xenbr0
  3. rc-update add net.xenbr0 default


3.3 Configure boot loaders

In grub, make sure have below lines like:

  1. title Gentoo Linux, Xen 4.1 with Kernel 3.1
  2. root (hd0,0)
  3. kernel /boot/xen-4.1.gz
  4. module /boot/kernel-genkernel-x86_64-3.1.6-gentoo root=UUID="whatever" fstype=ext4 ro dolvm
  5. module /boot/initramfs-genkernel-x86_64-3.1.6-gentoo

If you don't know UUID of the rootfs, please run tool blkid.
4 domU configuration

Modify /etc/inittab, add the below lines:

  1. #/etc/inittab
  2. hvc0:2345:respawn:/sbin/getty 38400 hvc0 linux
  3. xvc0:2345:respawn:/sbin/getty 38400 xvc0 linux

Modify /etc/securetty, add below lines:

  1. # hypervisor virtual consoles
  2. hvc0
  3. xvc0

Modify domU grub.conf:

  1. default 0
  2. timeout 5

  3. title Gentoo Linux, Kernel 3.1.6-gentoo
  4. root (hd0)
  5. kernel /boot/kernel-genkernel-x86_64-3.1.6-gentoo root=UUID="whatever" ro dolvm
  6. initrd /boot/initramfs-genkernel-x86_64-3.1.6-gentoo


Please note:

    The domU kernel can be the same kernel as dom0 kernel, because kernel 3.1 can support both dom0 & domU (and KVM host/guest too).
    For domU, there is no need to install grub, we only need a /boot/grub/grub.conf in domU, this file will be parsed by xen-pvgrub.

5 Start domU

In dom0:
5.1 Create domU launcher script:

Say config file test1 includes:

  1. name = 'xen'
  2.  
  3. vcpus = 1;
  4.  
  5. memory = 512;
  6. maxmem = 1024;
  7.  
  8. #pvgrub here
  9. kernel = "/usr/lib/xen/boot/pv-grub-x86_64.gz"
  10. extra = "(hd0)/boot/grub/grub.conf"
  11. #end pvgrub
  12.  
  13. disk = [ 'phy:/dev/mapper/vg02-debian,xvda1,w' ];
  14.  
  15. vif = [ 'bridge=xenbr0, mac=fe:39:00:00:01:11' ];

5.2 Start xen services

  1. rc-update add xenstored default

  2. /etc/init.d/xenstored start

  3. /usr/sbin/xenconsoled


5.3 Launch domU

  1. xl create -c test1

If xenconsoled has been launched, we can see ouput immediately. Otherwise we can use xl console to attach. -] will detach current xen console.

Output may like:

  1. # xl create -c test1
  2. Parsing config file test1
  3. xc: error: panic: xc_dom_bzimageloader.c:556: xc_dom_probe_bzimage_kernel: kernel is not a bzImage: Invalid kernel
  4. Booting 'Gentoo Linux, Kernel 3.1.5-gentoo'

  5. root (hd0)
  6. Filesystem type is ext2fs, using whole disk
  7. kernel /boot/kernel-genkernel-x86_64-3.1.5-gentoo root=UUID="aaaaaaaa-bbbb-cccc
  8. -dddd-eeeeeeeeeeee" ro dolvm
  9. initrd /boot/initramfs-genkernel-x86_64-3.1.5-gentoo

  10. close blk: backend=/local/domain/0/backend/vbd/2/51713 node=device/vbd/51713
  11. [ 0.000000] Initializing cgroup subsys cpuset
  12. [ 0.000000] Initializing cgroup subsys cpu
  13. [ 0.000000] Linux version 3.1.5-gentoo (root@home) (gcc version 4.5.2 (Gentoo 4.5.2 p1.1, pie-0.4.5) ) #1 SMP PREEMPT Tue Dec 27 21:56:33 CST 2011
  14. [ 0.000000] Command line: root=UUID="aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" ro dolvm
  15. [ 0.000000] ACPI in unprivileged domain disabled
  16. [ 0.000000] released 0 pages of unused memory
  17. [ 0.000000] Set 0 page(s) to 1-1 mapping.
  18. [ 0.000000] BIOS-provided physical RAM map:
  19. [ 0.000000] Xen: 0000000000000000 - 00000000000a0000 (usable)
  20. [ 0.000000] Xen: 00000000000a0000 - 0000000000100000 (reserved)
  21. [ 0.000000] Xen: 0000000000100000 - 0000000020100000 (usable)
  22. [ 0.000000] NX (Execute Disable) protection: active
  23. [ 0.000000] DMI not present or invalid.
  24. [ 0.000000] No AGP bridge found
  25. [ 0.000000] last_pfn = 0x20100 max_arch_pfn = 0x400000000
  26. [ 0.000000] init_memory_mapping: 0000000000000000-0000000020100000
  27. [ 0.000000] RAMDISK: 0200b000 - 027cb000
  28. [ 0.000000] No NUMA configuration found
  29. [ 0.000000] Faking a node at 0000000000000000-0000000020100000
  30. [ 0.000000] Initmem setup node 0 0000000000000000-0000000020100000
  31. [ 0.000000] NODE_DATA [000000001fffb000 - 000000001fffffff]
  32. [ 0.000000] Zone PFN ranges:
  33. [ 0.000000] DMA 0x00000010 -> 0x00001000
  34. [ 0.000000] DMA32 0x00001000 -> 0x00100000
  35. [ 0.000000] Normal empty
  36. [ 0.000000] Movable zone start PFN for each node
  37. [ 0.000000] early_node_map[2] active PFN ranges
  38. [ 0.000000] 0: 0x00000010 -> 0x000000a0
  39. [ 0.000000] 0: 0x00000100 -> 0x00020100
  40. [ 0.000000] SFI: Simple Firmware Interface v0.81
  41. [ 0.000000] SMP: Allowing 1 CPUs, 0 hotplug CPUs
  42. [ 0.000000] No local APIC present
  43. [ 0.000000] APIC: disable apic facility
  44. ...
  45. localhost ~ # cat /proc/cpuinfo
  46. processor : 0
  47. vendor_id : GenuineIntel
  48. cpu family : 6
  49. model : 23
  50. model name : Pentium(R) Dual-Core CPU E5700 @ 3.00GHz
  51. stepping : 10
  52. cpu MHz : 2992.556
  53. cache size : 2048 KB
  54. fpu : yes
  55. fpu_exception : yes
  56. cpuid level : 13
  57. wp : yes
  58. flags : fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc up rep_good nopl aperfmperf pni ssse3 cx16 hypervisor lahf_lm dts
  59. bogomips : 5985.11
  60. clflush size : 64
  61. cache_alignment : 64
  62. address sizes : 36 bits physical, 48 bits virtual
  63. power management:

  64. localhost ~ #


6 Misc

I did a simple test, compile ncurses-5.9 in both dom0 & domU with make -j1, in domU:

  1. real 1m18.058s
  2. user 0m48.501s
  3. sys 0m24.422s

And in dom0:

  1. real 1m18.684s
  2. user 0m41.670s
  3. sys 0m33.490s

Hardware: E5700, DDR3 8G, HDD (500G, 5400RPM).

阅读(2387) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~