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

King David
  • 433
  • 4
  • 17

3 Answers3

1

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

I know that is outdated question, but hope helps who have some extended rhel5 lifecycle OS, or special agreement with RHEL. :)

You made below steps:

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

But you talk about increase the swap from 6G to 8G. - in this point that is lvextend not lvcreate.

So the steps are following:

swapoff /dev/mapper/rootvg-swap1
lvextend -L +2G /dev/mapper/rootvg-swap1
mkswap /dev/mapper/rootvg-swap1
swapon /dev/mapper/rootvg-swap1
Aaron Copley
  • 12,345
  • 5
  • 46
  • 67
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).

kasperd
  • 29,894
  • 16
  • 72
  • 122