Qemu kvm_qemu详细教程

Qemu kvm_qemu详细教程重新创建vm修改虚拟机的xml文件virshshutdown原来的虚拟机virshundefine原来的虚拟机virshdefine新的xml文件,创建虚拟机virshstart虚拟机

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

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;

qemu-kvm

qemu manual : https://www.mankier.com/1/qemu

-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.

To control reporting of CPU topology information, values of the topology parameters can be specified. Machines may only support a subset of the parameters and different machines may have different subsets supported which vary depending on capacity of the corresponding CPU targets. So for a particular machine type board, an expected topology hierarchy can be defined through the supported sub-option. Unsupported parameters can also be provided in addition to the sub-option, but their values must be set as 1 in the purpose of correct parsing.

Either the initial CPU count, or at least one of the topology parameters must be specified. The specified parameters must be greater than zero, explicit configuration like "cpus=0" is not allowed. Values for any omitted parameters will be computed from those which are given.

For example, the following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 cores per socket, 2 threads per core) for a machine that only supports sockets/cores/threads. Some members of the option can be omitted but their values will be automatically computed:

-smp 8,sockets=2,cores=2,threads=2,maxcpus=8

接下来的参数,就是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:

-smp 16,sockets=2,dies=2,cores=2,threads=2,maxcpus=16

The following sub-option defines a CPU topology hierarchy (2 sockets totally on the machine, 2 clusters per socket, 2 cores per cluster, 2 threads per core) for ARM virt machines which support sockets/clusters /cores/threads. Some members of the option can be omitted but their values will be automatically computed:

-smp 16,sockets=2,clusters=2,cores=2,threads=2,maxcpus=16

Historically preference was given to the coarsest topology parameters when computing missing values (ie sockets preferred over cores, which were preferred over threads), however, this behaviour is considered liable to change. Prior to 6.2 the preference was sockets over cores over threads. Since 6.2 the preference is cores over sockets over threads.

For example, the following option defines a machine board with 2 sockets of 1 core before 6.2 and 1 socket of 2 cores after 6.2:

-smp 2

创建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.

       "--output=human" reports the following information (for every image in the chain):
       image
           The image file name

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)

参考

https://abelsu7.top/2019/03/28/kvm-review/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/169800.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号