Add Block Storage to Cloud Server with Linux

After creating a Block Storage volume in the Cloud Panel and assigning it to a server, Linux servers will need to be configured to access the new Block Storage. Learn how to add Block Storage to a Cloud Server with Linux.

Scenario 1: Assign Block Storage as Separate Storage

Connect to the server with SSH, then use the lsblk command to list all available block storage devices:

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  120G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0  119G  0 part
  ├─centos-root 253:0    0  117G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0  200G  0 disk
sr0              11:0    1 1024M  0 rom

NOTE The Block Storage device will only need to be formatted the first time you use it. If you detach the Block Storage device then attach it to another server, do not format the device.

Formatting the Block Storage device will erase all data on the device.

Use the following command to format the Block Storage device:

[root@localhost ~]# mkfs.<File-System> <Block Storage Name>

In this case we will format our Block Storage with XFS File System:

[root@localhost ~]# mkfs.xfs /dev/sdb

Now, we need to create a mount point for the Block Storage.

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

Next, we mount the Block Storage to our mount point /mnt/block

[root@localhost ~]# mount /dev/sdb /mnt/block

Scenario 2: Assign Block Storage to Extend Server disk space.

Connect to the server with SSH, then use the lsblk command to list all available block storage devices:

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  120G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0  119G  0 part
  ├─centos-root 253:0    0  117G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0  200G  0 disk
sr0              11:0    1 1024M  0 rom

Use the following command to format the Block Storage device:

[root@localhost ~]# mkfs.xfs /dev/sdb

Now, we need create a Partition for our Block Storage using fdisk, in order to create Physical Volume Group.

[root@localhost mnt]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0xfc537643.

Command (m for help): p

Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 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 label type: dos
Disk identifier: 0xfc537643

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set

Command (m for help): p

Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 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 label type: dos
Disk identifier: 0xfc537643

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   419430399   209714176   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 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 label type: dos
Disk identifier: 0xfc537643

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   419430399   209714176   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost mnt]# partprobe

Now, we create Physical Volume Group.

[root@localhost mnt]# pvcreate /dev/sdb1

Then we list our Physical Volume Groups:

[root@localhost mnt]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <119.00 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              30463
  Free PE               0
  Allocated PE          30463
  PV UUID               3yclEq-3Vje-FkPd-X8NU-Mj8t-ZTcA-skrzFm

  "/dev/sdb1" is a new physical volume of "<200.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               <200.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               YlRvcQ-IvYT-6D9A-jrdI-bzPV-IFc7-FCJqxA

Then, we need to Extend our existing Volume Group, the existing Volume Group name is centos

[root@localhost mnt]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended

Finally, we proceed with Extending our centos Volume Group.

[root@localhost mnt]# lvextend -l +100%FREE /dev/mapper/centos-root

Then, we apply File System changes.

[root@localhost mnt]# xfs_growfs /dev/mapper/centos-root

Now the Server disk has been Extended.

Mohammed has written 29 articles

One thought on “Add Block Storage to Cloud Server with Linux

Cancel reply

Leave a Reply to sirgliofrei

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>