所向无敌 发表于 2015-10-10 11:50:50

Ubuntu KVM Client OS创建 二

  上一篇文章创建了第一个虚拟机及Ubuntu server后,
  在/etc/libvirt/qemu/目录下,会看到vm1.xml文件,内容如下:
  
<!--                                                                                                                                                                           
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE                                                                                                         
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:                                                                                                   
virsh edit vm1                                                                                                                                                               
or other application using the libvirt API.                                                                                                                                    
-->
<domain type='kvm'>
<name>vm1</name>
<uuid>75a471b9-8243-72e2-b0bb-c9ffa8c53c42</uuid>
<memory>262144</memory>
<currentMemory>262144</currentMemory>
<vcpu>1</vcpu>                                                                                                                                                               
<os>
<type arch='x86_64' machine='pc-1.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>  
  
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vm1/ubuntu-kvm/tmpTvdl9x.qcow2'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vm1/ubuntu-kvm/tmpyGLuor.qcow2'/>
<target dev='hdb' bus='ide'/>
<address type='drive' controller='0' bus='0' unit='1'/>
</disk>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='52:54:00:6a:d1:90'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>  这个XML文件管理了内存大小,网络接口等设备的配置。对于管理非常有用。这里可以看到代表两个磁盘的文件:
  tmpTvdl9x.qcow2和tmpyGLuor.qcow2, 都在/var/lib/libvirt/images/vm1/ubuntu-kvm目录下。
  

  现在创建第二个VM及Ubuntu server.
  还是创建vm2及其子目录:
  
mkdir -p /var/lib/libvirt/images/vm2/mytemplates/libvirt复制必要的文件:  
  
cp /etc/vmbuilder/libvirt/* /var/lib/libvirt/images/vm2/mytemplates/libvirt/可以将vm1目录下vmbuilder.partition文件复制过来,改一改。然后按照上一篇的命令执行。  
  

  如果完全不改的话,连vm2目录都不需要创建,直接用下面的命令:
  
cd /var/lib/libvirt/images/vm1/
vmbuilder kvm ubuntu --suite=precise --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=10.112.18.192 --gw=10.112.18.1 --part=vmbuilder.partition --templates=mytemplates --user=chenshu --name=chenshu --pass=123456 --adpkg=openssh-server --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --mem=1024 --hostname=vm2 --bridge=br0 -d vm2-kvm  

  我不喜欢这种方式,因为它把vm2-kvm目录创建到了vm1目录下。虚拟机目录还是分开比较好。
  所以我还是按照上篇的方式创建vm2目录和子目录,然后运行命令:
  
vmbuilder kvm ubuntu --suite=precise --flavour=virtual --arch=amd64 --mirror=http://de.archive.ubuntu.com/ubuntu -o --libvirt=qemu:///system --ip=10.112.18.192 --gw=10.112.18.1 --part=vmbuilder.partition --templates=mytemplates --user=chenshu --name=chenshu --pass=123456 --addpkg=openssh-server --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --mem=2048 --hostname=vm1 --bridge=br0

  
同样的方法创建第三个vm,ip是193.  

  
  

  
   
版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Ubuntu KVM Client OS创建 二