1

in my Linux redhat machine ( version 5.x )

I perform the following steps in order to increase the swap from 6G to 8G

 lvcreate -n swap -L 2g /dev/rootvg
 mkswap /dev/mapper/rootvg-swap1
 swapon /dev/mapper/rootvg-swap1

after steps swap increased successfully to 8G

after two days I perform swapoff -a and swapon -a

but I noticed that total swap is only 6G as before my steps !

Please advice what was wrong in my steps – what is missing ?g

0

You should check "/etc/fstab" file first whether there is swap partition entry there or not. "swapon -a" command will check the swap partition entry from "/etc/fstab" and assign swap memory from that partition. You can add line below in fstab.

/dev/mapper/rootvg-swap1 none swap sw 0 0

Than try "swapon -a" command.

0

The reason it didn't work is because you omitted the necessary mkswap command. When you run the mkswap command it will write a header with three pieces of information:

  • How large is the swap space
  • What is the UUID of this swap space
  • A magic value indicating that this partition is swap space

The mkswap command will by default use the actual size of the partiton when writing the header, but you can override that from the command line if you really want to.

When you resize your swap partition but don't rewrite the swap header, the swap header will still contain the old size, and that is what the kernel will use.

Using this command before running swapon should do the job:

mkswap /dev/mapper/rootvg-swap1

If your /etc/fstab uses the UUID to find the swap partition, you need to add a -U argument and tell it the UUID (you can copy-paste the value from your fstab).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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