Today we'll be configuring a mirrored swap partition for swap redundancy. Neither ZFS or BTRFS support swap files, so we must create a swap partition.
Without thinking much about it, one may be inclined to setup a swap partition on each drive and activate them as is; however, swap is effectively the same as RAM and a drive failure is like a stick of RAM suddenly dying. To mitigate this problem, we'll need to create a mirrored partition using mdadm and setup the swap partition on that.
Install mdadm
Proxmox 8 does not come with mdadm by default. Before we begin, we'll install it using apt:
apt update
apt install mdadmNow we'll create the swap partitions on each drive.
Create partitions
We'll be assuming you're using the partions /dev/sda4 and /dev/sbd4. Use fdisk or another disk partitioning tool to create the swap partitions.
fdisk /dev/sdafdisk /dev/sdbUsing fdisk, we'll use the following key sequence on each drive:
n
4
<enter>
+8GiB
wNow we'll create a mirror across these partitions.
Mirror partitions
mdadm --create /dev/md/swap \
--name=swap \
--level=1 \
--raid-devices=2 \
--verbose \
/dev/sd[ab]4It will warn us that we can't use the partition for /boot, ignore the warning and continue.
We'll watch the partitions sync using cat /proc/mdstat:
watch cat /proc/mdstatWhen that's done, press Ctrl+C to exit and continue to the next step.
Configuring swap mirrored partition
Setup swap
mkswap --label swap /dev/md/swapEdit fstab
First we'll make a backup of our fstab file.
cp /etc/fstab /etc/fstab.old
We'll add our swap filesystem's UUID to /etc/fstab.
We need to replacing the UUID with the UUID of our swap partition in this single line command:
UUID=5857c9ac-4a95-4153-8390-d42cc0b12c7b && \
echo "UUID=$UUID none swap defaults 0 0" | \
tee -a /etc/fstabAfter that, we'll reload systemd daemon to refresh to mounts:
systemctl daemon-reloadReboot and confirm everything is working:
reboot nowNow we have redundant, highly available swap on our server.
Final thoughts
If one of the drives fail, the server will keep running and the swap will continue working. When the server is restarted, it will boot but the swap will fail to mount.