A network block device is an export of a virtual block device through TCP/IP via NBD server and can be accessed remotely.
NBD server is usually QEMU-NBD
can provide UNIX sockets
Qemu-nbd-t-K/HOME/CLIU8/IMAGES/UBUNTUTEST-NBD ubuntutest.img
Open another window to connect to this 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
can provide a normal socket connection
QEMU-NBD-T-P 1088 ubuntutest.img
Open another window to connect to the port
Qemu-system-x86_64-enable-kvm-name ubuntutest-m 2048-hda nbd:localhost:1088-vnc:19-net nic,model=virtio-net tap,i Fname=tap0,script=no,downscript=n
Parameter--share=num, multiple clients can access the server at the same time
Parameter--snapshot, indicating that any changes are placed in the temp file
Parameter-read-only, read-only mode export this device
If there is a parameter-connect = Dev, you can pay the image directly to a network block device, and you can mount it
Qemu-nbd-c/dev/nbd0 ubuntutest.img
This time we LS, found
# ls/dev/nbd0*
/dev/nbd0/dev/nbd0p1/dev/nbd0p2/dev/nbd0p5
In fact, there are at least three partition in Ubuntutest.img.
# fdisk-l/dev/nbd0
disk/dev/nbd0:5368 MB, 5368709120 bytes
255 heads, Sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x00077a7b
Device Boot Start End Blocks Id System
/DEV/NBD0P1 * 2048 6291455 3144704 Linux
/DEV/NBD0P2 6293502 10483711 2095105 5 Extended
/DEV/NBD0P5 6293504 10483711 2095104, Linux Swap/solaris
With the Fdisk verification, it's true.
We can mount one of them.
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
This time we can modify the file inside, we have modified the image.
After the modification, we umount
# Umount UBUNTUTESTP1
# qemu-nbd-d/dev/nbd0
/DEV/NBD0 disconnected
It's not all that simple, actually.
# qemu-nbd-c/dev/nbd0 Centos-5.8.new.qcow2
# fdisk-l/dev/nbd0
disk/dev/nbd0:10.7 GB, 10737418240 bytes
255 heads, Sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk identifier:0x000f117e
Device Boot Start End Blocks Id System
/DEV/NBD0P1 * 208844 104391 Linux
/DEV/NBD0P2 208845 20964824 10377990 8e Linux LVM
We found that there was LVM, and of course LVM could not be accessed as a whole, because logic volume in it, and it was a separate file system.
# Lvscan
Inactive '/dev/volgroup00/logvol00 ' [5.97 GiB] Inherit
Inactive '/dev/volgroup00/logvol01 ' [3.91 GiB] Inherit
# Vgscan
Reading all physical volumes. This is a while ...
Found Volume Group "VolGroup00" using metadata type LVM2
# Pvscan
PV/DEV/NBD0P2 VG VolGroup00 lvm2 [9.88 gib/0 Free]
Because logical volume is in the inactive state
# Vgimport VolGroup00
Volume Group "VolGroup00" is not exported
# Vgchange-ay VolGroup00
2 Logical Volume (s) in volume group ' VolGroup00 ' now active
It's possible to mount two LV respectively.
# 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 v Ar
Upon completion
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
Under Linux, a more efficient network block device is Nbd-server, and another nbd-client connects to the server, forming a/dev/ndb0