1. 加载 nbd 驱动
某些版本的 Linux 不加 max_part 参数会导致没有没有设备节点 /dev/nbd0p{1,2,3,4…} 等. 用 kpartx 也不行.
$ sudo modprobe nbd max_part=8
备注信息:查看Linux 模块信息(modinfo),例如查看nbd模块的参数
- $ modinfo nbd
- filename: /lib/modules/3.14.12/kernel/drivers/block/nbd.ko
- license: GPL
- description: Network Block Device
- srcversion: 910DE7DFCE8A0AE76D3D428
- depends:
- intree: Y
- vermagic: 3.14.12 SMP mod_unload modversions
- parm: nbds_max:number of network block devices to initialize (default: 16) (int)
- parm: max_part:number of partitions per device (default: 0) (int)
- parm: debugflags:flags for controlling debug output (int)
2.连接 qemu-nbd
- $ sudo qemu-nbd -c /dev/nbd0 centos.qcow2
查看分区:
- $ sudo 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: 0x0005d1fd
-
- Device Boot Start End Blocks Id System
- /dev/nbd0p1 * 2048 1026047 512000 83 Linux
- /dev/nbd0p2 1026048 20971519 9972736 8e Linux LVM
vgdisplay
- --- Logical volume ---
- LV Name /dev/VolGroup/lv_root
- VG Name VolGroup
- LV UUID v60jyE-1lDm-7dMW-hkVf-YWBH-OKXI-ySHDkb
- LV Write Access read/write
- LV Status NOT available
- LV Size 8.51 GiB
- Current LE 2178
- Segments 1
- Allocation inherit
- Read ahead sectors auto
-
- --- Logical volume ---
- LV Name /dev/VolGroup/lv_swap
- VG Name VolGroup
- LV UUID b1BctN-vPtc-8n6F-tokb-75pN-w34N-HXG1cB
- LV Write Access read/write
- LV Status NOT available
- LV Size 1.00 GiB
- Current LE 256
- Segments 1
- Allocation inherit
- Read ahead sectors auto
Active VolGroup
- $ sudo vgchange -a y VolGroup
mount vg
- $ sudo mount /dev/VolGroup/lv_root /mnt/test2
3.挂载
- $ sudo mount /dev/nbd0p1 /mnt/test1
4.umount disconnect
- $ sudo mount /dev/nbd0p1 /mnt/test1
- $ sudo qemu-nbd -d /dev/nbd0p1