网络块设备是通过NBD Server将虚拟块设备通过TCP/IP export出来,可以远程访问。

NBD Server通常是qemu-nbd

可以提供unix socket

qemu-nbd -t -k /home/cliu8/images/ubuntutest-nbd ubuntutest.img

打开另一个窗口,可以连接这个unix socket

qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda nbd:unix:/home/cliu8/images/ubuntutest-nbd -vnc :19 -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=n

可以提供普通的socket连接

qemu-nbd -t -p 1088 ubuntutest.img

打开另一个窗口,可以连接这个port

qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda nbd:localhost:1088 -vnc :19 -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=n

参数--share=num,可以多个客户端同时访问这个server

参数--snapshot,说明任何修改都放在临时文件中

参数—read-only,则只读模式export这个设备

如果有参数—connect = dev,则可以直接将image付给一个network block device,并且可以mount它

qemu-nbd -c /dev/nbd0 ubuntutest.img

这时候我们ls,发现

# ls /dev/nbd0*
/dev/nbd0  /dev/nbd0p1  /dev/nbd0p2  /dev/nbd0p5

其实ubuntutest.img中有至少三个partition

# fdisk -l /dev/nbd0

Disk /dev/nbd0: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00077a7b

Device Boot      Start         End      Blocks   Id  System
/dev/nbd0p1   *        2048     6291455     3144704   83  Linux
/dev/nbd0p2         6293502    10483711     2095105    5  Extended
/dev/nbd0p5         6293504    10483711     2095104   82  Linux swap / Solaris

通过fdisk验证,的确是这样的

我们可以mount其中的一个

mkdir ubuntutestp1

mount /dev/nbd0p1 ubuntutestp1/

# cd ubuntutestp1/
# ls
bin   dev  home        lib    lost+found  mnt  proc  run   srv  tmp  var
boot  etc  initrd.img  lib64  media       opt  root  sbin  sys  usr  vmlinuz

这个时候我们可以对里面的文件修改,就修改了image了。

修改完毕后,我们umount

# umount ubuntutestp1
# qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected

其实并不是所有的都这么简单

# qemu-nbd -c /dev/nbd0 centos-5.8.new.qcow2
# fdisk -l /dev/nbd0

Disk /dev/nbd0: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f117e

Device Boot      Start         End      Blocks   Id  System
/dev/nbd0p1   *          63      208844      104391   83  Linux
/dev/nbd0p2          208845    20964824    10377990   8e  Linux LVM

我们发现里面有LVM,当然LVM不能作为整体访问,因为里面有Logic volume,都是单独成文件系统的

# lvscan
  inactive          '/dev/VolGroup00/LogVol00' [5.97 GiB] inherit
  inactive          '/dev/VolGroup00/LogVol01' [3.91 GiB] inherit
# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2
# pvscan
  PV /dev/nbd0p2   VG VolGroup00            lvm2 [9.88 GiB / 0    free]

由于logical volume处于inactive的状态

# vgimport VolGroup00
  Volume group "VolGroup00" is not exported

# vgchange -ay VolGroup00
  2 logical volume(s) in volume group "VolGroup00" now active

这下可以分别mount两个LV了

# mount  /dev/VolGroup00/LogVol00 ubuntutestp1/      
# cd ubuntutestp1/
# ls
bin  boot  dev  etc  home  lib  lib64  lost+found  media  misc  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var

完毕后

umount ubuntutestp1

# vgchange -an VolGroup00
  0 logical volume(s) in volume group "VolGroup00" now active

# vgexport VolGroup00
  Volume group "VolGroup00" successfully exported

# qemu-nbd -d /dev/nbd0
/dev/nbd0 disconnected

在linux下,一个更高效的network block device是nbd-server,另有nbd-client连接server,形成一个/dev/ndb0

