Partition the New Drive

As mentioned in the introduction, we’ll create a single partition spanning the entire disk in this guide.

Choose a Partitioning Standard

To do this, we first need to specify the partitioning standard we wish to use. GPT is the more modern partitioning standard, while the MBR standard offers wider support among operating systems. If you do not have any special requirements, it is probably better to use GPT at this point.

To choose the GPT standard, pass in the disk you identified like this:

sudo parted /dev/sda mklabel gpt

If you wish to use the MBR format, type this instead:

sudo parted /dev/sda mklabel msdos

Create the New Partition

Once the format is selected, you can create a partition spanning the entire drive by typing:

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

If we check lsblk, we should see the new partition available:

lsblk
OutputNAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   100G  0 disk 
??sda1   8:1    0   100G  0 part 
vda    253:0    0    20G  0 disk 
??vda1 253:1    0    20G  0 part /

Create a Filesystem on the New Partition

Now that we have a partition available, we can format it as an Ext4 filesystem. To do this, pass the partition to the mkfs.ext4 utility.

We can add a partition label by passing the -L flag. Select a name that will help you identify this particular drive:note Make sure you pass in the partition and not the entire disk. In Linux, disks have names like sda, sdb, hda, etc. The partitions on these disks have a number appended to the end. So we would want to use something like sda1 and notsda.

sudo mkfs.ext4 -L datapartition /dev/sda1

If you want to change the partition label at a later date, you can use the e2label command:

sudo e2label /dev/sda1 newlabel

You can see all of the different ways to identify your partition with lsblk. We want to find the name, label, and UUID of the partition.

Some versions of lsblk will print all of this information if we type:

sudo lsblk --fs

If your version does not show all of the appropriate fields, you can request them manually:

sudo lsblk -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT

You should see something like this. The highlighted output indicate different methods you can use to refer to the new filesystem:

OutputNAME   FSTYPE LABEL         UUID                                 MOUNTPOINT
sda                                                              
??sda1 ext4   datapartition 4b313333-a7b5-48c1-a957-d77d637e4fda 
vda                                                              
??vda1 ext4   DOROOT        050e1e34-39e6-4072-a03e-ae0bf90ba13a /