New swap partition doesn't on automatically

Hello to all.
I tried to add a new swap partition by these steps:

  1. dd if=/dev/zero of=/swap bs=1M count 18000
  2. chmod 600 /swap
  3. mkswap /swap
  4. echo /swap none swap sw 0 0' >> /etc/fstab
    but mount -a of reboot wouldn’t up new swap partition.
    do I need any selinux possily?
    what should I do?

You can do:

swapon /swap

if seliux is causing a problem, you can check with:

audit2allow -a /var/log/audit/audit.log

alternatively, do:

setenforce 0
swapon /swap

and see if the swap is active. If any errors, post them in the thread here. Usually when I do swap like you I just do:

fallocate -l 4G /swap
chmod 600 /swap
mkswap /swap
swapon /swap

Swap isn’t mounted like regular filesystems, and the “mount” command doesn’t affect it. You need to run “swapon -a” to activate all known swap partitions and files, “swapon -av” to observe it in action.

hello and thanks.
so, you meant I couldn’t test it with ‘mount -a’ and couldn’t see the result of new ‘/etc/fstab’ unless reboot?

You can mount all the swap partitions in fstab with
swapon -a

Hi,
“mount -a” will only mount all “normal” filesystem, swap is not a “normal” one I would say :).

And as other already says, “swapon -a” will “mount” every swap partition mentioned/configured in /etc/fstab

You can see the swap current size and usage using “free -m | grep Swap” for example.
Or using “top” command.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.