Cloud Guides & Tutorials
Mount Block Storage in your sy...

Mounting Block Storage in Linux

7min
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 &#x9;\[root\@vm qb11p1fjc ]# lsblk &#x9;name maj\ min rm size ro type mountpoints &#x9;sr0 11 0 1 1024m 0 rom &#x9;vda 253 0 0 40g 0 disk &#x9;├─vda1 253 1 0 1g 0 part /boot &#x9;└─vda2 253 2 0 37g 0 part / &#x9;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 &#x9;\[root\@vm qb11p1fjc ]# fdisk /dev/vdb &#x9;welcome to fdisk (util linux 2 37 4) &#x9;changes will remain in memory only, until you decide to write them &#x9;be careful before using the write command &#x9; &#x9;device does not contain a recognized partition table &#x9;created a new dos disklabel with disk identifier 0x6fe3ef1e &#x9; &#x9;command (m for help) to create a new partition press n &#x9;command (m for help) n &#x9;partition type &#x9; p primary (0 primary, 0 extended, 4 free) &#x9; e extended (container for logical partitions) &#x9;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 &#x9;select (default p) p &#x9;partition number (1 4, default 1) &#x9;first sector (2048 209715199, default 2048) &#x9;last sector, +/ sectors or +/ size{k,m,g,t,p} (2048 209715199, default 209715199) &#x9; &#x9;created a new partition 1 of type 'linux' and of size 100 gib &#x9; &#x9;command (m for help) to view the created partition table press p &#x9;command (m for help) p &#x9;disk /dev/vdb 100 gib, 107374182400 bytes, 209715200 sectors &#x9;units sectors of 1 512 = 512 bytes &#x9;sector size (logical/physical) 512 bytes / 512 bytes &#x9;i/o size (minimum/optimal) 512 bytes / 512 bytes &#x9;disklabel type dos &#x9;disk identifier 0x6fe3ef1e &#x9; &#x9;device boot start end sectors size id type &#x9;/dev/vdb1 2048 209715199 209713152 100g 83 linux &#x9; &#x9;command (m for help) once you are done press w to write the changes now the partition has been created, can verify with lsblk &#x9;command (m for help) w &#x9;the partition table has been altered &#x9;calling ioctl() to re read partition table &#x9;syncing disks &#x9; &#x9;\[root\@vm qb11p1fjc ]# lsblk &#x9;name maj\ min rm size ro type mountpoints &#x9;sr0 11 0 1 1024m 0 rom &#x9;vda 253 0 0 40g 0 disk &#x9;├─vda1 253 1 0 1g 0 part /boot &#x9;└─vda2 253 2 0 37g 0 part / &#x9;vdb 253 16 0 100g 0 disk &#x9;└─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 https //linux die net/man/8/mkfs commands in this case we will make an ext4 partition so we will use the mkfs ext4 command &#x9;\[root\@vm qb11p1fjc ]# mkfs ext4 /dev/vdb1 &#x9;mke2fs 1 46 5 (30 dec 2021) &#x9;discarding device blocks done &#x9;creating filesystem with 26214144 4k blocks and 6553600 inodes &#x9;filesystem uuid 4e4cde18 8662 4e76 9e0d e6f8d9a353db &#x9;superblock backups stored on blocks &#x9; 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, &#x9; 4096000, 7962624, 11239424, 20480000, 23887872 &#x9; &#x9;allocating group tables done &#x9;writing inode tables done &#x9;creating journal (131072 blocks) done &#x9;writing superblocks and filesystem accounting information done once the format is complete you can mount the drive with the mount https //linux die net/man/8/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 &#x9;\[root\@vm qb11p1fjc ]# lsblk &#x9;name maj\ min rm size ro type mountpoints &#x9;sr0 11 0 1 1024m 0 rom &#x9;vda 253 0 0 40g 0 disk &#x9;├─vda1 253 1 0 1g 0 part /boot &#x9;└─vda2 253 2 0 37g 0 part / &#x9;vdb 253 16 0 100g 0 disk &#x9;└─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 https //linux die net/man/8/blkid command &#x9;\[root\@vm qb11p1fjc ]# blkid &#x9;/dev/vda2 uuid="dbfed337 0438 4685 8a2e eed84bb9e46a" type="xfs" partuuid="11ec2d3d 02" &#x9;/dev/vdb1 uuid="4e4cde18 8662 4e76 9e0d e6f8d9a353db" type="ext4" partuuid="6fe3ef1e 01" &#x9;/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 &#x9;uuid=dbfed337 0438 4685 8a2e eed84bb9e46a / xfs defaults 0 0 &#x9;uuid=90b9c72b b26b 4c27 a83c fcdad7d45178 /boot xfs defaults 0 0 &#x9;\# \<device> \<dir> \<type> \<options> \<fsck> &#x9;uuid=4e4cde18 8662 4e76 9e0d e6f8d9a353db /mnt ext4 defaults 0 0 for more information about the fstab file we recommend reading this guide https //linux die net/man/5/fstab