QEMU: virsh/qemu-kvm 总结
文章目錄
- 參考
- 縮寫
- 潛意識
- 代碼閱讀的問題
- qemu
- virsh
- 重新創建vm
- virsh dump
- qemu-kvm
- --device
- virtio-net-pci
- -machine
- -netdev / -net
- -smp
- 創建vm,基于vmlinz
- 錯誤總結
- Failed to create chardev
- ramdisk 的大小超過80M,boot failure
- 指定串口速率
- qemu-img
- info
- file format
- virtual size
- disk size
- 代碼閱讀
- qemu 代碼閱讀
- 參考
參考
1、幫助手冊:https://www.mankier.com/1/qemu
2、source code: qemu-options.hx
3、qemu object 模型:https://github.com/Gyumeijie/qemu-object-model
4、支持的架構:https://qemu.readthedocs.io/en/latest/system/targets.html
5、vhost-user說明:https://blog.csdn.net/sinat_20184565/article/details/83070894
縮寫
qemu: quick emulator
潛意識
QEMU不只是支持x86架構的虛擬機,還支持很多其他類型的如:ARM,MIPS,等;但是對于每一種類型,就支持那么幾種通用性強,性能好的硬件架構。很固定的模式。
需要看參考4;
代碼閱讀的問題
qemu
需要首先了解,object這一套結構的機制。
virsh
重新創建vm
修改虛擬機的xml文件
virsh shutdown 原來的虛擬機
virsh undefine 原來的虛擬機
virsh define 新的 xml文件,創建虛擬機
virsh start 虛擬機
virsh dump
如果是openstack的環境,virsh dump --file 指定文件路徑后,生成的文件,不是在 指定路徑而是在:
/var/lib/docker/overlay2/****/diff/root
可以用來dump vm的 memory,是不是可以用gdb 來做dump;
下面這個鏈接有關于如何生成guest vm的的core、crash文件。
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/sect-domain_commands-creating_a_dump_file_of_a_domains_core
qemu-kvm
qemu manual : https://www.mankier.com/1/qemu
–device
-device driver[,prop[=value][,...]]添加一個設備驅動。指定屬性:prop=value。
依據設備驅動各自的屬性,來判斷屬性值;想獲得可能的驅動幫助和屬性列表可以使用:“-device help” and “-device driver,help”.
virtio-net-pci
[root@10 ~]# /usr/libexec/qemu-kvm -device virtio-net-pci,help
virtio-net-pci options:
acpi-index= - (default: 0)
addr= - Slot and optional function number, example: 06.0 or 06 (default: -1)
aer= - on/off (default: false)
any_layout= - on/off (default: true)
ats= - on/off (default: false)
bootindex=
csum= - on/off (default: true)
ctrl_guest_offloads= - on/off (default: true)
ctrl_mac_addr= - on/off (default: true)
ctrl_rx= - on/off (default: true)
ctrl_rx_extra= - on/off (default: true)
ctrl_vlan= - on/off (default: true)
ctrl_vq= - on/off (default: true)
disable-legacy= - on/off/auto (default: “auto”)
disable-modern= - (default: false)
duplex=
event_idx= - on/off (default: true)
failover= - (default: false)
failover_pair_id=
gso= - on/off (default: true)
guest_announce= - on/off (default: true)
guest_csum= - on/off (default: true)
guest_ecn= - on/off (default: true)
guest_rsc_ext= - on/off (default: false)
guest_tso4= - on/off (default: true)
guest_tso6= - on/off (default: true)
guest_ufo= - on/off (default: true)
hash= - on/off (default: false)
host_ecn= - on/off (default: true)
host_mtu= - (default: 0)
host_tso4= - on/off (default: true)
host_tso6= - on/off (default: true)
host_ufo= - on/off (default: true)
indirect_desc= - on/off (default: true)
ioeventfd= - on/off (default: true)
iommu_platform= - on/off (default: false)
mac= - Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56
migrate-extra= - on/off (default: true)
modern-pio-notify= - on/off (default: false)
mq= - on/off (default: false)
mrg_rxbuf= - on/off (default: true)
multifunction= - on/off (default: false)
netdev= - ID of a netdev to use as a backend
notify_on_empty= - on/off (default: true)
packed= - on/off (default: false)
page-per-vq= - on/off (default: false)
rombar= - (default: 1)
romfile=
romsize= - (default: 4294967295)
rsc_interval= - (default: 300000)
rss= - on/off (default: false)
rx_queue_size= - (default: 256)
speed= - (default: -1)
status= - on/off (default: true)
tx=
tx_queue_size= - (default: 256)
use-disabled-flag= - (default: true)
use-started= - (default: true)
vectors= - (default: 4294967295)
virtio-backend=<child>
virtio-pci-bus-master-bug-migration= - on/off (default: false)
x-ats-page-aligned= - on/off (default: true)
x-disable-legacy-check= - (default: false)
x-disable-pcie= - on/off (default: false)
x-ignore-backend-features= - (default: false)
x-mtu-bypass-backend= - (default: true)
x-pcie-deverr-init= - on/off (default: true)
x-pcie-extcap-init= - on/off (default: true)
x-pcie-flr-init= - on/off (default: true)
x-pcie-lnkctl-init= - on/off (default: true)
x-pcie-lnksta-dllla= - on/off (default: true)
x-pcie-pm-init= - on/off (default: true)
x-txburst= - (default: 256)
x-txtimer= - (default: 150000)
-machine
-machine pc-i440fx-rhel7.0.0,accel=kvm,usb=off,dump-guest-core=off
[root@10 ~]# /usr/libexec/qemu-kvm -machine help
Supported machines are:
pc RHEL 7.6.0 PC (i440FX + PIIX, 1996) (alias of pc-i440fx-rhel7.6.0)
pc-i440fx-rhel7.6.0 RHEL 7.6.0 PC (i440FX + PIIX, 1996) (default)
pc-i440fx-rhel7.5.0 RHEL 7.5.0 PC (i440FX + PIIX, 1996)
pc-i440fx-rhel7.4.0 RHEL 7.4.0 PC (i440FX + PIIX, 1996)
pc-i440fx-rhel7.3.0 RHEL 7.3.0 PC (i440FX + PIIX, 1996)
pc-i440fx-rhel7.2.0 RHEL 7.2.0 PC (i440FX + PIIX, 1996)
pc-i440fx-rhel7.1.0 RHEL 7.1.0 PC (i440FX + PIIX, 1996)
pc-i440fx-rhel7.0.0 RHEL 7.0.0 PC (i440FX + PIIX, 1996)
q35 RHEL-8.6.0 PC (Q35 + ICH9, 2009) (alias of pc-q35-rhel8.6.0)
pc-q35-rhel8.6.0 RHEL-8.6.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel8.5.0 RHEL-8.5.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel8.4.0 RHEL-8.4.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel8.3.0 RHEL-8.3.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel8.2.0 RHEL-8.2.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel8.1.0 RHEL-8.1.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel8.0.0 RHEL-8.0.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.6.0 RHEL-7.6.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.5.0 RHEL-7.5.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.4.0 RHEL-7.4.0 PC (Q35 + ICH9, 2009)
pc-q35-rhel7.3.0 RHEL-7.3.0 PC (Q35 + ICH9, 2009)
none empty machine
[root@10 ~]# /usr/libexec/qemu-kvm -machine pc-i440fx-rhel7.0.0,help
pc-i440fx-rhel7.0.0-machine options:
acpi= - Enable ACPI
append= - Linux kernel command line
bus-lock-ratelimit=<uint64_t> - Set the ratelimit for the bus locks acquired in VMs
confidential-guest-support=<link> - Set confidential guest scheme to support
default-bus-bypass-iommu=
dt-compatible= - Overrides the “compatible” property of the dt root node
dtb= - Linux kernel device tree file
dump-guest-core= - Include guest memory in a core dump;是否包含guest的內存,在core dump文件里;
這個使用時特別小心,如果guest的內存很大,和容易將host的磁盤吃光。需要權衡利弊。
https://libvirt.org/kbase/qemu-core-dump.html
dumpdtb= - Dump current dtb to a file and quit
firmware= - Firmware image
graphics= - Set on/off to enable/disable graphics emulation
hpet=
initrd= - Linux initial ramdisk file
kernel= - Linux kernel image file
max-fw-size= - Maximum combined firmware size
max-ram-below-4g= - Maximum ram below the 4G boundary (32bit boundary)
mem-merge= - Enable/disable memory merge support
memory-backend= - Set RAM backendValid value is ID of hostmem based backend
memory-encryption= - Set memory encryption object to use
phandle-start= - The first phandle ID we may generate dynamically
pit=
sata=
sgx-epc= - SGX EPC device
smbus=
smm= - Enable SMM
smp= - CPU topology
suppress-vmdesc= - Set on to disable self-describing migration
usb= - Set on/off to enable/disable usb
vmport= - Enable vmport (pc & q35)
x-oem-id= - Override the default value of field OEMID in ACPI table header.The string may be up to 6 bytes in size
x-oem-table-id= - Override the default value of field OEM Table ID in ACPI table header.The string may be up to 8 bytes in size
-netdev / -net
這個參數可以有多個格式,分別對應建立的網絡設備;基本格式:
-netdev tap,id=id[,fd=h][,ifname=name][,script=file][,downscript=dfile][,helper=helper]-net tap[,vlan=n][,name=name][,fd=h][,ifname=name][,script=file][,downscript=dfile][,helper=helper]下面這個是增強模式,支持vlan:Connect the host TAP network interface name to VLAN n.這個參數可以使用腳本來配置,網絡設備:
script=file是配置腳本;
downscript=dfile是消除配置腳本;如果沒有提供ifname參數,系統會默認提供一個;默認的配置腳本在:/etc/qemu-ifup,消除配置腳本是在/etc/qemu-ifdown。如果不想使用腳本可以設置尾no:script=no 和downscript=no;
如果當前qemu執行的用戶非root用戶,可以是i有helper參數來幫助對TAP設備進行配置,默認的幫助腳本是:/path/to/qemu-bridge-helper。
fd=h,可以用來指定已經打開的主機TAP設備的處理程序,handler,文件描述符。
舉例: #launch a QEMU instance with the default network script
qemu-system-i386 linux.img -net nic -net tap
#launch a QEMU instance with two NICs, each one connected to a TAP device
qemu-system-i386 linux.img
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0
-net nic,vlan=1 -net tap,vlan=1,ifname=tap1
#launch a QEMU instance with the default network helper to connect a TAP device to bridge br0
qemu-system-i386 linux.img
-net nic -net tap,“helper=/path/to/qemu-bridge-helper”
這個說明有點老;無法解釋下面的參數設置;
-netdev tap,fd=32,id=hostnet0,vhost=on,vhostfd=34
" use vhost=on to enable experimental in kernel accelerator\n" ;; 使用內核加速器;
" use ‘vhostfd=h’ to connect to an already opened vhost net device\n";;鏈接已經打開的vhost網絡設備
-smp
-smp [[cpus=]n][,maxcpus=maxcpus][,sockets=sockets][,dies=dies][,clusters=clusters][,cores=cores][,threads=threads]
模擬SMP的系統,虛擬器初始之后,模擬出n個CPU。如果模擬的板子支持CPU熱拔插,maxcpus就是在系統運行時,最多可以添加到多少個CPU。如果cpus和maxcpus兩個參數沒有設置,會根據相關的其他參數來做計算,計算的值就是兩個參數的值。When only one of them is given then the omitted one will be set to its counterpart’s value. Both parameters may be specified, but the maximum number of CPUs must be equal to or greater than the initial CPU count. Product of the CPU topology hierarchy must be equal to the maximum number of CPUs. Both parameters are subject to an upper limit that is determined by the specific machine type chosen.
接下來的參數,就是CPU拓撲結構(2個sockets,每個socket兩個dies,每個die有兩個core,每個core有2個threads)
The following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 dies per socket, 2 cores per die, 2 threads per core) for PC machines which support sockets/dies/cores/threads. Some members of the option can be omitted but their values will be automatically computed:
創建vm,基于vmlinz
-kernel bzImage Use bzImage as kernel image. The kernel can be either a Linux kernel or in multiboot format.
-append cmdline Use cmdline as kernel command line
-initrd file Use file as initial ram disk.
-name name Sets the name of the guest. This name will be displayed in the SDL window caption. The name will also be used for the VNC server. Also optionally set the top visible process name in Linux.
-serial stdio 在command 參數里指定 console=ttyS0,就可以打印出來了。debug kernel/系統啟動的問題時,就用這個參數就可用。不需要其他的
-m 指定內存大小
/usr/libexec/qemu-kvm -kernel vmlinuz-4.18.0-240.15.1.el8_3.x86_64 -initrd js.lcprhel.image -append “root=/dev/ram rw root_size=300M lcpbrdtype=kvm console=ttyS0” -serial stdio -m 512
錯誤總結
Failed to create chardev
char device redirected to /dev/pts/12 (label charserial0)
qemu-kvm: -chardev pipe,id=charchannel0,path=/tmp/FROM-abc: Failed to create chardev
這個是什么原因:
chardev/char-pty.c
char_pty_open
error_report(“char device redirected to %s (label %s)”, pty_name, chr->label);
為什么會打印這個錯誤:https://gitlab.com/qemu-project/qemu/-/commit/6ade45f2ac936114d82a18ed10df1fb717f4a584
Why is it even printed? No other ChardevClass::open() prints anything on success. It’s because you need to know PTY_NAME to actually use this char device, e.g. like e.g. “socat STDIO,cfmakeraw FILE:PTY_NAME” to use the monitor’s readline interface. You can get PTY_NAME with “info chardev” (a.k.a. query-chardev for QMP), but only if you already have a monitor.
之后再怎么處理? 有log文件,可用查看log文件,在哪里?
ramdisk 的大小超過80M,boot failure
/usr/libexec/qemu-kvm -kernel vmlinuz-4.18.0-240.15.1.el8_3.x86_64 -initrd js.lcprhel.image -append “root=/dev/ram rw root_size=300M lcpbrdtype=kvm console=ttyS0” -serial stdio -m 512
如果ramdsik的大小大于80M,需要指定的內存大一點。-m 默認是128M
https://stackoverflow.com/questions/42872992/qemu-fails-to-load-when-my-initrd-cpio-is-large-80-mb
這個有什么可用供參考的log嗎?
指定串口速率
/usr/libexec/qemu-kvm -kernel vmlinuz-4.18.0-240.15.1.el8_3.x86_64 -initrd js.lcprhel.image -append “root=/dev/ram rw root_size=300M lcpbrdtype=kvm console=ttyS0,115200n81” -serial stdio -m 512
指定串口的速率,這個也比較重要;不如串口不能輸入命令
qemu-img
qemu-img可以離線新建,轉換,修改images。It can handle all image formats supported by QEMU.
警告,絕不要在image被虛擬機或者其他進程使用三修改它。這樣會導致image損壞。同時在這種情況下也不要查詢image,可能導致image的狀態不一致。
info
info [–object objectdef] [–image-opts] [-f fmt] [–output=ofmt] [–backing-chain] [-U] filename
查詢磁盤image文件的信息。主要是查看占有的磁盤空間,原因是所占用的磁盤空間可能和顯示的大小不一樣。
Use it in particular to know the size reserved on disk which can be different from the displayed size. If VM snapshots are stored in the disk image, they are displayed too.
If a disk image has a backing file chain, information about each disk image in the chain can be recursively enumerated by using the option “–backing-chain”.
For instance, if you have an image chain like:
base.qcow2 <- snap1.qcow2 <- snap2.qcow2
To enumerate information about each disk image in the above chain, starting from top to base, do:
qemu-img info --backing-chain snap2.qcow2
The command can output in the format ofmt which is either “human” or “json”. The JSON output is an object
of QAPI type “ImageInfo”; with “–backing-chain”, it is an array of “ImageInfo” objects.
file format
The image format: 這些都是什么format,格式,奇奇怪怪的格式。
Supported formats: blkdebug blklogwrites blkreplay blkverify copy-on-read file ftp ftps gluster host_cdrom host_device http https iscsi iser luks nbd null-aio null-co nvme qcow2 quorum raw rbd ssh throttle vhdx vmdk vpc
virtual size
The size of the guest disk
disk size
How much space the image file occupies on the host file system (may be shown as 0 if this information is unavailable, e.g. because there is no file system)
代碼閱讀
qemu 代碼閱讀
這一段代碼的含義是,在5.1 這個版本上設置:no_kvm_steal_time = true;
static void virt_machine_5_1_options(MachineClass *mc) {VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));virt_machine_5_2_options(mc);compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len);vmc->no_kvm_steal_time = true; }參考
https://abelsu7.top/2019/03/28/kvm-review/
總結
以上是生活随笔為你收集整理的QEMU: virsh/qemu-kvm 总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab imnoise 用法,使用
- 下一篇: 计算机数值转换教案,计算机数值方法教案.