How to Mount and Use a Block Device

Block Storage - Overview

Block storage volumes are additional volumes that you can connect to your Virtual Instances.

The block storage technology breaks files into smaller pieces, also called chunks, or simply blocks). Each of these pieces can be stored separately and under a unique address anywhere in the storage system. This way of storing data makes block storage ideal for latency critical applications such as transactional databases or mission-critical data as it is faster, latency-wise, than a traditional file-storage device.

In this tutorial you will learn how to format and mount a block storage volume that you have created for your Virtual Instance.

Requirements:

Verifying the Device Availability

1 . Connect to your instance with ssh:

ssh root@<your_instance_ip>

2 . Use the lsblk command to make sure your block volume is available:

root@scw-festive-agnesi:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0 23.3G  0 disk
vda     252:0    0 18.6G  0 disk
├─vda1  252:1    0 18.5G  0 part /
└─vda15 252:15   0  100M  0 part /boot/efi

Your can see your block volume named sda with the chosen storage size.

Note: The Scaleway ecosystem uses GiB to define storage sizes and not GB as the default on linux.

Formatting the Block Volume

You can now format your block volume.
If you do not know which file system to use, you probably want to use ext4.

root@scw-festive-agnesi:~# mkfs.ext4 /dev/sda

Make sure your file system is correctly created by running the lsblk -f command.

root@scw-festive-agnesi:~# lsblk -f
NAME    FSTYPE LABEL UUID                                 MOUNTPOINT
sda     ext4         925c2c17-ca8c-493a-a9cd-b475d87fd276
vda
├─vda1  ext4   root  8509fe04-d91c-410a-9087-c5d34537d3ae /
└─vda15 vfat         B3E7-7040                            /boot/efi

Check if the FSTYPE field matches ext4 for your block volume.

Mounting the Block Volume

Once your file system is created, you need to mount it.

1 . Create the mount point. In this tutorial, we choose /mnt/block-volume.

root@scw-festive-agnesi:~# mkdir /mnt/block-volume

2 . Then, mount it. It is recommended to use the defaults option:

       **defaults**
            Use  the  default  options: **rw**, **suid**, **dev**,
            **exec**, **auto**, **nouser**, and **async**.

If you want to see all available options, you can run man mount on your instance.

root@scw-festive-agnesi:~# mount -o defaults /dev/sda /mnt/block-volume

3 . Make sure your file system is properly mounted by running the lsblk command.

root@scw-festive-agnesi:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0 23.3G  0 disk /mnt/volume-block
vda     252:0    0 18.6G  0 disk
├─vda1  252:1    0 18.5G  0 part /
└─vda15 252:15   0  100M  0 part /boot/efi

Check the MOUNTPOINT field.

Using fstab for Persistent Mounting

With the current configuration, the block device will not be mounted automatically upon reboot.
You might want your file system to survive the reboot.
The fstab file is there for you!

Add this line to the /etc/fstab file of your instance:

echo '/dev/sda /mnt/volume-block ext4 defaults 0 0' >> /etc/fstab

Umounting the Volume / Mounting it Elsewhere

1 . umount the volume to remove it from your current setup:

root@scw-festive-agnesi:~# umount /mtn/volume-block

2 . Check with lsblk that the volume is no longer mounted in the system:

root@scw-festive-agnesi:~# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0 23.3G  0 disk
vda     252:0    0 18.6G  0 disk
├─vda1  252:1    0 18.5G  0 part /
└─vda15 252:15   0  100M  0 part /boot/efi

Important: Do not forget to edit the /etc/fstab file and delete the line corresponding to your block volume.

Also, you may want to change the mount point. You can mount it elsewhere.
Please refer to the Mounting the block volume section above.
Do not forget to edit the /etc/fstab file and update the line corresponding to your block volume with the new mount point.

Discover a New Cloud Experience

Deploy SSD Cloud Servers in seconds.