This is done on Debian 11 and I will assume no GPT partition table was used, and thus creates one. If GPT is already installed, you can skip the GPT creation step which would destroy all data on your disk.

Create GPT partition table

When we know our disk (figuring out our disk), we can start fdisk. In this case, I’m editing /dev/sdf.

$ sudo fdisk /dev/sdf

Welcome to fdisk (util-linux 2.33.1).                                               
Changes will remain in memory only, until you decide to write them.                     
Be careful before using the write command.                                                 

Create the partition table:

Command (m for help): g                                                             
Created a new GPT disklabel (GUID: 704ED935-2E40-D44C-BA5A-3A52BD1E2CC3).           

Now create a partition, in this case, I’m only creating a single partition, of 2TB (full disk size).

Command (m for help): n                                                             
Partition number (1-128, default 1):                                                
First sector (2048-3907029134, default 2048):                                       
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3907029134, default 3907029134):

Created a new partition 1 of type 'Linux filesystem' and of size 1.8 TiB.
Partition #1 contains a zfs_member signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Set the partition type, to a Linux RAID type (29)

Open Fdisk, again if it was closed.

sudo fdisk /dev/sdf

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Set the partition type:

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): 29
Changed type of partition 'Linux filesystem' to 'Linux RAID'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Giving a label to your partition

First install gdisk, which allows you to do more with your GPT partition table, then the more generic tool fdisk (which for example also allows MBR).

sudo apt install gdisk

Now, let’s start gdisk with our disk.

sudo gdisk /dev/sdf
GPT fdisk (gdisk) version 1.0.3

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Now let’s give the partition a name (in my case, and since I only have a single partition, I’m giving it the location of the disk right-mid):

Command (? for help): c
Using 1
Enter name: right-mid

And write to disk:

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sde.
The operation has completed successfully.

Finding a partition by label

If you followed the steps above it should show up in /dev/disk/by-partlabel/:

$ ls -l /dev/disk/by-partlabel/
total 0
lrwxrwxrwx 1 root root 10 Dec 27 12:00  left-bottom -> ../../sdf1

Let’s create a RAID 5 with labeled partitions

Since I have six disks, stored in two columns, and six rows, I used a {left, right}-{top, mid, bottom} naming scheme.

sudo mdadm --create --verbose --level=5 --raid-devices=6 /dev/md0 /dev/disk/by-partlabel/left-bottom /dev/disk/by-partlabel/left-mid /dev/disk/by-partlabel/left-top /dev/disk/by-partlabel/right-bottom /dev/disk/by-partlabel/right-mid /dev/disk/by-partlabel/right-top

Progress of RAID creation can be followed in /proc/mdstat:

watch -n 1 cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid5 sdd1[6] sde1[4] sdc1[3] sda1[2] sdb1[1] sdf1[0]
      9766906880 blocks super 1.2 level 5, 512k chunk, algorithm 2 [6/5] [UUUUU_]
      [==>..................]  recovery = 10.2% (200248524/1953381376) finish=225.0min speed=129839K/sec
      bitmap: 0/15 pages [0KB], 65536KB chunk

unused devices: <none>

Finally, don’t forget to add the reference to the RAID into the mdadm config file:

# mdadm --detail --scan >> /etc/mdadm.conf

This will be inserted:

# mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=kn0:0 UUID=5d06cd5e:9547dab2:641b1a7b:e2427dc7

Formatting the filesystem

You can, of course, just format the disks without setting the blocksize, stride, and stride-width. However, if you do this correctly, you have a more optimized system. To calculate the stride, and stride width I made a small calculator, which calculates these values, and gives you an example command to use. For example like below:

# mkfs.ext4 -v -L RAIDStorage -b 4096 -E stride=128,stripe-width=768 /dev/md0

Please, be careful that you select the correct device (I refer to /dev/md0), if you format the wrong device, you lose all data on that device.

Reset disk

If you want to try again to setup disks in RAID, such that MDADM is not finding any data on the disk from previous tries:

mdadm --zero-superblock /dev/sde

Again, this destroys all data on the specified disk.

Potentially interesting still (not used…):