14

I’m using two swap disks. Changing the order they are in in /etc/fstab and using pri in fstab 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 to fstab seem to have no effect.

4 Answers 4

7

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.

1
  • my fstab doesnt show the swap priority configuration, I wonder how it is being automated here Feb 25, 2015 at 21:12
5

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.

1
  • 1
    from the swapon man page: "priority is a value between -1 and 32767"
    – golimar
    Dec 11, 2019 at 7:57
4

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
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.