Formatting and Mounting Additional Volumes

Multiple Volumes Overview

Compute Instances can be launched with the storage divided into several volumes. This can be useful for encrypted volumes, different backup scenarios or to isolate data on different partitions.


Viewing All Volumes

Run lsblk to see all volumes attached to an instance:

vda     252:0    0 116.4G  0 disk
├─vda1  252:1    0 116.3G  0 part /
└─vda15 252:15   0   100M  0 part /boot/efi
vdb     252:16   0  23.3G  0 disk

Formatting Additional Volumes

During instance creation, only the first volume of an instance is being formatted and the OS being installed.

If the volume on an instance has never been formatted, it has to be formatted using mkfs before you can mount it.

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

 mkfs -t ext4 /dev/vdb

The output looks similar to the following example:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 6103515 4k blocks and 1525920 inodes
Filesystem UUID: 6191325f-0bde-4476-8465-176b2d183d60
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

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

Mounting Additional Volumes Manually

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

mkdir -p /mnt/data
mount /dev/vdb /mnt/data
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 Additional Volumes Automatically with systemd

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

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/vdb

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:

Important: The file name of the script must correspond to the path where you mount the volume (/mnt/datamnt-data.mount)*

Description=Mount Volume at boot



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-gallant-wu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  632K  1.6G   1% /run
/dev/vda1       115G  1.9G  108G   2% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/vda15       99M  122K   99M   1% /boot/efi
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/vdb         23G   45M   22G   1% /mnt/data

Discover the Cloud That Makes Sense