Formatting and mounting block storage in Linux
Block Storage
Many cloud providers provide the ability to add arbitrary amounts of block storage and present it to compute (usually virtual servers).
In this example, we present block storage to Ubuntu LTS, format it with the ‘ext4’ filesystem and mount it under ‘/backups’.
Given the process to add block storage differs greatly between providers, it is assumed this has already been done.
Partitioning with fdisk
The first command to run ‘fdisk -l’ which runs the program “fixed disks” and provides disk partitioning functions, lists the available storage.
fdisk -l
The disk we’re interested in isn’t the first disk as this is for the running system, but the 2nd one. In the above example, observe ‘/dev/vdb’.
Next to add a partition taking up the entire disk.
Commands:
fdisk /dev/vdb # we found /dev/vdb above using fdisk -l
n # new partition
(enter) # using default choice of 'Primary'
(enter) # using the default partition number '1'
(enter) # using default 'First sector 2048'
(enter) # using default 'last sector'
w # write the new partition to disk
fdisk -l #check for the newly created partition: /dev/vdb1
Format with ext4 filesystem
Commands:
mkfs.ext4 /dev/vdb1 # writes out the ext4 filesystem on the partition
mkdir /backups # change to whatever other mountpoint you want to use as required
echo "/dev/vdb1 /backups ext4 defaults,noatime,nodiratime,nofail 0 0" >> /etc/fstab # mount using fstab
mount -a # mount all from fstab, this ensures it will mount successfully next reboot too
That’s it! Job done and block storage mounted and ready for use.