qemu命令总结 =================== * https://medium.com/@calerogers/gpu-virtualization-with-kvm-qemu-63ca98a6a172 .. image:: ./Qemu-logo-small.png :scale: 60% :target: https://libvirt.org --------- .. image:: ./apple-touch-icon.png :scale: 60% :target: https://www.qemu.org --------- .. |LibvirtLink| image:: ./Qemu-logo-small.png :scale: 60% .. _LibvirtLink: https://libvirt.org * `Hooks for specific system management `_ * `Libvirt和QEMU Hook机制介绍 `_ kvmgt --------------- * `Igvtg-qemu `_ * `Igvtg-kernel `_ PCI 透传 ---------------------- * `使用libvirt和qemu将pci pass through设备添加到虚拟机上 `_ * `PCI PASSTHROUGH `_ .. code-block:: sh $ tail -f /var/log/syslog $ tail -f /var/log/libvirt/qemu/${domain}.log .. code-block:: sh vim /etc/default/grub add " intel_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: GRUB_CMDLINE_LINUX="quiet splash loglevel=2 intel_iommu=igfx_off i915.hvm_boot_foreground=1 i915.enable_cmd_parser=0 i915.enable_hangcheck=0 loglvl=all guest_loglvl=all conring_size=4M noreboot intel_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1" OR .. code-block:: sh #add " intel_iommu=on vfio_iommu_type1.allow_unsafe_interrupts=1" $ vim /boot/grub/grub.cfg .. code-block:: bash $ tee hostdev.xml <<-"EOF"
EOF $ sudo virsh nodedev-dettach pci_0000_00_14_0 $ sudo virsh nodedev-reattach pci_0000_00_14_0 $ virsh attach-device --config ${domain} ./hostdev.xml $ virsh attach-device ${domain} ./hostdev.xml $ virsh detach-device ${domain} ./hostdev.xml virsh 与 qemu-img ---------------------- * `Reference Manual for libvirt `_ * https://avdv.github.io/libvirt/index.html * `Snapshot XML format `_ * `libvirt.openAuth `_ * `Python libvirt.openAuth() Examples `_ * `Libvirt Remote URIs `_ * `Adding Storage Devices To Guests `_ * https://www.thegeekstuff.com/2015/02/add-memory-cpu-disk-to-kvm-vm/ 常用命令 ------------------- * `列出 CPU Models `_ .. code-block:: sh $ cat /usr/share/libvirt/cpu_map.xml $ virsh cpu-models x86_64 .. code-block:: sh # virsh # https://wiki.libvirt.org/page/Failed_to_connect_to_the_hypervisor virsh --connect qemu+ssh://username@remove.host.com/system list virsh --connect qemu+ssh://root@192.168.8.204/system --all # spice端口 netstat -ntpl | grep qemu virsh domdisplay --type spice {Id or Name} # 创建镜像 qemu-img create -f qcow2 ubuntu-14.04.qcow2 20G qemu-img info ubuntu-14.04.qcow2 # 镜像压缩 qemu-img convert -p -c -O qcow2 source.img destination.qcow2 # resize qemu-img resize source.qcow2 +10G # 创建外部快照 qemu-img create -f qcow2 -b base.qcow2 snapshot.qcow2 # 内部快照 qemu-img snapshot -l source.qcow2 # 查看 qemu-img snapshot -c s1 source.qcow2 # 创建 qemu-img snapshot -a s1 source.qcow2 # 还原 # Committing Changes # https://dustymabe.com/2015/01/11/qemu-img-backing-files-a-poor-mans-snapshotrollback/ # $ sudo qemu-img info /guests/F21server.qcow2.snap image: /guests/F21server.qcow2.snap file format: qcow2 virtual size: 20G (21474836480 bytes) disk size: 15M cluster_size: 65536 backing file: /guests/F21server.img $ sudo qemu-img commit /guests/F21server.qcow2.snap Image committed. # 重改基础镜像 $ qemu-img rebase [-u] -b /PATH/TO/base.qcow2 linux.qcow2 # -u 指 unsafe 模式,需检验,常用于基础镜像移动位置或重命名之后. * `How to create Snapshot of Guest machine in Libvirt `_ .. code-block:: sh virsh snapshot-create-as --domain srv7 --name srv7-snapshot_1 # 创建快照 virsh snapshot-list srv7 # 列出 virsh snapshot-info srv7 srv7-snapshot_1 # info virsh snapshot-revert srv7 srv7-snapshot_1 # 还原 virsh snapshot-delete srv7 srv7-snapshot_1 # 删除 串口 ----------- * `libvirt使用虚拟机的串口和控制台 `_ 磁盘 ------ .. code-block:: sh # ubuntu 14 安装libguestfs $ sudo apt-get install libguestfs-tools # centos 7 安装libguestfs $ yum install libguestfs-winsupport # ntfs $ yum install libguestfs-tools # virt-format .. code-block:: bash $ sudo qemu-img create -f qcow2 disk 20G $ sudo virt-format --filesystem ntfs -a disk.qcow2 $ virt-ls -a image.qcow2 / $ virt-copy-in test.txt -a image.qcow2 / CD ------ .. code-block:: xml 声卡 ------ #. 查询支持的声卡 .. code-block:: sh [localhost ~] $ sudo /usr/libexec/qemu-kvm --soundhw ? Valid sound card names (comma separated): ac97 Intel 82801AA AC97 Audio hda Intel HD Audio pcspk PC speaker -soundhw all will enable all of the above 2 增加声卡 .. code-block:: sh [localhost ~] $ sudo /usr/libexec/qemu-kvm --soundhw all `Creating Guests with PXE `_ `Red Hat Enterprise Linux 6 Virtualization Host Configuration and Guest Installation Guide `_ .. raw:: html