NBD Network block Device usage tutorial

Source: Internet
Author: User
Tags bz2 reserved server port

http://blog.csdn.net/gui694278452/article/details/7652450


I. NBD profile NBD (Network block Device) allows you to use the disk space of a remote host as a piece of equipment. It's like a hard drive.
With it, you can easily add another server's hard disk space to the local server.
NBD is different from NFS. NFS simply provides a mount point for clients to use, and the client cannot change the partition format of the mount point.
The NBD provides a block device that the client can format into various types of partitions. More user-friendly.
NBD is a kernel module that most Linux distributions already contain.
Two. NBD Installation method
In more than 10 versions of Turbolinux, NBD has been compiled into modules. Saved in
The/lib/modules/$version/kernel/driver/block/.
You also need to install Nbd-server and nbd-client Tools on both the server side and the client.
You can download source packages from the official website and install them on both the server and client servers:
Http://sourceforge.net/projects/nbd
We download nbd-2.8.8.tar.bz2 here
After downloading, perform the following steps to install:
# tar jxf nbd-2.8.8.tar.bz2
# CD nbd-2.8.8
#./configure
# make

# make Install


or install using the command line:

sudo apt-get install nbd-client

sudo apt-get install nbd-server three. NBD Use method
1. Example 1: Server-side provides a single image file to the client
A. Server-side configuration method (IP 192.168.1.1)
You need to create a disk image file to use as a block device for the client. We make a 300MB file as a block device.
# cd/var/tmp
# dd If=/dev/zero of=nbd-disk0 bs=104857600 count=3
Start Nbd-server, listen for port 1234, use Nbd-disk0 image file.
# Nbd-server 1234/var/tmp/nbd-disk0
View the NBD process.
# Ps-ef | grep NBD
Root 11292 1 0 15:02? 00:00:00 Nbd-server 1234/var/tmp/nbd-disk0
Nbd-server usage:
Nbd-server port file [SIZE][KKMM] [-l authorize_file] [-R] [-m] [-c] [-a timeout_sec]
Port Nbd-server listening ports.
The image file of the file binding.
Size of the block device that is seen by the client (in the unit can be: k,k,m,m).
-r|--read-only read-only mode, the client cannot write on a block device.
-m|--multi-file multiple files, you can provide multiple image files as a block device to the client.
-c|--copy-on-write all client writes will be saved as a file, and the file will be deleted after the connection is disconnected.
You can guarantee that the image file content will not be modified.
-l|--authorize-file file a list of hosts that allow access to this NBD.
-a|--idle-time server disconnects the maximum idle time before connecting to the client.
B. Client configuration method (IP is 192.168.1.2)
Load the NBD module.
# modprobe NBD
# Lsmod | grep NBD
NBD 26400 0
Check to see if the NBD device is established.
# ls/dev/nbd*-HL
Brw-r-----1 root disk, 0 June 06:40/dev/nbd0
Brw-r-----1 root disk, 1 June 06:40/DEV/NBD1
Brw-r-----1 root disk, 2 June 06:40/dev/nbd2
Brw-r-----1 root disk, 3 June 06:40/dev/nbd3
Brw-r-----1 root disk, 4 June 06:40/dev/nbd4
Brw-r-----1 root disk, 5 June 06:40/dev/nbd5
Brw-r-----1 Root disk, 6 June 06:40/dev/nbd6
Brw-r-----1 Root disk, 7 June 06:40/dev/nbd7
Brw-r-----1 root disk, 8 June 06:40/dev/nbd8
Brw-r-----1 Root disk, 9 June 06:40/DEV/NBD9
Connect the/DEV/NBD0 device to the host.
# nbd-client 192.168.1.1 1234/dev/nbd0
Negotiation:.. Size = 307200KB
bs=1024, sz=307200
Nbd-client usage:
Nbd-client [Bs=blocksize] host Port Nbd_device [-swap]
BS is used to set block size, default is 1024, can be 512,1024.2048,4096
Hostname or IP of host server
Listening port for Port server
Nbd_device map to which of the local NBD devices (such as:/DEV/NBD0)
-SWAP Specifies that the NBD device will be used as swap space
Nbd-client-d Nbd_device for disconnecting
Once the connection is successful, you can view the nbd-client process.
# Ps-ef | grep NBD
Root 3156 1 0 06:44 pts/0 00:00:00 nbd-client 192.168.1.1 1234/dev/nbd0
Before using, you need to format this piece of equipment.
# mkfs.ext3/dev/nbd0
MKE2FS 1.39 (29-may-2006)
FileSystem label=
OS Type:linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
76912 inodes, 307200 blocks
15360 blocks (5.00%) reserved for the Super user
The Data block=1
Maximum filesystem blocks=67633152
Block groups
8192 blocks per group, 8192 fragments per group
2024 Inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing Inode Tables:done
Creating journal (8192 blocks): Done
Writing superblocks and filesystem accounting Information:done
This filesystem would be automatically checked every mounts or
180 days, whichever comes. Use Tune2fs-c or-i to override.
Mount this block device.
# mkdir/mnt/nbd0
# mount/dev/nbd0/mnt/nbd0
# cd/mnt/nbd0
# ls
Lost+found
Copy the/root directory into this directory.
# Cp/root. -rf
# ls
Lost+found Root
Disconnect the block device.
# umount/mnt/nbd0/
# nbd-client-d/dev/nbd0
Disconnecting:que, disconnect, sock, done
Kernel call Returned:broken Pipeclosing:que, sock, done
2. Example 2: Server-side provides multiple image files to client
A. Server-side configuration
# cd/var/tmp
# dd If=/dev/zero of=nbd-disk1 bs=104857600 count=3
Recorded the 3+0 reading.
Record the writing of 3+0.
314572800 bytes (315 MB) replicated, 0.584027 seconds, 539 mb/sec
# dd If=/dev/zero of=nbd-disk2 bs=104857600 count=3
Recorded the 3+0 reading.
Record the writing of 3+0.
314572800 bytes (315 MB) replicated, 1.5128 seconds, in the same MB/sec
# Nbd-server 1234/var/tmp/nbd-disk1
# Nbd-server 1235/var/tmp/nbd-disk1
# Nbd-server 1236/var/tmp/nbd-disk2
# Ps-ef | grep NBD
Root 11292 1 0 15:02? 00:00:00 Nbd-server 1234/var/tmp/nbd-disk0
Root 11599 1 0 15:14? 00:00:00 Nbd-server 1235/var/tmp/nbd-disk1
Root 11606 1 0 15:14? 00:00:00 Nbd-server 1236/var/tmp/nbd-disk2
B. Client Configuration
# Lsmod | grep NBD
NBD 24736 0
# ls/dev/nbd*
/dev/nbd0/dev/nbd11/dev/nbd14/dev/nbd3/dev/nbd6/dev/nbd9
/dev/nbd1/dev/nbd12/dev/nbd15/dev/nbd4/dev/nbd7
/dev/nbd10/dev/nbd13/dev/nbd2/dev/nbd5/dev/nbd8
# nbd-client 192.168.1.1 1234/dev/nbd0
Negotiation:.. Size = 307200KB
bs=1024, sz=307200
# nbd-client 192.168.1.1 1235/DEV/NBD1
Negotiation:.. Size = 307200KB
bs=1024, sz=307200
# nbd-client 192.168.1.1 1236/dev/nbd2
Negotiation:.. Size = 307200KB
bs=1024, sz=307200
Format NBD1 into VFAT format.
# MKFS.VFAT/DEV/NBD1
Mkfs.vfat 2.11 (Mar 2005)
Unable to get drive geometry, using default 255/63
Format nbd2 into ext2 format.
# MKFS.EXT2/DEV/NBD2
MKE2FS 1.39 (29-may-2006)
FileSystem label=
OS Type:linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
76912 inodes, 307200 blocks
15360 blocks (5.00%) reserved for the Super user
The Data block=1
Maximum filesystem blocks=67633152
Block groups
8192 blocks per group, 8192 fragments per group
2024 Inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing Inode Tables:done
Writing superblocks and filesystem accounting Information:done
This filesystem would be automatically checked every mounts or
180 days, whichever comes. Use Tune2fs-c or-i to override.
Mount these 3 block devices
# cd/mnt
# mkdir NBD1 Nbd2
# mount/dev/nbd0 Nbd0
# MOUNT/DEV/NBD1 NBD1
# mount/dev/nbd2 Nbd2
# df-h
FileSystem Size Used Avail use% mounted on
/dev/nbd0 291M 11M 265M 4%/mnt/nbd0
/DEV/NBD1 300M 0 300M 0%/mnt/nbd1
/dev/nbd2 291M 2.1M 274M 1%/mnt/nbd2
# mount
/dev/nbd0 on/mnt/nbd0 type ext3 (rw)
/DEV/NBD1 on/mnt/nbd1 type VFAT (rw)
/dev/nbd2 on/mnt/nbd2 type ext2 (rw)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.