为了创建的半虚拟化VM能上网,在domain0中需设置网桥:
#vi /etc/network/interface
修改如下:
# The loopback network interfaces
auto lo
iface lo inet loopback
#The primary network interface
#auto eth0
#iface eth0 inet dhcp
auto lo eth0 xenbr0
iface lo inet loopback
iface xenbr0 inet dhcp
bridge_ports eth0
iface eth0 inet manual
注意这里先创建配置文件ubud1.cfg不带vtpm的VM,然后再添加进去。你也可以从vtpmmgr.cfg->vtpm.cfg->ubund1.cfg顺序启动。不过由于没有硬件tpm,创建vtpmmgr.cfg就会报错,解决方法后面讲。
List your existingvolume groups (VG) and choose where you'd like to create the new logicalvolume. 这里用的是逻辑盘创建 ,如果你的没有(即安装Ubuntuserver的时候没有用lvm)你可以用dd命令创建磁盘。
$ sudo vgs
Create the logical volume (LV).
$ sudo lvcreate -L10G -n lv_vm_ubuntu /dev/<VGNAME>
Confirm that the new LV was successfully created.
$ sudo lvs
Get NetbootImages
$ sudo mkdir -p /var/lib/xen/images/ubuntu-netboot/trusty14LTS
$ cd /var/lib/xen/images/ubuntu-netboot/trusty14LTS
下载镜像进行安装:http://mirrors.163.com或者http://mirrors.aliyun.com
$ wget http://mirrors.163.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/xen/vmlinuz
$ wget http://mirrors.163.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/xen/initrd.gz
Set Up InitialGuest Configuration
$ cd /etc/xen
$ cp xlexample.pvlinux ubud1.cfg
$ vi ubud1.cfg
name = "ubud1"
kernel = "/var/lib/xen/images/ubuntu-netboot/trusty14LTS/vmlinuz"
ramdisk = "/var/lib/xen/images/ubuntu-netboot/trusty14LTS/initrd.gz"
#bootloader = "/usr/lib/xen-4.4/bin/pygrub"
memory = 1024
vcpus = 1
# Custom option for Open vSwitch
vif = [ '' ]
disk = [ '/dev/<VGNAME>/lv_vm_ubuntu,raw,xvda,rw' ]
# You may also consider some other options
# [[http://xenbits.xen.org/docs/4.4-testing/man/xl.cfg.5.html]]
然后启动ubund1.cfg进行domainU的安装: 注意这里一定联网哦 !
$ sudo xl create -c /etc/xen/ubud1.cfg
Once installed and back to command line, modify guestconfiguration to use the pygrub bootloader. These lines will change
$ vi /etc/xen/ubud1.cfg
#kernel = "/var/lib/xen/images/ubuntu-netboot/trusty14LTS/vmlinuz"
#ramdisk = "/var/lib/xen/images/ubuntu-netboot/trusty14LTS/initrd.gz"
bootloader = "/usr/lib/xen-4.4/bin/pygrub"
Now let's restart theVM with the new bootloader. (If the VM didn't shutdown after the install above,you may manually shut it down.)
$ sudo xl shutdownubud1
$ sudo xl create -c /etc/xen/ubud1.cfg
Ctrl+]
再回到domainU输入:
$ sudo xl consoleubud1
好了,下面开始说一下关于vtpm的事情,分析源码发现用户DomainU发送一个命令比如:tpm_version。这个命令根本没有传入到vtpmmgr域中(而根据xen的前后端思想,命令应该传送到vtpmmgr然后传入物理tpm芯片。),而分析源码发现:该命令直接传入vtpm域的main_loop函数中,在这个函数中调用了tpm-emulator中的命令。直接执行并且返回了,而没有往下层传命令。而这个tpm-emulator是编译xen的时候自动下载,并且编译到vtpm域中的。有兴趣的可以看一下源码:
在xen4.6版本中:/stubdom/vtpm/vtpm.c 300行左右的tpm_handle_command函数(这个是调用的tpm-emulato中的函数)。
而如何启动vtpm域,是应该先启动vtpmmgr域的,你可以把启动vtpmmgr域时(cd /etc/xen xl create -c vtpmmgr.cfg)报错的代码注释掉,让vtpmmgr域启动,然后再配置好vtpm.cfg启动就ok了。