Introducing Scaleway NextGen NVMe Cloud Servers with Hot-Snapshots. 🚀

Help


Community tutorials and documentations

How to connect a block device manually

How to connect a block device manually

This page shows how to connect a block device manually.

Requirements

When you create a server with additional storage, the connection to a block device is automatic at the server boot.

If you want to avoid this behavior and connect additional block devices manually, execute the following command on your server echo manual > /etc/init/nbd-add-extra-volumes.override (Ubuntu only).

There are three steps to connect a block device manually:

  • Identify NBD server and port
  • Connect to a block device
  • Format and mount the volume

Important: The maximum number of volumes attach to a BareMetal instance is limited to 15 devices.

Step 1 - Identify NBD server and port

The NBD client requires the IP address and the port number of our NBD server exporting your volume.
These settings are available from your server details page on the control panel.

Server details

The above picture shows the IP address and the port number required to export the volume in our example.

You can also use “server metadata” which gives you a lot of information.
Execute the following command on your server to display server metadata:

root@c1-X-Y-Z-T:~# oc-metadata
NAME=myc1
TAGS=1
TAGS_0=test
STATE_DETAIL=booted
PUBLIC_IP=DYNAMIC ID ADDRESS
PUBLIC_IP_DYNAMIC=True
PUBLIC_IP_ID=9915ace8-2729-4289-b962-f6a2f94d44a0
PUBLIC_IP_ADDRESS=212.47.236.31
SSH_PUBLIC_KEYS=1
SSH_PUBLIC_KEYS_0=KEY
SSH_PUBLIC_KEYS_0_KEY='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIwtTLiaKl+YPV0LjN/DJtS6hYOAEEXqAS1O5z8ft61da+3sG/kd3j9ONiepugG6sanGKRAMvx652OIZDgWbzEC40/7shAoxxbiFXBj3VgPCoKXCNLtTla4nx9hR/Xstzfm6k3/mODiioWV+TwWimM9SRo5ihwF09BhLw4sfTchtUxlLrW6pv0o4ykBPMC90yJl5KrB+7QKWaedbUYwBkXHNDDOTpBawJppp3hcfPhJjZrCk4NCdNsRhmhwaKMPNmx37hBs+Wu3Y2aAbHd4tAsQAc646/E6Xlipll8IzkNaH7PGYLhMmHB9FXI6gavi0UF12OC7abzm+MiLDOzRBx1'
PRIVATE_IP=10.1.0.31
VOLUMES=1 0
VOLUMES_1=NAME EXPORT_URI VOLUME_TYPE SERVER ORGANIZATION ID SIZE
VOLUMES_1_NAME=data_vol
-> VOLUMES_1_EXPORT_URI=nbd://10.1.0.44:4321
VOLUMES_1_VOLUME_TYPE=l_hdd
VOLUMES_1_SERVER=ID NAME
VOLUMES_1_SERVER_ID=838271d7-9744-4b3e-b29c-1c38c7c435e8
VOLUMES_1_SERVER_NAME=myc1
VOLUMES_1_ORGANIZATION=ecc1c86a-1122-43a7-9c0a-77e3123456789
VOLUMES_1_ID=965b38e6-b3bf-466c-a13c-b2004f37214a
VOLUMES_1_SIZE=100000000000
VOLUMES_0=NAME EXPORT_URI VOLUME_TYPE SERVER ORGANIZATION ID SIZE
VOLUMES_0_NAME='Ubuntu Trusty (14.04) on SSD 2014.07.15'
VOLUMES_0_EXPORT_URI=nbd://10.1.0.44:4320
VOLUMES_0_VOLUME_TYPE=l_ssd
VOLUMES_0_SERVER=ID NAME
VOLUMES_0_SERVER_ID=838271d7-9744-4b3e-b29c-1c38c7c435e8
VOLUMES_0_SERVER_NAME=myc1
VOLUMES_0_ORGANIZATION=ecc1c86a-1122-43a7-9c0a-77e3123456789
VOLUMES_0_ID=b741de3c-6bf7-4e07-b432-baadcef606a3
VOLUMES_0_SIZE=20000000000
ORGANIZATION=ecc1c86a-1122-43a7-9c0a-77e3123456789
ID=838271d7-9744-4b3e-b29c-1c38c7c435e8
  • VOLUMES_0 / VOLUMES_0_* always match the root volume of the server. Server connects and mounts it automatically at boot time.

  • VOLUMES_[1-15] / VOLUMES_[1-15]_* are additional volumes attached to the server.

