Table of Contents

NAS - Build a Linux NAS - Prepare the RAID Disks

Determine the available disks

lsblk

returns:

NAME                   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                      8:0    0 232.9G  0 disk 
├─sda1                   8:1    0  1007K  0 part 
├─sda2                   8:2    0   512M  0 part /boot/efi
├─sda3                 253:28   0     8G  0 part [SWAP]
├─sda4                 253:29   0    58G  0 part /
sdb                      8:32   0  14.6T  0 disk 
sdc                      8:48   0  14.6T  0 disk 
sdd                      8:64   0  14.6T  0 disk 

NOTE: This shows:

  • sda: The boot disk of the host OS. Leave this alone!
  • sdb: A free disk.
  • sdc: A free disk.
  • sdd: A free disk.

The free disks do not have any partitions yet and will be included into a RAID.


Obtain the Serial Numbers of the Disks

hdparm -i /dev/sdd | grep SerialNo

returns:

Model=ST16000NM001G-2KK103, FwRev=SB30, SerialNo=WL2091XL

IMPORTANT: Obtain the serial number for every disk; and keep a record of this somewhere safe.

NOTE: Many disks also have the serial number written on the disk.

The reason for recording the serial number of each disk is that in the case of a disk failure, there needs to be a way to determine which disk has failed and needs to be replaced.

  • The enclosure being used for the disks may not support hot-swapping and there may not be a separate light for each disk, so there may not be a straight-forward way to determine which specific disk has failed.

Test the Disks

All hard drives, both new and old, should be tested before adding them to an array.

See S.M.A.R.T. to view smart data and run smart tests.

Do a short smart test:

smartctl -t short /dev/sdb [-d sat]

Do a long smart test:

smartctl -t long /dev/sdb [-d sat]

Check all smart attributes:

smartctl -a /dev/sdb [-d sat]

Do a random readwrite test:

sudo fio --filename="/dev/sdb --name=randwrite --ioengine=sync --iodepth=1 --rw=randrw --rwmixread=50 --rwmixwrite=50 --bs=4k --direct=0 --numjobs=8 --size=300G --runtime=7200 --group_reporting

NOTE: The smartmontools package might be needed to be installed:

sudo apt install smartmontools
  • -d sat: Sata disks.

See: https://www.smartmontools.org/


Initialize the free disks

sudo fdisk /dev/sdb

returns:

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Device does not contain a recognized partition table.
The size of this disk is 14.6 TiB (16000900661248 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
 
Created a new DOS disklabel with disk identifier 0xc778227a.
 
Command (m for help): 

Create a GPT Partition

Command (m for help): g

returns:

Created a new GPT disklabel (GUID: 6D811672-A5FE-BA4F-8F79-D17E0285C5E1).

NOTE: GPT (GUID Partition Table) is much better than MBR (Master Boot Record) partitions:

  • GPT supports much larger disks.
  • GPT allows for a nearly unlimited number of partitions.
  • GPT also stores cyclic redundancy check (CRC) values to check that its data is intact.
    • If the data is corrupted, GPT can notice the problem and attempt to recover the damaged data from another location on the disk.

Create a Linux RAID Partition

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

returns:

Created a new partition 1 of type 'Linux filesystem' and of size 14.6 TiB.

NOTE: Just taking the default values uses the entire disk.


Command (m for help): p

returns:

Disk /dev/sdb: 14.55 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM001G-2K
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 6D811672-A5FE-BA4F-8F79-D17E0285C5E1
 
Device     Start         End     Sectors  Size Type
/dev/sdb1   2048 31251759070 31251757023 14.6T Linux filesystem

NOTE: This shows that there is a single partition, /dev/sdb1, using the entire disk.


Change the Partition Type

Command (m for help): t
Selected partition 1
Partition type or alias (type L to list all): 29

returns:

Changed type of partition 'Linux filesystem' to 'Linux RAID'.

NOTE: The type is changed to Linux RAID, which is type 29.


Command (m for help): p

returns:

Disk /dev/sdd: 14.55 TiB, 16000900661248 bytes, 31251759104 sectors
Disk model: ST16000NM001G-2K
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: EAA2F832-9810-AA45-9DDB-8ED531C20139
 
Device     Start         End     Sectors  Size Type
/dev/sdd1   2048 31251759070 31251757023 14.6T Linux RAID

NOTE: This shows the Type has been changed to Linux RAID.


Write the Partition Table

Command (m for help): w

returns:

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Partition other Disks

NOTE: Repeat the above instructions for the other free disks.


Check the available disks again

lsblk

returns:

NAME                   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                      8:0    0 232.9G  0 disk 
├─sda1                   8:1    0  1007K  0 part 
├─sda2                   8:2    0   512M  0 part /boot/efi
├─sda3                 253:28   0     8G  0 part [SWAP]
├─sda4                 253:29   0    58G  0 part /
sdb                      8:32   0  14.6T  0 disk 
├─sdb1                   8:33   0  14.6T  0 part 
sdc                      8:48   0  14.6T  0 disk 
├─sdc1                   8:49   0  14.6T  0 part 
sdd                      8:64   0  14.6T  0 disk 
├─sdd1                   8:65   0  14.6T  0 part 

NOTE: This shows the original free disks all now have partitions.

  • At this point, these disks can be tied together as a RAID array.