使用xml文件创建虚拟机

步骤一:创建一个空镜像文件(空磁盘)用来存放虚拟机

Qemu-img create -f qcow2/raw  /mnt/sunwei.qcow2 10G

步骤二:更改libvirt.xml文件

<name>vm1</name> #更改名字

<memory>8388608</memory> #更改内存

<source file='/bcshare/cluster/instance/i-02672D9E/instance'/ #空镜像文件位置

 <disk type='file' device='cdrom'>

              <target dev='hdc' bus='ide'/> 

              <source file="" />   #iso文件存放位置

              <readonly/>   #创建好虚拟机后注释这行,否则启动不了

            </disk>

            <disk type='file' device='cdrom'>

              <target dev='hdd' bus='ide'/>

              <source file="" />      #创建windows虚拟机时,驱动存放位置

              <readonly/>

            </disk>

<graphics type='vnc' port='16606' passwd='ACAEA20F' autoport='no' keymap='en-us' listen='0.0.0.0'/>  #vnc设置

<interface type='bridge'><source bridge='eucabr102'/><mac address='D0:0D:02:67:2D:9E'/><model type='virtio'/></interface> #网卡桥接模式设置,需要更改mac地址,以及桥接名称(br0)

步骤3:如果在xml文件内没有设置网卡的话,那么此时就需要手动添加网卡

virsh attach-interface --domain vm1 --type bridge --source br0

步骤4:此时物理机上面就会将br0与vnet0绑定在一起,这只是临时添加的,如果需要永久添加的话,就需要执行下面的这条语句

Virsh dumpxml vm1 >/mnt/libvirt.xml  #将生成的新的配置文件导入原始的xml文件,达到永久保存。

[root@localhost libvirt]# ls

libvirt.conf  libvirtd.conf  lxc.conf  nwfilter  qemu  qemu.conf  qemu-lockd.conf  storage  virtlockd.conf

[root@localhost libvirt]# cd qemu/

[root@localhost qemu]# ls

networks  rhel7.0.xml  vm1.xml  vm2.xml  

[root@localhost qemu]# pwd #自己创建的虚拟机xml文件存放位置

/etc/libvirt/qemu

[root@localhost qemu]# cd /var/lib/libvirt/images/

[root@localhost images]# ls

rhel7.0.qcow2  vm1  vm2

[root@localhost images]# pwd

/var/lib/libvirt/images #镜像存放位置

 

 

转载于:https://my.oschina.net/u/2368584/blog/661451

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值