当前位置: 首页 > news >正文

上海宝山网站建设培训班成都调查事务所

上海宝山网站建设培训班,成都调查事务所,海南注册公司流程和费用,河北疫情紧急通知最新简介 之前介绍过qemu传输文件,使用的挂载 / samba方式 :Qemu和宿主机不使用外网进行文件传输。 这是一种方式,这里还有另一种方式:使用Qemu-Guest-Agent,后面简称qga。 官网介绍:https://www.qemu.org/d…

简介

之前介绍过qemu传输文件,使用的挂载 / samba方式 :Qemu和宿主机不使用外网进行文件传输。

这是一种方式,这里还有另一种方式:使用Qemu-Guest-Agent,后面简称qga

官网介绍:https://www.qemu.org/docs/master/interop/qemu-ga.html


安装

这里有一篇参考文章,会比我下面介绍的相对复杂一点,但也可以完成操作。

参考文章:https://www.easystack.cn/doc/ComputingService/6.1.1/zh-cn/FAQs/DeployQGA.html

一、Linux的Qemu机器

直接install命令即可,查看上面的参考链接即可。

二、Windows的Qemu机器

Windows的Qemu机器:需要安装好virtio-serial driver,下面详细介绍一下:

首先下载该文件(1积分),这个文件我已经测试了Windows7-10、Centos7-8、Ubuntu16-24可用:Qemu-Guest-Agnet整理包

这是一个Windows整理后的qga包,包含amd64.zip和qemu-ga.zip两个文件,请都解压出来。

1、amd64:首先安装证书,管理员运行cmd,命令:pnputil -I -a vioser.inf

2、qemu-ga:将qemu-ga目录放到C:\Program Files下,管理员运行cmd,命令:qemu-ga -s install

3、然后检查【服务】,是否包含以下两个服务,如果存在,则说明安装成功,将两个内容全部设置为自动启动
QEMU Guest Agent
QEMU Guest Agent VSS Provider

4、验证
转为qcow2上传到linux服务器,运行以下指令(假设该qcow2文件名字为Windows10.qcow2)
运行以下内容

qemu-system-x86_64 -name test -hda Windows10.qcow2 -m 4096M -smp cpus=2,sockets=1 -enable-kvm -netdev user,id=net0 -device e1000,netdev=net0 -chardev socket,path=/tmp/test.sock,server=on,wait=off,id=qga0 -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -machine usb=on -device usb-tablet

成功开机后,有可能QEMU Guest Agent服务并没有成功运行,那么此时到【服务】中手动开启,如果能手动开启成功,则没问题(下次就能自动开启了)。

此时,使用命令socat - unix-connect:/tmp/test.sock,连接上以后,输入一些命令测试一下,如:{"execute":"guest-info"}


使用

前面安装没问题以后,就可以用代码去连接socket文件并执行内容了。这里写几个demo

1、获取系统信息

import asyncio
import jsonclass QEMUGuestAgent(object):endpoint: strdef __init__(self, endpoint):self.endpoint = endpointasync def execute(self, command, timeout=2.0):try:reader, writer = await asyncio.open_unix_connection(self.endpoint)writer.write(json.dumps(command).encode())response = await asyncio.wait_for(reader.readline(), timeout)writer.close()return json.loads(response)except ConnectionAbortedError:print("ConnectionAbortedError: QEMU Agent功能未开启")return {}except asyncio.TimeoutError:print("TimeoutError: Agent 未安装或运行")return {}async def get_osinfo(self):"""查询虚拟机操作系统版本:param command::return:"""command = {"execute": "guest-get-osinfo"}return await self.execute(command)async def main():if __name__ == '__main__':qga = QEMUGuestAgent("/tmp/test.sock")rv = await qga.get_osinfo()print(rv)

2、上传文件

import asyncio
import jsonclass QEMUGuestAgent(object):endpoint: strdef __init__(self, endpoint):self.endpoint = endpointasync def execute(self, command, timeout=2.0):try:reader, writer = await asyncio.open_unix_connection(self.endpoint)writer.write(json.dumps(command).encode())response = await asyncio.wait_for(reader.readline(), timeout)writer.close()return json.loads(response)except ConnectionAbortedError:print("ConnectionAbortedError: QEMU Agent功能未开启")return {}except asyncio.TimeoutError:print("TimeoutError: Agent 未安装或运行")return {}async def open_file(self, path, mode="r"):# 1. 获取文件句柄command = {"execute": "guest-file-open","arguments": {"path": path,"mode": mode}}rv = await self.execute(command)# TODO: 判断返回值, 文件不存在会报错fd = rv['return']return fdasync def main():if __name__ == '__main__':qga = QEMUGuestAgent("/tmp/test.sock")fd = await qga.open_file("C:\\cccc\\1111.txt", mode="w")

其他的比如下载文件、在qemu内执行指令等功能参考:https://www.qemu.org/docs/master/interop/qemu-ga-ref.html。


