# 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