DEV Community

Cover image for How to Configure a Network Block Device on a Debian-Based System
Muutassim Mukhtar
Muutassim Mukhtar

Posted on

3

How to Configure a Network Block Device on a Debian-Based System

In this article, we will configure a Network Block Device on a Debian system. The communication will occur via a loopback device, with both the client and server running on the same system.

As you may know, Network Block Devices (NBD) allow us to access remote storage devices that are not physically present on the local machine. With NBD, we can access and utilize these remote storage devices on the local machine in the following three ways:

  • SWAP

  • File System

  • RAW

Let's get right into it. For the NBD export, export, an empty file will be used.The /opt directory is to be used for the exported device and configuration files. But Production environments may prefer different locations.

-Install the NBD client and server packages.

$ mkdir ~/src
$ cd ~/src
$ git clone https://github.com/NetworkBlockDevice/nbd.git

The packages docbook-utils and autoconf-archive may not be installed on your system, install them now.

$ sudo apt install nbd-client nbd-server

  • Create an nbd-server.conf file in the /opt directory. A minimal, no-comments file is sufficient. (A more interesting configuration file can be found in the SOLUTIONS directory

$ sudo vi /opt/nbd-server.conf

/opt/nbd-server.conf

config

  • Create two files for exporting and set the ownership to your user

$ sudo dd if=/dev/zero of=/opt/dsk1 status=progress bs=100M count=5

$ sudo dd if=/dev/zero of=/opt/dsk2 status=progress bs=100M count=5

$ sudo chmod 777 /opt

$ sudo chown muutassim.muutassim /opt/*

  • Verify the nbd respond to a query

$ sudo nbd-server -C /opt/nbd-server.conf
$ sudo nbd-client -l 127.0.0.1 -p 10042

verify

  • Install the nbd kernel module, and verify the block devices are present

$ sudo modprobe -i nbd
$ ls /dev/nbd*

nbd verify

  • Connect the server supplied image, using the ip address, port to the local block device

sudo nbd-client -N export_block_device 127.0.0.1 10042 /dev/nbd0

  • Wipe out the NBD

$ sudo dd if=/dev/zero of=/dev/nbd0 bs=1M count=5

wipeoutnbd

  • Create GPT label oon the NBD:

sudo sh -c "echo 'label: gpt' | sfdisk /dev/nbd0"

gpt

  • Add a partition to the NBD:

$ sudo sh -c "echo';'| sfdisk /dev/nbd0"

checking situation

  • Add an ext3 filesystem to the network block device and test:

$ sudo mkfs.ext3 -L nbd-foo /dev/nbd0

checking

$ sudo mount LABEL=nbd-foo /mnt

$ sudo touch /mnt/file1

$ ls -l /mnt

mount

Neon image

Resources for building AI applications with Neon Postgres 🤖

Core concepts, starter applications, framework integrations, and deployment guides. Use these resources to build applications like RAG chatbots, semantic search engines, or custom AI tools.

Explore AI Tools →

Top comments (0)

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay