Setup redundant swap partition on Proxmox 8

8 July 2025

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 mdadm

Now 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/sda
fdisk /dev/sdb

Using fdisk, we'll use the following key sequence on each drive:

n
4
<enter>
+8GiB
w

Now 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]4

It 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/mdstat

When 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/swap

Edit 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/fstab

After that, we'll reload systemd daemon to refresh to mounts:

systemctl daemon-reload

Reboot and confirm everything is working:

reboot now

Now 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.