16th July 2010
In short: sudo mkswap -L new_swap_label -U old_swap_UUID /dev/sd_swap_device.
If you don’t care about the UUID: just sudo mkswap -L new_swap_label /dev/sd_swap_device.
- Identify current swap UUID: grep swap /etc/fstab ; you should see a line starting with UUID=b4e6e… – note that UUID; let us assume our UUID is b4e6e5d8-8854-4a3e-8edb-f423ded31e2a
- Identify swap partition device. If you are using Debian or Ubuntu, device might have been shown to you when running command #1 as a comment of the form
# /dev/sdX4 none swap sw 0 0
Just to be sure, run cat /proc/swaps (or sudo swapon -s), to be shown something like this:
Filename Type Size Used Priority
/dev/sdX4 partition 2104504 0 -1
You can also use partition managers to identify swap device, e.g. sudo fdisk -l. Let us assume our partition device is sdX4.
- If that swap partition is in use, you need to disable it first: sudo swapoff /dev/sdX4
- Now that you have both the UUID and the device, run
sudo mkswap -L new_swap_label -U b4e6e5d8-8854-4a3e-8edb-f423ded31e2a /dev/sdX4
Do not forget replacing sample values above (label, UUID and device) with your actual values.
- Enable swap: sudo swapon /dev/sdX4
Now, if you wish so, you may proceed to edit /etc/fstab and replace UUID=…. with LABEL=your_new_swap_label, leaving all other spaces and values in that line untouched.