Home Server Disk Setup

2024-06-30

Disclaimer: I am not a sys admin. This is just a note of how I setup my disk of my home server, and not a guide. Take your own risk if you follow my note to setup your disks.


I use a 2-bay DAS for my disks. I don’t have that much data to store. Thus, a 2-bay DAS is good enough. If I have more data in the future, I may get disks with larger storage instead of a 4-bay DAS.

I am not a fan of RAID. Lots of softwares help users to build RAID automatically, but I am not sure how to restore or migrate my data whenver I want to switch to another disks. RAID increases complexity, so I would avoid doing that, unless I have more knowledge about it.

The first step whenever receiving a disk is to format. Get the path and identifier of the disks by sudo fdisk -l. It may be /dev/sda or /dev/sdb.

I would like to encrypt the whole disk to secure my data. It can skipped if you don’t care that.

cryptsetup luksFormat /dev/sda
cryptsetup luksFormat /dev/sdb
cryptsetup open /dev/sda mario
cryptsetup open /dev/sdb luigi
# /dev/sda will now be unlocked and mapped to /dev/mapper/mario,
# while /dev/sdb will be /dev/mapper/luigi

To make them unlocked during boot time, append /etc/crypttab with lines like below. Remember to replace the UUID with the real ones. The UUID can be get by blkid /dev/sda and blkid /dev/sdb.

mario         UUID=uuid-of-dev-sda        none    timeout=180
luigi         UUID=uuid-of-dev-sdb        none    timeout=180

Now the encryption part is done.

Create a BTRFS file system:

mkfs.btrfs /dev/mapper/mario
mkfs.btrfs /dev/mapper/luigi

Mount them:

mount -t btrfs --mkdir -o noatime,compress=zstd,autodefrag \
  /dev/mapper/mario /mnt/mario
mount -t btrfs --mkdir -o noatime,compress=zstd,autodefrag \
  /dev/mapper/luigi /mnt/luigi

Edit /etc/fstab to mount them automatically:

/dev/mapper/mario /mnt/mario btrfs noatime,compress=zstd,autodefrag 0 2
/dev/mapper/luigi /mnt/luigi btrfs noatime,compress=zstd,autodefrag 0 2

Helpful articles: