it is not possible to change uuid of a swap partition with tune2fs, because it only supports ext3/ext4.

you will have to recreate it and pass the uuid during creation, which is not a problem because usually swap SHOULD not contain any valuable data.

mkswap -U 410f0b20-edca-4db2-a8f6-3e82d29602e7 /dev/sda5


If your swap device uuid changes you will have to update several other config files:

  • /etc/fstab
  • /etc/initramfs-tools/conf.d/resume
  • god knows what else

it happened to me, that dmesg showed me that it got stuck for 30seconds during boot by not finding the uuid of swap in /etc/fstab or resume

vim /etc/grub

# remove quiet in order to get some output during boot and debug what is happening and where it gets stuck.

update-grub2; # do not forget to run after changes

so it is probably wiser to just restore the existing uuid, when you zeroed out the harddisk (in order to make a backup that saves some space)

how to zero out swap space, before backup:

# where is my swap?
/dev/sda5 partition 7.7G   0B   -1
# what uuid does swap have?
blkid /dev/sda5
/dev/sda5: UUID="410f0b20-edca-4db2-a8f6-3e82d29602e7" TYPE="swap" PARTUUID="9c1c254e-05"

# label it as swap
tune2fs /dev/sda5 -L swap

# deactivate swap
swapoff /dev/sda5;
# overwrite swap partition with zeroes that compress well with gzip
time dd if=/dev/zero of=/dev/sda5 bs=$((1024*1024));

# maybe also zero out root partition/harddisk
time dd if=/dev/zero of=/fill_up_space bs=$((1024*1024*1024)) count=$((10*9999));rm -rf /fill_up_space;

# recreate swap
mkswap -U 410f0b20-edca-4db2-a8f6-3e82d29602e7 /dev/sda5

# activate swap
swapon /dev/sda5

# check how much swap is used (nill)
free -m
              total        used        free      shared  buff/cache   available
Mem:           7678         725        6501          94         450        6630
Swap:          7876           0        7876

now you can run the backup:

boot/buy from my stick and attach external usb harddisk to save backup file to.

lsblk; # where is what
umount /dev/sda*;
dd if=/dev/sda | pv | gzip -c > /media/user/BACKUPS/Debian94.img.gz;

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!