unix

How do I resize swap on an LVM on my Linux server?

If your swap partition is on a logical volume it can be resized without rebooting your system using a few easy steps.

You will need additional free space to be able to expand it or you can possibly shrink another volume or add another physical disk into your volume group.

1. # grep swap /etc/fstab

/dev/VolGroup00/LogVol01 swap swap defaults 0 0

2. Run the lvdisplay to see the size of your logical volume.

# lvdisplay /dev/VolGroup00/LogVol01

— Logical volume —
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID AZ143-B8kp-z9KV-JYtG-N997-JOQ6-ETaJaJ
LV Write Access read/write
LV Status available
# open 1
LV Size 4096.00 MB
Current LE 24
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1

3. To resize an LVM you need to unmount it, or in this case turn swap off.

# swapoff /dev/VolGroup00/LogVol01

4. To resizing the volume to add 1 GB (assuming you have the space to extend into) use the lvresize command.

# lvresize /dev/VolGroup00/LogVol01 -L +1G
Extending logical volume LogVol01 to 5 GB
Logical volume LogVol01 successfully resized

5. Next turn swap back on.

# swapon /dev/VolGroup00/LogVol01
# free -m
total used free shared buffers cached
Mem: 16384 13343 3042 0 48 120
-/+ buffers/cache: 174 201
Swap: 5120 0 5120

6. If you encounter an issue trying to mount swap, repeat step 3.

# swapoff /dev/VolGroup00/LogVol01

After that, run

# mkswap /dev/VolGroup00/LogVol01

7. After mkswap completes, repeat step 5.

# swapon /dev/VolGroup00/LogVol01

8. Validate the swap space again by running free -m.

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top