VOLUMES_[1-15_EXPORT_URI=nbd://10.1.0.44:4321 this entry shows NBD server IP address and the port number of our NBD server exporting your volume.

Step 2 - Connect to a block device

An instance of the NBD client must be started for each block device to import.

For instance:

root@c1-X-Y-Z-T:~# nbd-client 10.1.0.44 4321 /dev/nbd1
Negotiation: ..size = 9536MB
bs=1024, sz=9999998976 bytes

root@c1-X-Y-Z-T:~# fdisk -l -u /dev/nbd1
Disk /dev/nbd1: 100.0 GB, 99999997952 bytes
255 heads, 63 sectors/track, 12157 cylinders, total 195312496 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: 0x00000000

In the above example, nbd-client 10.1.2.21 4129 /dev/nbd1 connects to the NBD server.
The output of fdisk -l -u /dev/nbd1 command shows that the block device /dev/nbd1 is attached to the server with success.

Step 3 - Format and mount the volume

Format additional volumes

If the new volume has never been formatted, you need to format the volume using mkfs before you can mount it.

For instance, the following command creates an ext4 file system on the volume:

root@c1-X-Y-Z-T:~# mkfs -t ext4 /dev/nbd1
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
610800 inodes, 2441406 blocks
122070 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2503999488
75 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks:
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Mount additional volumes manually

To mount the device manually as /mnt/data, run the following commands:

root@c1-X-Y-Z-T:~# mkdir -p /mnt/data
root@c1-X-Y-Z-T:~# mount /dev/nbd1 /mnt/data
root@c1-X-Y-Z-T:~# ls -la /mnt/data/
total 24
drwxr-xr-x 3 root root  4096 Jan  1 00:07 .
drwxr-xr-x 3 root root  4096 Jan  1 00:07 ..
drwx------ 2 root root 16384 Jan  1 00:07 lost+found

Mount additional volumes with systemd (automatic mount)

To mount the additional volume automatically, you can create a systemd script that will mount your volumes automatically during the boot of your cloud server.

If not yet done, create the directory into you want to mount your volume: mkdir -p /mnt/data

As the volume is empty by default, you have to create a filesystem before you can use it. To format it with with an ext4 filesystem, use the following command: mkfs -t ext4 /dev/nbd1

To get the UUID of your volume, run the command blkid and take a note of the ID as you will need it in the next step.

Create or edit the file that corresponds to the path of your directory nano /etc/systemd/system/mnt-data.mount and edit is as following: The file name of the script must correspond to the path where you mount the volume (/mnt/datamnt-data.mount)

[Unit]
Description=Mount NDB Volume at boot

[Mount]
What=UUID="16575a81-bb2c-46f3-9ad8-3bbe20157f7c"
Where=/mnt/data
Type=ext4
Options=defaults

[Install]
WantedBy=multi-user.target

Replace UUID with the ID of your volume.

Now reload systemd: systemctl daemon-reload Launch the script to mount the volume: systemctl start mnt-data.mount Finally enable the script to mount your volume automatically during boot: systemctl enable mnt-data.mount

Your volume will automatically be mounted after a reboot. You can run the df -h command, this command will list all your devices and where they are mounted:

root@scw-65acb0:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev           1009M     0 1009M   0% /dev
tmpfs           203M   12M  191M   6% /run
/dev/nbd0        46G  454M   43G   2% /
tmpfs          1011M     0 1011M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs          1011M     0 1011M   0% /sys/fs/cgroup
/dev/nbd1        46G   52M   44G   1% /mnt/data

Discover a New Cloud Experience

Deploy SSD Cloud Servers in seconds.