To set the swap priority in Linux, you can use the swapon command with the -p option. The priority determines the order in which swap spaces are used; lower numbers indicate higher priority.
Steps to Set Swap Priority:
Identify Swap Devices: First, check your current swap devices using:
swapon --showTurn Off Swap: If you need to change the priority of an active swap device, turn it off:
sudo swapoff /dev/sdXReplace
/dev/sdXwith your swap device.Set Swap Priority: Use the
swaponcommand to set the priority:sudo swapon -p <priority> /dev/sdXReplace
<priority>with the desired priority value and/dev/sdXwith your swap device.Verify Changes: Check the swap priorities again:
swapon --show
Example:
To set the priority of /dev/sda2 to 10:
sudo swapoff /dev/sda2
sudo swapon -p 10 /dev/sda2
Feel free to ask if you need more information!
