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.