欢迎光临散文网 会员登陆 & 注册

[QEMU]设备网址语法

2022-07-24 17:38 作者:-小白之家-  | 我要投稿

除了对模拟存储设备使用普通文件映像外,QEMU 还可以使用网络资源,如 iSCSI 设备。这些是使用特殊的 URL 语法指定的。

  • iSCSI

  • iSCSI 支持允许 QEMU 直接访问 iSCSI 资源,并用作来宾存储的映像。同时支持磁盘和 CDROM 映像。

    指定 iSCSI LUN 的语法是“iscsi://<target-ip>[:<port>]/<target-iqn>/<lun>”

    默认情况下,qemu 将使用 iSCSI 发起程序名称 'iqn.2008-11.org.linux-kvm[:<name>]“,但这也可以从命令行或配置文件进行设置。

    从版本 QEMU 2.4 开始,可以指定 iSCSI 请求超时来检测停止的请求并强制重新建立会话。超时以秒为单位指定。默认值为 0,表示无超时。此功能需要 Libiscsi 1.15.0 或更高版本。

    示例(不带身份验证):

    qemu-system-x86_64 -iscsi initiator-name=iqn.2001-04.com.example:my-initiator \                 -cdrom iscsi://192.0.2.1/iqn.2001-04.com.example/2 \                 -drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1

    示例(通过 URL 的 CHAP 用户名/密码):

    qemu-system-x86_64 -drive file=iscsi://user%password@192.0.2.1/iqn.2001-04.com.example/1

    示例(通过环境变量的 CHAP 用户名/密码):

    LIBISCSI_CHAP_USERNAME="user" \ LIBISCSI_CHAP_PASSWORD="password" \ qemu-system-x86_64 -drive file=iscsi://192.0.2.1/iqn.2001-04.com.example/1

  • NBD

  • QEMU支持NBD(网络块设备),既使用TCP协议,也支持Unix域套接字。使用 TCP 时,默认端口为 10809。

    使用 TCP 指定 NBD 设备的语法,采用首选 URI 形式:“nbd://<server-ip>[:<port>]/[<export>]”

    使用Unix域套接字指定NBD设备的语法;请记住,'?'是一个shell glob字符,可能需要引用:“nbd+unix:///[<export>]?socket=<domain-socket>”

    也可以识别的旧语法:“nbd:<server-ip>:<port>[:exportname=<export>]”

    使用Unix域套接字指定NBD设备的语法“nbd:unix:<domain-socket>[:exportname=<export>]”

    TCP 示例

    qemu-system-x86_64 --drive file=nbd:192.0.2.1:30000

    Unix 域套接字的示例

    qemu-system-x86_64 --drive file=nbd:unix:/tmp/nbd-socket

  • SSH

  • QEMU 支持对远程磁盘的 SSH(安全外壳)访问。

    例子:

    qemu-system-x86_64 -drive file=ssh://user@host/path/to/disk.imgqemu-system-x86_64 -drive file.driver=ssh,file.user=user,file.host=host,file.port=22,file.path=/path/to/disk.img

    当前,必须使用 ssh 代理完成身份验证。将来可能会支持其他身份验证方法。

  • GlusterFS

  • GlusterFS是一个用户空间分布式文件系统。QEMU 支持使用 GlusterFS 卷来托管使用 TCP、Unix 域套接字和 RDMA 传输协议的虚拟机磁盘映像。

    在 GlusterFS 卷上指定 VM 磁盘映像的语法为

    URI: gluster[+type]://[host[:port]]/volume/path[?socket=...][,debug=N][,logfile=...] JSON: 'json:{"driver":"qcow2","file":{"driver":"gluster","volume":"testvol","path":"a.img","debug":N,"logfile":"...",                                  "server":[{"type":"tcp","host":"...","port":"..."},                                            {"type":"unix","socket":"..."}]}}'

    URI: qemu-system-x86_64 --drive file=gluster://192.0.2.1/testvol/a.img,                                file.debug=9,file.logfile=/var/log/qemu-gluster.log JSON: qemu-system-x86_64 'json:{"driver":"qcow2",                           "file":{"driver":"gluster",                                    "volume":"testvol","path":"a.img",                                    "debug":9,"logfile":"/var/log/qemu-gluster.log",                                    "server":[{"type":"tcp","host":"1.2.3.4","port":24007},                                              {"type":"unix","socket":"/var/run/glusterd.socket"}]}}' qemu-system-x86_64 -drive driver=qcow2,file.driver=gluster,file.volume=testvol,file.path=/path/a.img,                                       file.debug=9,file.logfile=/var/log/qemu-gluster.log,                                       file.server.0.type=tcp,file.server.0.host=1.2.3.4,file.server.0.port=24007,                                       file.server.1.type=unix,file.server.1.socket=/var/run/glusterd.socket

    另请参见 http://www.gluster.org。

  • HTTP/HTTPS/FTP/FTPS

  • QEMU 支持对通过 http(s) 和 ftp(s) 访问的文件进行只读访问。

    使用单个文件名的语法:

    <protocol>://[<username>[:<password>]@]<host>/<path>

    哪里:

    还支持以下选项:

    请注意,当显式地将选项传递给 qemu 时,值是 <protocol>。driver

    示例:从远程 Fedora 20 实时 ISO 映像引导

    qemu-system-x86_64 --drive media=cdrom,file=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Live/x86_64/Fedora-Live-Desktop-x86_64-20-1.iso,readonly qemu-system-x86_64 --drive media=cdrom,file.driver=http,file.url=http://archives.fedoraproject.org/pub/fedora/linux/releases/20/Live/x86_64/Fedora-Live-Desktop-x86_64-20-1.iso,readonly

    示例:从远程 Fedora 20 云映像引导,使用本地覆盖进行写入、边读时复制和 64k 的预读

    qemu-img create -f qcow2 -o backing_file='json:{"file.driver":"http",, "file.url":"http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Images/x86_64/Fedora-x86_64-20-20131211.1-sda.qcow2",, "file.readahead":"64k"}' /tmp/Fedora-x86_64-20-20131211.1-sda.qcow2 qemu-system-x86_64 -drive file=/tmp/Fedora-x86_64-20-20131211.1-sda.qcow2,copy-on-read=on

    示例:从存储在 VMware vSphere 服务器上的映像引导,该映像具有自签名证书,使用本地覆盖进行写入,读取间隔为 64k,超时时间为 10 秒。

    qemu-img create -f qcow2 -o backing_file='json:{"file.driver":"https",, "file.url":"https://user:password@vsphere.example.com/folder/test/test-flat.vmdk?dcPath=Datacenter&dsName=datastore1",, "file.sslverify":"off",, "file.readahead":"64k",, "file.timeout":10}' /tmp/test.qcow2 qemu-system-x86_64 -drive file=/tmp/test.qcow2

    • url

    • 将选项显式传递给驱动程序时的完整 URL。

    • readahead

    • 向远程服务器发出每个范围请求时要提前读取的数据量。此值可以选择具有后缀“T”、“G”、“M”、“K”、“k”或“b”。如果它没有后缀,则假定它以字节为单位。该值必须是 512 字节的倍数。它默认为 256k。

    • sslverify

    • 通过 SSL 连接时是否验证远程服务器的证书。它可以具有值“开”或“关”。它默认为“开”。

    • cookie

    • 随每个传出请求发送此 Cookie(也可以是用“;”分隔的 Cookie 列表)。仅当使用支持 cookie 的 HTTP 等协议时才受支持,否则将被忽略。

    • timeout

    • 设置 CURL 连接的超时(以秒为单位)。此超时是 CURL 等待来自远程服务器的响应以获取要下载的图像大小的时间。如果未设置,则使用 5 秒的默认超时。

    • protocol

    • “http”、“https”、“ftp”或“ftps”。

    • username

    • 用于对远程服务器进行身份验证的可选用户名。

    • password

    • 用于对远程服务器进行身份验证的可选密码。

    • host

    • 远程服务器的地址。

    • path

    • 远程服务器上的路径,包括任何查询字符串。


    [QEMU]设备网址语法的评论 (共 条)

    分享到微博请遵守国家法律