How permanently change Linux swap disk priority
Solution 1
All seems fine.
pri=-1
and pri=-2
in your fstab
means sda1
is a priority.
If you want the inverse, remove the '-'
. You should have sw,pri=1
for sda1
and sw,pri=2
for sda2
.
Reboot and re-check.
Solution 2
Yes, but trying to set a negative priority doesn't work; we are only allowed to use positive numbers. To tell the system to use a given swap partition or file before another one, assign a larger positive number to it in fstab.
Solution 3
It looks like the pri
parameter set to -1 in /etc/fstab
(default value by the way) doesn't affect the priority reported by swapon
. To make it work, you have to change for a bigger number (like 1).
Example that doesn't work:
# swap was on /dev/sdb2 during installation
UUID=b42f6c79-d6c8-4b7e-a5e3-468d83f30146 none swap sw,pri=-1 0 0
# swap was on /dev/sdc2 during installation
UUID=ead96714-efdf-4758-8124-a79aa98dd052 none swap sw,pri=-1 0 0
But swapon return is:
$ swapon -s
Filename Type Size Used Priority
/dev/sdb2 partition 2096832 5652 -1
/dev/sdc2 partition 2096832 0 -2
On the other hand
# swap was on /dev/sdb2 during installation
UUID=b42f6c79-d6c8-4b7e-a5e3-468d83f30146 none swap sw,pri=1 0 0
# swap was on /dev/sdc2 during installation
UUID=ead96714-efdf-4758-8124-a79aa98dd052 none swap sw,pri=1 0 0
Then swapon return gives:
$ swapon -s
Filename Type Size Used Priority
/dev/sdb2 partition 2096832 1741 1
/dev/sdc2 partition 2096832 1635 1
Solution 4
Like said above, assigning priority is done by using a positive value. Negative numbers are used by the kernel. According to: https://lists.debian.org/debian-user/2002/09/msg01075.html
If you don't add a priority yourself, the kernel generates a number for you. And those numbers are negative.
So always use positive values, as they will work, the negative ones will be ignored. If you find out there are negative numbers, you will know they were kernel generated. By using positive numbers you will be avoiding confusion when figuring out why and where those priorities come from.
Related videos on Youtube
tony_sid
Born and raised in California. Computers are my main hobby.
Updated on September 17, 2022Comments
-
tony_sid over 1 year
I’m using two swap disks. Changing the order they are in in
/etc/fstab
and usingpri
infstab
doesn’t seem to have any effect.This is what it looks like in the
/etc/fstab
:#swap on other disk UUID=90a1550c-84d6-4bde-8bc1-7c15292980f1 none swap sw,pri=-1 0 0 #swap on same disk UUID=13b70e65-f1c3-4728-920f-9e92467d1df0 none swap sw,pri=-2 0 0
This is the output of
swapon -s
:Filename Type Size Used Priority /dev/sda1 partition 2562328 176 -1 /dev/sdb1 partition 2562328 0 -2
It’s the opposite of what it is in
fstab
, and changes tofstab
seem to have no effect. -
Aquarius Power about 9 yearsmy fstab doesnt show the swap priority configuration, I wonder how it is being automated here
-
SuperSafie over 4 yearsfrom the swapon man page: "priority is a value between -1 and 32767"