Mounting Block Storage in Linux

Cloud Guides & Tutorials

Mount Block Storage in your sy...

Mounting Block Storage in Linux

To partition and mount your Block Storage in a Linux system follow this guide.

Mount Block Storage in Linux

Once you connect to your instance run lsblk to view the current drives:

Text

1 [root@vm-qb11p1fjc ~]# lsblk
2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
3 sr0 11:0 1 1024M 0 rom
4 vda 253:0 0 40G 0 disk
5 ├─vda1 253:1 0 1G 0 part /boot
6 └─vda2 253:2 0 37G 0 part /
7 vdb 253:16 0 100G 0 disk

[root@vm-qb11p1fjc ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 1024M 0 rom
vda 253:0 0 40G 0 disk
├─vda1 253:1 0 1G 0 part /boot
└─vda2 253:2 0 37G 0 part /
vdb 253:16 0 100G 0 disk



New Block Storage devices are shown as unpartitioned drives. In the above case it's the vdb drive.
First you need to partition the drive. For that use the fdisk command:

fdisk /dev/vdb

This will bring a commandline menu:

Text

1 [root@vm-qb11p1fjc ~]# fdisk /dev/vdb
2 Welcome to fdisk (util-linux 2.37.4).
3 Changes will remain in memory only, until you decide to write them.
4 Be careful before using the write command.
5
6 Device does not contain a recognized partition table.
7 Created a new DOS disklabel with disk identifier 0x6fe3ef1e.
8
9 Command (m for help):

[root@vm-qb11p1fjc ~]# 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 0x6fe3ef1e.
Command (m for help):



To create a new partition press n:

Text

1 Command (m for help): n
2 Partition type
3 p primary (0 primary, 0 extended, 4 free)
4 e extended (container for logical partitions)
5 Select (default p):

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):



Select p for primary.
Leave the Partition number, First sector and Last sector with the default values. This will partition the full drive.

Text

1 Select (default p): p
2 Partition number (1-4, default 1):
3 First sector (2048-209715199, default 2048):
4 Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199):
5
6 Created a new partition 1 of type 'Linux' and of size 100 GiB.
7
8 Command (m for help):

Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199):
Created a new partition 1 of type 'Linux' and of size 100 GiB.
Command (m for help):



To view the created partition table press p.

Text

1 Command (m for help): p
2 Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 sectors
3 Units: sectors of 1 * 512 = 512 bytes
4 Sector size (logical/physical): 512 bytes / 512 bytes
5 I/O size (minimum/optimal): 512 bytes / 512 bytes
6 Disklabel type: dos
7 Disk identifier: 0x6fe3ef1e
8
9 Device Boot Start End Sectors Size Id Type
10 /dev/vdb1 2048 209715199 209713152 100G 83 Linux
11
12 Command (m for help):

Command (m for help): p
Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x6fe3ef1e
Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 209715199 209713152 100G 83 Linux
Command (m for help):



Once you are done press w to write the changes.
Now the partition has been created, can verify with lsblk.

Text

1 Command (m for help): w
2 The partition table has been altered.
3 Calling ioctl() to re-read partition table.
4 Syncing disks.
5
6 [root@vm-qb11p1fjc ~]# lsblk
7 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
8 sr0 11:0 1 1024M 0 rom
9 vda 253:0 0 40G 0 disk
10 ├─vda1 253:1 0 1G 0 part /boot
11 └─vda2 253:2 0 37G 0 part /
12 vdb 253:16 0 100G 0 disk
13 └─vdb1 253:17 0 100G 0 part

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@vm-qb11p1fjc ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 1024M 0 rom
vda 253:0 0 40G 0 disk
├─vda1 253:1 0 1G 0 part /boot
└─vda2 253:2 0 37G 0 part /
vdb 253:16 0 100G 0 disk
└─vdb1 253:17 0 100G 0 part



Next you will have to format the drive with the preffered file system. This can be done with the mkfs commands. In this case we will make an ext4 partition so we will use the mkfs.ext4 command.

Text

