搭建虚拟机模版

内存配置
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
 
添加光驱配置文件
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
    </disk>
 
添加硬盘配置文件
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/disk02.img'/>
      <target dev='sdb' bus='scsi'/>
    </disk>
 
添加网卡配置文件
    <interface type='bridge'>
      <source bridge='你机器上网桥的名称'/>
      <model type='virtio'/>
    </interface>
 
修改完配置文件需要 virsh define xx.xml 进行定义更新,然后 reboot 虚拟机
 
更换光盘
change-media 虚拟机名称  设备名称  --source iso路径  [--eject拔出 | --insert插入]
change-media  node1        sda     --source  /var/ftp/iso/Centos7-1708.iso --insert
 
查看块设备信息
domblklist node1
 
查看网卡信息
domiflist node1
 
命令添加网卡
virsh -c qemu:///system attach-interface 虚拟机名称 bridge 网桥名称 --model virtio
 
命令添加硬盘
virsh -c qemu:///system attach-disk 虚拟机名称 /var/lib/libvirt/images/disk.img sdb --subdriver qcow2 --sourcetype file
 
命令添加即时生效,重启后失效
 
 
使用 eth0 网卡 dhcp 动态获取ip地址
dhclient -I eth0 -v  
 
dd if=读取设备路径  of=写入设备 bs=块大小 count=块总数

模版:

domain type='kvm'>
  <name>node</name>
  <memory unit='KB'>2097152</memory>
  <currentMemory unit='KB'>2097152</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='hd'/>
    <bootmenu enable='yes'/>
    <bios useserial='yes'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-passthrough'>
  </cpu>
  <clock offset='localtime'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/node.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <source bridge='vbr'/>
      <model type='virtio'/>
    </interface>
    <channel type='unix'>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
    </channel>
    <serial type='pty'></serial>
    <console type='pty'>
      <target type='serial'/>
    </console>
    <memballoon model='virtio'></memballoon>
  </devices>
</domain>
[root@风云集团]#:

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值