linux qemu 加载 镜像,使用qemu-nbd挂载qcow2镜像文件

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

$ sudo lvdisplay

--- 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值