QEMU KVM Libvirt手册(6) – Network Block Device的更多相关文章

  1. QEMU KVM Libvirt手册(9): network

    虚拟网卡由-net nic定义 # qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda ubuntutest.img -vnc ...

  2. QEMU KVM Libvirt手册(11): Managing Storage

    When managing a VM Guest on the VM Host Server itself, it is possible to access the complete file sy ...

  3. QEMU KVM Libvirt手册(10):Managing Virtual Machines with libvirt

    libvirt is a library that provides a common API for managing popular virtualization solutions, among ...

  4. QEMU KVM Libvirt手册(7): 硬件虚拟化

    在openstack中,如果我们启动一个虚拟机,我们会看到非常复杂的参数 qemu-system-x86_64 -enable-kvm -name instance-00000024 -S -mach ...

  5. QEMU KVM libvirt 手册(3) - Storage Media

    访问Hard Drive 使用-hda –hdb qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda ubuntutest.im ...

  6. QEMU KVM libvirt手册(2): monitor

    Administrating Virtual Machines with QEMU Monitor When QEMU is running, a monitor console is provide ...

  7. QEMU KVM Libvirt手册(5) – snapshots

    前面讲了QEMU的qcow2格式的internal snapshot和external snapshot,这都是虚拟机文件格式的功能. 这是文件级别的. 还可以是文件系统级别的,比如很多文件系统支持s ...

  8. QEMU KVM Libvirt手册(8): 半虚拟化设备virtio

    KVM本身并不提供半虚拟化功能,是通过virtio来实现的 The benefits of virtio drivers are of lower overhead and higher perfor ...

  9. QEMU KVM libvirt手册(4) – images

    RAW raw是默认的格式,格式简单,容易转换为其他的格式.需要文件系统的支持才能支持sparse file 创建image # qemu-img create -f raw flat.img 10G ...

随机推荐

  1. Deep face recognition: a survey v4

    http://www.cnblogs.com/shouhuxianjian/p/9789243.html

  2. 仓鼠找sugar

    洛谷P3398 仓鼠找sugar 题目传送门 参考 \(whm\) 大佬的博客 这儿 代码不难,难在思路上. 令 \(X = lca(a,b) Y = lca(c,d)\) 仓鼠 \((cs)\) 的 ...

  3. TPshop之短信注册配置(阿里云)

      短信注册准备: 1.阿里云账号实名认证(申请地址: https://www.aliyun.com/ , 注意不是阿里大于短信平台) 步骤: 注册登录阿里云——找到控制台 ​ 鼠标放在左上角,弹出菜 ...

  4. CentOS 7 配置静态IP后不生效 & Job for network.service failed

    参考:http://tieba.baidu.com/p/3233996339#57290767555l 在CentOS中配置静态IP后不生效. 解决办法:将/etc/sysconfig/network ...

  5. sql 选取分组中的第一条,显示聚合以外的列,having字句的使用

    分组中的第一条:select * from(select row_number() over(partition by 列1,列2,... order by 列1,列2,...) as rownum ...

  6. 禁止Centos7系统yum自动下载更新

    安装Centos7后,系统自动更新状态默认为开启,若禁止系统自动更新需要手动关闭. 1.进入yum目录  [root@localhost ~]$ cd /etc/yum 2.编辑yum-cron.co ...

  7. jar文件内lib引用的jar插件修改后更新

    打包的java服务在第三方jar进行修改后,要更新线上的jar包时,直接替换原有lib引用的jar文件,会造成服务起不来, 可在本地clean install之后,用线上的classes文件夹替换本地 ...

  8. linux 端口占用

    进程id为9106,进程名称为java的进程,占用了8080端口(监听了8080端口)

  9. 部署ceph

    前提:因为ceph部署时要去国外源下载包,导致下载安装时会卡住,因此我们只需通过国内的源找到对应的rpm下载安装. 一.环境准备 4台机器,1台机器当部署节点和客户端,3台ceph节点,ceph节点配 ...

  10. 派多个订单给一个司机,拒单是同一订单id

    问题:多次派单给一个司机,发现多个拒单请求是同一个订单id的. 原因:来单页面是SingleTask, 并且没有重写onNewIntent, 而倒计时结束拒单的时候会弹窗提示,只有点了确认按钮才会把当 ...