How To Assign UUID to Swap in Raspbian

Here is how I assign an UUID to a swap in Raspbian. I have 2 swap partition at /dev/sda1 and /dev/sda2 each having 2GB of size. Below is the output of blkid command: –

# blkid
/dev/mmcblk0p1: UUID="8DFA-0D4E" TYPE="vfat"
/dev/mmcblk0p2: UUID="1b920f7d-119f-4ecf-8b95-e5cc6a67b8f1" TYPE="ext4"
/dev/sda1: TYPE="swap"
/dev/sda2: TYPE="swap"
/dev/sda3: UUID="e1fb5d19-ff43-cf01-a0b3-5119ff43cf01" TYPE="ext4"

There are two options you can assign an UUID to a swap. Below is first option: –

# mkswap /dev/sda1
Setting up swapspace version 1, size = 2096124 KiB
no label, UUID=676025b5-3710-44f9-b122-e4d60e622f2f
# blkid
/dev/mmcblk0p1: UUID="8DFA-0D4E" TYPE="vfat"
/dev/mmcblk0p2: UUID="1b920f7d-119f-4ecf-8b95-e5cc6a67b8f1" TYPE="ext4"
/dev/sda1: TYPE="swap" UUID="676025b5-3710-44f9-b122-e4d60e622f2f"
/dev/sda2: TYPE="swap"
/dev/sda3: UUID="e1fb5d19-ff43-cf01-a0b3-5119ff43cf01" TYPE="ext4"

Here you can have second option assigning an UUID to a swap: –

# uuidgen -r
7e0375b9-c858-4c68-8ce2-2e25eeddb313
# swaplabel -U 7e0375b9-c858-4c68-8ce2-2e25eeddb313 /dev/sda2
# blkid
/dev/mmcblk0p1: UUID="8DFA-0D4E" TYPE="vfat"
/dev/mmcblk0p2: UUID="1b920f7d-119f-4ecf-8b95-e5cc6a67b8f1" TYPE="ext4"
/dev/sda1: TYPE="swap" UUID="676025b5-3710-44f9-b122-e4d60e622f2f"
/dev/sda2: TYPE="swap" UUID="7e0375b9-c858-4c68-8ce2-2e25eeddb313"
/dev/sda3: UUID="e1fb5d19-ff43-cf01-a0b3-5119ff43cf01" TYPE="ext4"

Next, you can add the following line at /etc/fstab file: –

UUID=676025b5-3710-44f9-b122-e4d60e622f2f       none    swap    sw      0       0
UUID=7e0375b9-c858-4c68-8ce2-2e25eeddb313       none    swap    sw      0       0

Reboot the Raspbian and run command below to verify swap: –

# free -mh

Thank you.

Source: Debian Part-UUID Ubuntu SwapFaq