Quickly Setting up a Storage Device

Brandon Rozek

January 12, 2020

This post exists mostly to aid myself for when I buy new drives for my home server. It’s a quick and easy way to create an ext4 filesystem over the entire drive.

To go through this post, you’ll need to know the name of your drive.

sudo fdisk -l

or

lsblk

The drive is most likely one of the larger devices with no partitions set. It’ll likely be of the format /dev/sdX.

To begin, we’ll have to set the label. Here we’ll use gpt.

sudo parted /dev/sdX mklabel gpt

Then we can create a primary partition formatted with ext4 covering the entire device.

sudo parted -a opt /dev/sdX mkpart primary ext4 0% 100%

Now we can let ext4 format the drive,

sudo mkfs.ext4 /dev/sdX1

I like to set up my mount points to be /mnt/data/N where N is the number of the drive I’m working with.

sudo mkdir /mnt/data/N

To temporarily mount it, just to make sure it works you can run

sudo mount /dev/sdX1 /mnt/data/N

You can unmount it with umount

sudo umount /dev/sdX1

When you’re ready to make it permanent, we’ll have to edit the /etc/fstab file. We should note the drive by its UUID so that it’s not dependent on the slot the hard drive sits in. You can find it by running this command

lsblk -o UUID /dev/sdX1

Now you can append your /etc/fstab with the following:

UUID=uuid-here /mnt/data/N ext4 defaults 0 0