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:
[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
# fdisk /dev/vdb
This will bring a commandline menu:
[root@vm-qb11p1fjc ~]# fdisk /dev/vdbWelcome 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:
Command (m for help): n Partition typep 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.
Select (default p): pPartition 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.
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: 0x6fe3ef1eOnce you are done press w to write the changes. Now the partition has been created, can verify with lsblk.
Command (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks. [root@vm-qb11p1fjc ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 8 sr0 11:0 1 1024M 0 romvda 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 partNext 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.
[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, 8 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: doneWriting inode tables: done Creating journal (131072 blocks): done Writing superblocks and filesystem accounting information: doneOnce 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.
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.
[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.
UUID=dbfed337-0438-4685-8a2e-eed84bb9e46a / xfs defaults 0 0 UUID=90b9c72b-b26b-4c27-a83c-fcdad7d45178 /boot xfs defaults 0 0 # <device> <dir> <type> <options> <fsck> UUID=4e4cde18-8662-4e76-9e0d-e6f8d9a353db /mnt ext4 defaults 0 0For more information about the fstab file we recommend reading this guide.