内存配置
<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@风云集团]#: