1. 创建domU使用的逻辑分区
首先需要创建domU使用的逻辑分区LV(Logical Volume),这要求在进行dom0安装时进行逻辑卷组VG(Volume Group)的创建或在新的硬盘分区上进行创建。作者在centos dom0安装时预留了用于domU使用的逻辑卷组xen_domu,创建domU的逻辑卷都可以从此卷组上分配。
i. 查看系统目前的逻辑卷组的情况
[root@centos xen]# vgdisplay --- Volume group --- VG Name xen_domu System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 250.00 GiB PE Size 4.00 MiB Total PE 63999 Alloc PE / Size 4096 / 16.00 GiB Free PE / Size 59903 / 234.00 GiB VG UUID EsdDpB-9fuy-EqF7-8URN-DEAg-MGub-fsndjw ......ii. 使用lvcreate创建所需的逻辑分区
[root@centos xen]# lvcreate -L 8G -n ubuntu64 xen_domu Logical volume "ubuntu" created [root@centos xen]# lvdisplay /dev/xen_domu/ubuntu64 --- Logical volume --- LV Path /dev/xen_domu/ubuntu64 LV Name ubuntu64 VG Name xen_domu LV UUID 3bEYBI-NWD2-8FH8-Qc09-rlnQ-9JhN-LHFlWO LV Write Access read/write LV Creation host, time centos, 2014-02-21 17:12:13 -0500 LV Status available # open 1 LV Size 8.00 GiB Current LE 2048 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3
2. 准备配置文件
你会需要 domU 安装用的 initrd 映像及内核。你可以将它们放在一个合适的目录,并将它们改为恰当的名称。作者将相关文件放置在了/srv/ubuntu64目录下。
[root@centos ~]# cd /srv [root@centos srv]# mkdir ubuntu64 [root@centos ubuntu64]# wget http://mirrors.sohu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz [root@centos ubuntu64]# wget http://mirrors.sohu.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuzXen 在每个本地使用一个配置文件。这些本地设置在安装时会稍有分别,因为我们要提供所安装内核,甚至乎一些开机参数。Xen缺省将配置文件放置在/etc/xen目录下,这样在使用xm create创建domU客户机时就不需要指定路径参数。
/etc/xen/ubuntu.cfg配置文件的具体内容如下(具体每个参数含义可参考配置文件中的说明):
# -*- mode: python; -*- #============================================================================ # Python configuration setup for 'xm create'. # This script sets the parameters used when a domain is created using 'xm create'. # You use a separate script for each domain you want to create, or # you can set the parameters for the domain on the xm command line. #============================================================================ #---------------------------------------------------------------------------- # Kernel image file. kernel = "/srv/ubuntu64/vmlinuz" # Optional ramdisk. ramdisk = "/srv/ubuntu64/initrd.gz" # The extra option specifies a string that is appended, unchanged, to the # domU kernel options. extra = "debian-installer/exit/always_halt=true --console=hvc0" # A name for your domain. All domains must have different names. name = "ubuntu" # Initial memory allocation (in megabytes) for the new domain. # # WARNING: Creating a domain with insufficient memory may cause out of # memory errors. The domain needs enough memory to boot kernel # and modules. Allocating less than 32MBs is not recommended. memory = 1024 #---------------------------------------------------------------------------- # Define the disk devices you want the domain to have access to, and # what you want them accessible as. # Each disk entry is of the form phy:UNAME,DEV,MODE # where UNAME is the device, DEV is the device name the domain will see, # and MODE is r for read-only, w for read-write. # /dev/xvd is the standard name for Xen virtual disks, by analogy with # the hd and sd device nodes. The first virtual disk is /dev/xvda, which can # be partitioned into /dev/xvda1, and so on. disk = ['phy:/dev/xen_domu/ubuntu64,xvda,w'] # The bootloader line specifies a program that will be run within dom0 # to load and initialize the domain kernel. For example, you can specify # bootloader=pygrub to get a domain that, on startup, presents a GRUBlike # boot menu. # bootloader = "pygrub" #---------------------------------------------------------------------------- # Define network interfaces. # By default, no network interfaces are configured. You may have one created # with sensible defaults using an empty vif clause: # # vif = [ '' ] # # or optionally override backend, bridge, ip, mac, script, type, or vifname: # # vif = [ 'mac=00:16:3e:00:00:11, bridge=xenbr0' ] # # or more than one interface may be configured: # # vif = [ '', 'bridge=xenbr1' ] vif = ['bridge=xenbr0'] #---------------------------------------------------------------------------- # Configure the behaviour when a domain exits. There are three 'reasons' # for a domain to stop: poweroff, reboot, and crash. For each of these you # may specify: # # "destroy", meaning that the domain is cleaned up as normal; # "restart", meaning that a new domain is started in place of the old # one; # "preserve", meaning that no clean-up is done until the domain is # manually destroyed (using xm destroy, for example); or # "rename-restart", meaning that the old domain is not cleaned up, but is # renamed and a new domain started in its place. # # In the event a domain stops due to a crash, you have the additional options: # # "coredump-destroy", meaning dump the crashed domain's core and then destroy; # "coredump-restart', meaning dump the crashed domain's core and the restart. # # The default is # # on_poweroff = 'destroy' # on_reboot = 'restart' # on_crash = 'restart' # # For backwards compatibility we also support the deprecated option restart # # restart = 'onreboot' means on_poweroff = 'destroy' # on_reboot = 'restart' # on_crash = 'destroy' # # restart = 'always' means on_poweroff = 'restart' # on_reboot = 'restart' # on_crash = 'restart' # # restart = 'never' means on_poweroff = 'destroy' # on_reboot = 'destroy' # on_crash = 'destroy' on_shutdown = 'destroy' on_poweroff = 'destroy'
[root@centos ~]# xm create ubuntu.cfg [root@centos ~]# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 1024 16 r----- 7152.9 ubuntu 15 1024 1 ---s-- 4.1如果你正确地设置了这台 domU,安装桯序将会顺利地开始。假若你选择了手动式安装,你可以将一个主控台连接到这台domU:
[root@centos ~]# xm console ubuntu安装完成后,这台domU将会重新引导并被销毁(因为这是重新引导的缺省动作,我们稍后会更改它)。
之前的配置文件是用于安装domU,安装完成以后需要修改配置文件。
#kernel = "/srv/ubuntu/vmlinuz" #ramdisk = "/srv/ubuntu/initrd.gz" #extra = "debian-installer/exit/always_halt=true --console=hvc0" name = "ubuntu" memory = 1024 disk = ['phy:/dev/xen_domu/ubuntu64,xvda,w'] bootloader = "pygrub" vif = ['bridge=xenbr0'] on_shutdown = 'preserve' on_poweroff = 'preserve'如你所见,这个新的配置文件不会再使用内核或initrd映像。取而代之,它会使用pygrub为开机程序。pygrub会尝试在虚拟映像档的分区内寻找一个藏有GRUB配置文件的文件系统。假若能找到GRUB的配置文件,它便会被用来引导内核。
同时,你也会注意到开关机选项参数由destroy更改为perserve,这意味着domU关机操作后,你仍然可以通过“xm list”查看到此客户机,直到你使用了"xm destroy“删除。
如果你想在系统(dom0)开机时自动引导一个本地domU客户机,请将这个本地的配置文件链接到到/etc/xen/auto目录内。例如:
[root@centos ~]# cd /etc/xen/auto [root@centos auto]# ln -s ubuntu.cfg /etc/xen/ubuntu.cfg这样做亦会确保这个本地在系统关机时会被正确地关闭。
本文简单介绍了Xen4.2下安装PV Ubuntu的主要步骤,希望能够指导感兴趣的阅读者迅速创建PV的客户机。
你可能在安装的过程中遇到各种问题,需要做的就是平静下来,了解每个步骤或参数的含义,逐步排除各种可能的问题;解决问题的过程远比顺利创建出来学到的知识和技能要多得多。