Many new Linux users get introduced to fdisk as the go-to tool for disk partitioning. But when it comes to particular drives, like 16TB or larger, you have to use the newer and much simpler parted Linux tool.
In this article, I will provide a quick and dirty guide on configuring a new external drive that can be used for backup. I used a dual disk RAID0 external HDD case which provided a whooping 32TB of storage, used for air-gapped backups.
Making use of a disk has three parts. Partitioning the drive, formatting the drive with a filesystem, and mounting the drive to your filesystems for access. This guide will only focus on the first two parts, Partitioning, and formatting. How the drive is mounted and used is outside of the scope of this article.
Partition
parted
Before starting to partition the drive you need to know what it's named in the Linux file system. The easiest way to get this is to print all the block devices before and after the device is connected. Block devices is a fancy (computer science correct) way of saying devices that store data in block. In other words storage devices.
Below is a terminal dump before the external drive cabinet was connected:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 4K 1 loop /snap/bare/5
nvme0n1 259:0 0 476,9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 476,4G 0 part /var/snap/firefox/common/host-hunspell/
This is after it got connected:
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 4K 1 loop /snap/bare/5
sda 8:0 0 29,1T 0 disk
nvme0n1 259:0 0 476,9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 476,4G 0 part /var/snap/firefox/common/host-hunspell/
From the outputs, you can see that the connected drive, is named "sda". From the terminal dump, it's also easy to see that it has no partitions.
To create a single partition that conver the entire RAID0 on the external HDD case we will use "parted"
sudo parted /dev/sda
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt
(parted) quit
the "mktable gpt" command creates a GUID Partition Table (GPT). This is used to store information about the partitions on the RAID0.
Next creat a new partition spanning the entire disk:
sudo parted /dev/sda
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart LVM ext4 0% 100%
(parted)
(parted)
(parted) print
Model: H/W RAID 0 (scsi)
Disk /dev/sda: 32,0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 33,6MB 32,0TB 32,0TB ext4 LVM
(parted) quit
The "mkpart LVM ext4 0% 100%" command creates a "partition of the type Logical Volume, which supports the ext4 file system. The partition, starts at the beginning of the RAID (the 0% mark) and ends at the end of the RAID (the 100% mark).
After the portion was created checked that the partition was created by running the "print" command to print the entire partition table.
If you want to create more partitions, simply make each partition start where the previous one ended.
Now the partitioning was completed, and parted could be exited by running the "quit" command.
Control that a partition was created, spanning the entire drive by listing all bock devices.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 4K 1 loop /snap/bare/5
sda 8:0 0 29,1T 0 disk
└─sda1 8:1 0 29,1T 0 part
nvme0n1 259:0 0 476,9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
└─nvme0n1p2 259:2 0 476,4G 0 part /var/snap/firefox/common/host-hunspell
As you can see from the terminal dump above, the partition was successfully created on the drive "sda", and named "sda1".
Format
Create the file system
Now the only thing remaining is to create a new filesystem on the partition spanning the entire RAID. Without a filesystem, it's impossible to store data on the RAID.
Run the mkfs.ext4 command to create a ext4 files system on the RAID named "sda1":
sudo mkfs.ext4 /dev/sda1
mke2fs 1.46.5 (30-Dec-2021)
/dev/sda1 alignment is offset by 512 bytes.
This may result in very poor performance, (re)-partitioning suggested.
Creating filesystem with 7812910670 4k blocks and 488308736 inodes
Filesystem UUID: 83b01009-5eb3-437d-b0a6-c5598830b738
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
2560000000, 3855122432, 5804752896
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
As you can read from the terminal dump above, the filesystem was successfully created.
Congratulations! You can now mount it to your filesystem and use it as you please 🎉