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/

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Springboot + Openjpa 整合 GBase8s 实践「建议收藏」

    Springboot + Openjpa 整合 GBase8s 实践「建议收藏」本文我们将先来介绍JPA以及OpenJPA之间的关系,然后通过一个手把手的应用案例来讲述Springboot和Openjpa整合GBase8s。那么就让我们开始吧。JPAJPA(JavaPersistenceAPI)作为JavaEE5.0平台标准的ORM规范,将得到所有JavaEE服务器的支持。Sun这次吸取了之前EJB规范惨痛失败的经历,在充分吸收现有ORM框架的基础上,得到了一个易于使用、伸缩性强的ORM规范。从目前的开发社区的反应上看,JPA受到了极大…

    2022年4月28日
    77
  • Pytest(16)随机执行测试用例pytest-random-order「建议收藏」

    Pytest(16)随机执行测试用例pytest-random-order「建议收藏」前言通常我们认为每个测试用例都是相互独立的,因此需要保证测试结果不依赖于测试顺序,以不同的顺序运行测试用例,可以得到相同的结果。pytest默认运行用例的顺序是按模块和用例命名的ASCII编码

    2022年7月31日
    9
  • 计算机基础知识-操作系统

    计算机基础知识-操作系统1.2操作系统用来操作硬件,了解每一个硬件的作用并熟知其物理特性及使用方法(这是一个极其繁琐、庞大的工作)。桌面很占用系统资源为什么要有操作系统一般而言,现代计算机系统是一个复杂的系统。如果

    2022年8月5日
    7
  • SQL中的cast()函数「建议收藏」

    SQL中的cast()函数「建议收藏」CAST函数用于将某种数据类型的表达式显式转换为另一种数据类型。CAST()函数的参数是一个表达式,它包括用AS关键字分隔的源值和目标数据类型。语法:CAST(expressionASdata_type)expression:任何有效的SQServer表达式。AS:用于分隔两个参数,在AS之前的是要处理的数据,在AS之后是要转换的数据类型。data_type:目标系统所提供的

    2022年4月18日
    173
  • PS2手柄遥控控制灯开关(arduino)

    PS2手柄遥控控制灯开关(arduino)PS2手柄遥控控制灯开关(arduino)使用的材料arduino板子:ps2遥控手柄;一个5V供电的LDE;连线首先按照遥控手柄底座上的英文,你会发现一共有六根线,分别是GND,VCC,DAT,CMD,CS,CL。GND连接arduino板子上的gnd,vcc连接5V或者3.3v,其他四根线可以按照代码中的引脚设置连接,也可以自己更改。代码部分#include<PS…

    2022年6月3日
    89
  • 【2021-09-07】JS逆向之空气质量历史数据查询

    【2021-09-07】JS逆向之空气质量历史数据查询文章仅供学习使用,请勿用于非法活动文章目录前言一、页面分析二、数据获取三、总结前言目标网站:aHR0cHM6Ly93d3cuYXFpc3R1ZHkuY24vaGlzdG9yeWRhdGEvZGF5ZGF0YS5waHA/Y2l0eT0lRTYlOUQlQUQlRTUlQjclOUUmbW9udGg9MjAyMTA5反爬类型:反调试,动态js,数据加密一、页面分析打开网页后,f12调用开发者工具,弹出提示框解决办法:点这玩意设置里直接打开开发者工具,或者新开一个网页,f12再进链接然

    2022年6月19日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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