1 [root@vm-qb11p1fjc ~]# mkfs.ext4 /dev/vdb1
2 mke2fs 1.46.5 (30-Dec-2021)
3 Discarding device blocks: done
4 Creating filesystem with 26214144 4k blocks and 6553600 inodes
5 Filesystem UUID: 4e4cde18-8662-4e76-9e0d-e6f8d9a353db
6 Superblock backups stored on blocks:
7 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
8 4096000, 7962624, 11239424, 20480000, 23887872
9
10 Allocating group tables: done
11 Writing inode tables: done
12 Creating journal (131072 blocks): done
13 Writing superblocks and filesystem accounting information: done

[root@vm-qb11p1fjc ~]# mkfs.ext4 /dev/vdb1
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 26214144 4k blocks and 6553600 inodes
Filesystem UUID: 4e4cde18-8662-4e76-9e0d-e6f8d9a353db
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done



Once the format is complete you can mount the drive with the mount command. In this case we will mount the drive to the /mnt directory with mount /dev/vdb1 /mnt.
You can view the mounted drive with the lsblk command.

Text

1 [root@vm-qb11p1fjc ~]# lsblk
2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
3 sr0 11:0 1 1024M 0 rom
4 vda 253:0 0 40G 0 disk
5 ├─vda1 253:1 0 1G 0 part /boot
6 └─vda2 253:2 0 37G 0 part /
7 vdb 253:16 0 100G 0 disk
8 └─vdb1 253:17 0 100G 0 part /mnt

[root@vm-qb11p1fjc ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 1024M 0 rom
vda 253:0 0 40G 0 disk
├─vda1 253:1 0 1G 0 part /boot
└─vda2 253:2 0 37G 0 part /
vdb 253:16 0 100G 0 disk
└─vdb1 253:17 0 100G 0 part /mnt



Persist the mount

To make drive stays mounted after reboots you must add it in the /etc/fstab file.
Fist get the UUID of the partition with the blkid command.

Text

1 [root@vm-qb11p1fjc ~]# blkid
2 /dev/vda2: UUID="dbfed337-0438-4685-8a2e-eed84bb9e46a" TYPE="xfs" PARTUUID="11ec2d3d-02"
3 /dev/vdb1: UUID="4e4cde18-8662-4e76-9e0d-e6f8d9a353db" TYPE="ext4" PARTUUID="6fe3ef1e-01"
4 /dev/vda1: UUID="90b9c72b-b26b-4c27-a83c-fcdad7d45178" TYPE="xfs" PARTUUID="11ec2d3d-01"

[root@vm-qb11p1fjc ~]# blkid
/dev/vda2: UUID="dbfed337-0438-4685-8a2e-eed84bb9e46a" TYPE="xfs" PARTUUID="11ec2d3d-02"
/dev/vdb1: UUID="4e4cde18-8662-4e76-9e0d-e6f8d9a353db" TYPE="ext4" PARTUUID="6fe3ef1e-01"
/dev/vda1: UUID="90b9c72b-b26b-4c27-a83c-fcdad7d45178" TYPE="xfs" PARTUUID="11ec2d3d-01"



Copy the UUID of the drive and edit the /etc/fstab file like this.

Text

1 UUID=dbfed337-0438-4685-8a2e-eed84bb9e46a / xfs defaults 0 0
2 UUID=90b9c72b-b26b-4c27-a83c-fcdad7d45178 /boot xfs defaults 0 0
3 #


4 UUID=4e4cde18-8662-4e76-9e0d-e6f8d9a353db /mnt ext4 defaults 0 0

UUID=dbfed337-0438-4685-8a2e-eed84bb9e46a / xfs defaults 0 0
UUID=90b9c72b-b26b-4c27-a83c-fcdad7d45178 /boot xfs defaults 0 0

UUID=4e4cde18-8662-4e76-9e0d-e6f8d9a353db /mnt ext4 defaults 0 0



For more information about the fstab file we recommend reading this guide.

Docs powered by Archbee

Persist the mount

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Press space bar to start a drag.
When dragging you can use the arrow keys to move the item around and escape to cancel.
Some screen readers may require you to be in focus mode or to use your pass through key

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us