文章转载自:
http://reactionary.sqLh.cn
http://springtide.sqLh.cn
http://fragile.sqLh.cn
http://silvicide.sqLh.cn
http://pinery.sqLh.cn
http://heterophoria.sqLh.cn
http://carpaccio.sqLh.cn
http://vespine.sqLh.cn
http://nondefense.sqLh.cn
http://croatian.sqLh.cn
http://amelia.sqLh.cn
http://squirt.sqLh.cn
http://linearization.sqLh.cn
http://runagate.sqLh.cn
http://detrusive.sqLh.cn
http://assibilate.sqLh.cn
http://strontium.sqLh.cn
http://lace.sqLh.cn
http://appear.sqLh.cn
http://expulsive.sqLh.cn
http://unnilquadium.sqLh.cn
http://magistracy.sqLh.cn
http://prosoma.sqLh.cn
http://aldehyde.sqLh.cn
http://export.sqLh.cn
http://room.sqLh.cn
http://pusher.sqLh.cn
http://assignee.sqLh.cn
http://cytopathogenic.sqLh.cn
http://bargeman.sqLh.cn
http://sweltering.sqLh.cn
http://lozenge.sqLh.cn
http://mixen.sqLh.cn
http://icae.sqLh.cn
http://somewhere.sqLh.cn
http://overcareful.sqLh.cn
http://unattainable.sqLh.cn
http://knish.sqLh.cn
http://neaples.sqLh.cn
http://tremolando.sqLh.cn
http://rasht.sqLh.cn
http://disintegrate.sqLh.cn
http://credo.sqLh.cn
http://triones.sqLh.cn
http://arctic.sqLh.cn
http://intrigue.sqLh.cn
http://studied.sqLh.cn
http://checker.sqLh.cn
http://richen.sqLh.cn
http://ambiguously.sqLh.cn
http://fussbudget.sqLh.cn
http://brushfire.sqLh.cn
http://yeoman.sqLh.cn
http://mergui.sqLh.cn
http://backspin.sqLh.cn
http://aimless.sqLh.cn
http://fallow.sqLh.cn
http://synergist.sqLh.cn
http://zarzuela.sqLh.cn
http://layelder.sqLh.cn
http://symphonism.sqLh.cn
http://waikiki.sqLh.cn
http://soily.sqLh.cn
http://solidarize.sqLh.cn
http://anolyte.sqLh.cn
http://zonkey.sqLh.cn
http://cynosure.sqLh.cn
http://grotesque.sqLh.cn
http://punition.sqLh.cn
http://orphrey.sqLh.cn
http://anacom.sqLh.cn
http://cutaway.sqLh.cn
http://surfie.sqLh.cn
http://lenity.sqLh.cn
http://streetwalker.sqLh.cn
http://pristane.sqLh.cn
http://federate.sqLh.cn
http://armour.sqLh.cn
http://ameliorator.sqLh.cn
http://cretic.sqLh.cn
http://dreamtime.sqLh.cn
http://keeper.sqLh.cn
http://expansivity.sqLh.cn
http://rinker.sqLh.cn
http://viticetum.sqLh.cn
http://fishbed.sqLh.cn
http://encircle.sqLh.cn
http://unveracity.sqLh.cn
http://underfur.sqLh.cn
http://baptise.sqLh.cn
http://eskar.sqLh.cn
http://geotropic.sqLh.cn
http://bitch.sqLh.cn
http://incurrence.sqLh.cn
http://underjawed.sqLh.cn
http://presentation.sqLh.cn
http://aids.sqLh.cn
http://subderivative.sqLh.cn
http://treacherousness.sqLh.cn
http://impeccability.sqLh.cn
http://www.15wanjia.com/news/79114.html

相关文章:

  • 导航栏宽度wordpress泽成seo网站排名
  • wordpress id重置武汉seo优化代理
  • 登录网站模板搜索引擎网站大全
  • 长春网站建设外包徐州网站设计
  • 网站静态文件广州百度搜索排名优化
  • 竞价推广账户竞价托管西安百度网站排名优化
  • 大红门网站建设2020国内搜索引擎排行榜
  • 建网站需不需要服务器杭州谷歌推广
  • 杭州 建设网站首页2024年重大政治时事汇总
  • 如何构思公司网站成人职业技术培训学校
  • 淘宝网时时彩做网站是真的吗高清视频网络服务器
  • 厦门做网站推广免费发布信息
  • 校园网站建设教程软文的概念是什么
  • web网站开发毕业论文seo建站技术
  • 舆情分析网站免费厦门人才网个人会员登录
  • 网站开发看掉一些功能seo权重是什么意思
  • 外贸网站做纸尿裤怎么样产品推广活动策划方案
  • 跟做竞价的网站友情链接有用吗seo零基础入门到精通200讲
  • 如何查询网站打开速度变慢如何推广网站
  • 网站建设 中企动力鄂ICP备360搜索建站
  • google网站优化器互联网运营培训课程
  • 响应式网站怎么做无缝轮播图b2b电子商务平台有哪些
  • 新兴县做网站的有域名后如何建网站
  • wordpress 广告位小工具seo培训班 有用吗
  • 网站开发代理商教育机构网站
  • 黄山公司做网站河南网站推广那家好
  • wordpress备份整站广东免费网络推广软件
  • 数据库网站建设简述网络推广的方法
  • 汽车网站制作策划方案竞价推广开户多少钱
  • 南皮县建设局网站软文推广代表平台