使用qemu-nbd挂载qcow2文件

1. 加载 nbd 驱动

某些版本的 Linux 不加 max_part 参数会导致没有没有设备节点 /dev/nbd0p{1,2,3,4…} 等. 用 kpartx 也不行.

$ sudo modprobe nbd max_part=8

备注信息:查看Linux 模块信息(modinfo),例如查看nbd模块的参数


[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ modinfo nbd  
  2. filename:       /lib/modules/3.14.12/kernel/drivers/block/nbd.ko  
  3. license:        GPL  
  4. description:    Network Block Device  
  5. srcversion:     910DE7DFCE8A0AE76D3D428  
  6. depends:          
  7. intree:         Y  
  8. vermagic:       3.14.12 SMP mod_unload modversions   
  9. parm:           nbds_max:number of network block devices to initialize (default: 16) (int)  
  10. parm:           max_part:number of partitions per device (default: 0) (int)  
  11. parm:           debugflags:flags for controlling debug output (int)  


2.连接 qemu-nbd


[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo qemu-nbd -c /dev/nbd0 centos.qcow2  

查看分区:
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo fdisk -l /dev/nbd0  

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. Disk /dev/nbd0: 10.7 GB, 10737418240 bytes  
  2. 255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors  
  3. Units = sectors of 1 * 512 = 512 bytes  
  4. Sector size (logical/physical): 512 bytes / 512 bytes  
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes  
  6. Disk identifier: 0x0005d1fd  
  7.   
  8.      Device Boot      Start         End      Blocks   Id  System  
  9. /dev/nbd0p1   *        2048     1026047      512000   83  Linux  
  10. /dev/nbd0p2         1026048    20971519     9972736   8e  Linux LVM  


vgdisplay

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo lvdisplay  
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. --- Logical volume ---  
  2. LV Name                /dev/VolGroup/lv_root  
  3. VG Name                VolGroup  
  4. LV UUID                v60jyE-1lDm-7dMW-hkVf-YWBH-OKXI-ySHDkb  
  5. LV Write Access        read/write  
  6. LV Status              NOT available  
  7. LV Size                8.51 GiB  
  8. Current LE             2178  
  9. Segments               1  
  10. Allocation             inherit  
  11. Read ahead sectors     auto  
  12.    
  13. --- Logical volume ---  
  14. LV Name                /dev/VolGroup/lv_swap  
  15. VG Name                VolGroup  
  16. LV UUID                b1BctN-vPtc-8n6F-tokb-75pN-w34N-HXG1cB  
  17. LV Write Access        read/write  
  18. LV Status              NOT available  
  19. LV Size                1.00 GiB  
  20. Current LE             256  
  21. Segments               1  
  22. Allocation             inherit  
  23. Read ahead sectors     auto  


Active VolGroup

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo vgchange -a y VolGroup  

mount vg

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo mount /dev/VolGroup/lv_root /mnt/test2  



3.挂载


[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo mount /dev/nbd0p1 /mnt/test1  

4.umount disconnect


[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $ sudo mount /dev/nbd0p1 /mnt/test1  
  2. $ sudo qemu-nbd -d /dev/nbd0p1 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值