Valid for migrated Cloud Servers.

This article explains how to integrate, format, and configure a block storage as a mount point on a migrated Linux Cloud Server.

If you assign a block storage to a migrated Cloud Server with Linux, you must then mount it on the server. To mount a block storage on your server, complete the following:

Requirements

  • You have created a block storage.
  • You have assigned the block storage to the server.
  • You have logged in to the server as an administrator.

Create partition

  • To list the block storage assigned to the server, enter the following command:

    [root@localhost ~]# lsblk

    After entering the command, all important information about the available data carriers and the assigned block storage is displayed. Example:

    [root@localhost ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
    vda 252:0 0 30G 0 disk
    ├─vda1 252:1 0 1M 0 part
    ├─vda2 252:2 0 200M 0 part /boot/efi
    ├─vda3 252:3 0 1G 0 part /boot
    └─vda4 252:4 0 28.8G 0 part /
    vdb 252:16 0 5G 0 disc

    In the example above, a block storage with a size of 5 GB is assigned to the server. This has the name vdb.

  • To open up the /dev/vdb partition in fdisk, enter the following command:

    [root@localhost ~]# fdisk /dev/vdb

    After entering the command, the following message is displayed:

    [root@localhost ~]# fdisk /dev/vdb

    Welcome to fdisk (util-linux 2.37.4).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Device does not contain a recognized partition table.
    Created a new DOS disklabel with disk identifier 0x2392d4a9.
    Command (m for help):
    All unwritten changes will be lost, do you really want to quit?

  • To add a partition, enter n. Then press the Enter key. The following message will be displayed:

    Command (m for help): n
    Partition type:
    p primary (2 primary, 0 extended, 2 free)
    e extended

  • To select the partition type Primary, enter p. Then press Enter.

    Select (default p): p

  • Enter the partition number of the partition. Example:

    Partition number (1-4, default 1): 1

  • Enter the start sector. Example:

    First sector (2048-10485759, default 2048): 2048

  • To use the entire available storage space, press Enter. The following information is displayed after the entry:

    Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759):
    Created a new partition 1 of type 'Linux' and of size 5 GiB.

  • To check the modified partition table, enter p. Then press Enter.
  • To write the partition table to the Storage block and exit the program, enter w.
  • Restart the server.

Format partition

If you are using the block storage for the first time, you must format the partition before using it for the first time. If you format the partition, all data on it will be deleted.

To format the partition, enter the command mkfs.ext4 in the following format:

[root@localhost ~]# mkfs.ext4 [name of the block storage]

Example:

[root@localhost ~]# mkfs.ext4 /dev/vdb1
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 1310464 4k blocks and 327680 inodes
Filesystem UUID: f04c0279-3a01-4c34-892c-05af0bb4da5a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

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

The block storage is now formatted.

Attach block storage

  • A mount point must be created so that the block storage can be mounted. To create this, enter the following command:

    [root@localhost ~]# mkdir /mnt/block

  • Open /etc/fstab with the editor (e.g. vi). Enter the following command:

    [root@localhost ~]# vi /etc/fstab

Note

The vi editor has an insert mode and a command mode. You can call up insert mode with the [i] key. In this mode, the characters entered are immediately inserted into the text. To call up command mode, press [ESC]. If you use command mode, your keyboard input is interpreted as a command.

  • Insert the desired mount point in the following format:

    /dev/vdb1 /mnt/block auto defaults 0 0

  • To save the changes, press the ESC key and enter :wq. Then press Enter.
  • To check the new entry in /etc/fstab and mount the block storage immediately, enter the command mount -a. This command mounts all file systems defined in /etc/fstab that are not yet mounted.

    [root@localhost ~]# mount -a

  • Applies to AlmaLinux 8, AlmaLinux 9, Rocky Linux 8, Rocky Linux 9: To restart systemd, enter the following command:

    [root@localhost ~]# systemctl daemon-reload

  • To access the drive, enter the following command:

    [root@localhost ~]# cd /mnt/block