How to attach and detach additional volumes to a Bare Metal instance

Attaching and detaching additional volumes on an existing Bare Metal instance

Important: Additional Volumes are available on Bare Metal instances. The volume size of virtual cloud instances is fixed depending on the offer.

This page shows how to attach and detach additional volumes to an existing Bare Metal instance.

Requirements

Each Bare Metal instance can have up to 15 volumes, including the root volume.

Local storage volumes are transferred close to your instance.

When you start a instance for the first time, your volume files are downloaded from the volumes store to the local storage devices.

Each time you start or stop a instance, the volumes are downloaded or uploaded to the volumes store. The larger the amount of data to transfer, the longer the upload or download duration.

We work constantly on optimizing the transfer time of local storage devices to the volumes store.

There are six steps to attach a volume to an existing Bare Metal instance

Important: A Bare Metal instance must be powered off to attach or detach a volume.

Powering off a Bare Metal Instance

Before being able to attach a new volume to an existing Bare Metal instance, it has to be switched off from the control panel.

Important: To avoid data loss, it is recommended to shutdown the operating system on your instance first. Login to your instance as root and execute the halt command.

1 . From your instances overview page, click on OFF to power off the instance:

2 . A pop up appears, verify that you have shut down the operating system on your instance before clicking on Power off this instance:

Important: This operation takes some time, as your local volumes will be transferred to a secure storage cluster. You won’t be able to restart your server immediately. If your server has a DSSD, remember that it will be totally erased without any possible recovery.

Attaching a Volume to an Existing Instance

In the Control Panel, click Volumes in the compute section.

Creating a New Volume

1 . Click the Create Volume button.

2 . The volume-creation window displays. Enter the required information for your volume:

  • The physical location of the volume
  • The name of your volume
  • The size in GB

Attaching an Existing Volume to an Instance

1 . In the Volumes list click on Attach to server next to the concerned volume.

2 . In the “Attach Volume” window, select the instance on which you want to attach the volume.

3 . Once the volume is attached to your instance, power on your instance by clicking on the greyed out OFF button:

4 . You can use lsblk to determine its name. Please note that the name might be different depending on the instance type you use. It might be something like /dev/nbdX for a Bare Metal instance or /dev/vdX for a Virtual Cloud Instance.

As exemplified below, the additional volume is named vdb:

root@scw-8838b4:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda     252:0    0 46.6G  0 disk
|-vda1  252:1    0 46.5G  0 part /
`-vda15 252:15   0  100M  0 part /boot/efi
vdb     252:16   0 46.6G  0 disk

Formatting the additional volume

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

1 . 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

Mounting an additional volume manually

1 . 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

Mounting an additional volume 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 instance.

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

2 . 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

3 . 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.

4 . 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.

5 . Now reload systemd: systemctl daemon-reload

6 . Launch the script to mount the volume: systemctl start mnt-data.mount 7 . 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

Detaching a volume from an existing instance

1 . On the details page of a instance, click on Volumes to view the list of connected volumes.

2 . Click on “Detach”, then confirm that you want to detach the volume:

Discover a New Cloud Experience

Deploy SSD Cloud Servers in seconds.