手机版
你好,游客 登录 注册
背景:
阅读新闻

Ubuntu KVM Client OS创建

[日期:2012-10-15] 来源:Linux社区  作者:sheismylife [字体:大 中 小]

上一篇文章创建了第一个虚拟机及Ubuntu server后,

在/etc/libvirt/qemu/目录下,会看到vm1.xml文件,内容如下:

  1. <!--                                                                                                                                                                               
  2. WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE                                                                                                           
  3. OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:                                                                                                     
  4.   virsh edit vm1                                                                                                                                                                   
  5. or other application using the libvirt API.                                                                                                                                       
  6. --> 
  7.  
  8. <domain type='kvm'> 
  9.   <name>vm1</name> 
  10.   <uuid>75a471b9-8243-72e2-b0bb-c9ffa8c53c42</uuid> 
  11.   <memory>262144</memory> 
  12.   <currentMemory>262144</currentMemory> 
  13.   <vcpu>1</vcpu>                                                                                                                                                                   
  14.   <os> 
  15.     <type arch='x86_64' machine='pc-1.0'>hvm</type> 
  16.     <boot dev='hd'/> 
  17.   </os> 
  18.   <features> 
  19.     <acpi/> 
  20.   </features> 
  21.   <clock offset='utc'/> 
  22.   <on_poweroff>destroy</on_poweroff> 
  23.   <on_reboot>restart</on_reboot> 

 

  1.  <on_crash>destroy</on_crash> 
  2.   <devices> 
  3.     <emulator>/usr/bin/kvm</emulator> 
  4.     <disk type='file' device='disk'> 
  5.       <driver name='qemu' type='qcow2'/> 
  6.       <source file='/var/lib/libvirt/images/vm1/ubuntu-kvm/tmpTvdl9x.qcow2'/> 
  7.       <target dev='hda' bus='ide'/> 
  8.       <address type='drive' controller='0' bus='0' unit='0'/> 
  9.     </disk> 
  10.     <disk type='file' device='disk'> 
  11.       <driver name='qemu' type='qcow2'/> 
  12.       <source file='/var/lib/libvirt/images/vm1/ubuntu-kvm/tmpyGLuor.qcow2'/> 
  13.       <target dev='hdb' bus='ide'/> 
  14.       <address type='drive' controller='0' bus='0' unit='1'/> 
  15.     </disk> 
  16.     <controller type='ide' index='0'> 
  17.       <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> 
  18.     </controller> 
  19.     <interface type='bridge'> 
  20.       <mac address='52:54:00:6a:d1:90'/> 
  21.       <source bridge='br0'/> 
  22.       <model type='virtio'/> 
  23.       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> 
  24.     </interface> 
  25.     <input type='mouse' bus='ps2'/> 
  26.     <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'> 
  27.       <listen type='address' address='127.0.0.1'/> 
  28.     </graphics> 
  29.     <video> 
  30.       <model type='cirrus' vram='9216' heads='1'/> 
  31.       <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> 
  32.     </video> 
  33.     <memballoon model='virtio'> 
  34.       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> 
  35.     </memballoon> 
  36.   </devices> 
  37. </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目录下的boot.sh和vmbuilder.partition文件复制过来,改一改。然后按照上一篇的命令执行。

如果完全不改的话,连vm2目录都不需要创建,直接用下面的命令:

  1. cd /var/lib/libvirt/images/vm1/ 
  2. 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=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --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=howtoforge --addpkg=vim-nox --addpkg=unattended-upgrades --addpkg=acpid --firstboot=/var/lib/libvirt/images/vm1/boot.sh --mem=1024 --hostname=vm2 --bridge=br0 

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

linux
相关资讯       KVM  Ubuntu KVM 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款