Formatting Block Storage
April 16, 2025
Formatting a block storage device, like a hard drive or a flash drive, is the process of making the drive usable for storage. It consists of two steps:
- Format the partitions of the drive. These are logical sections of memorythat can have distinct filesystems, mount points, etc.
- Make filesystems on the partitions. This allows your computer to write files to the partitions when the device is mounted.
Format the Partitions
Use fdisk
to manage the partitions on the block device. Start the process with
fdisk <device>
where <device>
is e.g. /dev/sda
.
You can tap m
for help with the different commands. p
prints the partition table. d
deletes a partition. n
creates a partition.
When creating a partition, select p
for a primary partition. You’ll then be prompted for a partition number (1-4), and then sector sizes. The first sector is for the partition table, and the last sector is for the actual data.
When you like what you have, w
will write the new partitions to the device.
Make the Filesystem
Once the partition has been made, you can make the filesystem using mkfs
. For linux, use mkfs.ext4
.
mkfs.ext4 -L <label> <device partition>
where <label>
is a human readable label for the device, and <device partition
is e.g. /dev/sda1
.
You can add -n
for a dry run.
After that, you can mount
your newly formatted device with mount <device partition> <mountpoint>
e.g. mount /dev/sdb1 /media/sandisk
.