Alexander / Aebian

Who am I?

Musician, Programmer, Linux Geek and what not.  more...

The Categories


Cookie Policy
Media Creations
My Projects

July 21st at 2:28am
S ➠

❬ Back to Blog

Extend swap size on Linux

This post will cover the plain details on how to extend a swap partition. No stories, just facts!

This post just covers the basic details of how to extend the swap space partiton.

First you wanna make sure your disk drive has enough space available for resizing, otherwise you may lose data.
So open up your terminal and type df -h the output will be something like this:

Filesystem            Size  Used Avail Use% Mounted on
                       18G  5.9G   11G  36% /
tmpfs                 3.9G  448K  3.9G   1% /dev/shm
/dev/sda1             477M   33M  419M   8% /boot
/dev/sdc              4.8G   10M  4.6G   1% /db
/dev/sdb               20G   44M   19G   1% /sw
/dev/sdd               20G   44M   19G   1% /data
/dev/sr0              2.8G  2.8G     0 100% /media/ORACLE_12.1_LinuxX64

Make sure your mount point on / has enough space free.
Otherwise free some space up or attach another disk and extend the mount point.
The next thing you want to do is to display the volume group for the device.

In most cases /dev/sda/ with sda1 and sda2 is the default "system drive". So just enter this command: vgdisplay.
After that your output should look like this:

  --- Volume group ---
  VG Name               vg_redhat66tp
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               31jXy7-hIo7-gyid-p9KE-tc0u-45Vr-uDodmR

The VG Name section is our thing we need.
First we need to resize our normal disk and remove some Gigabytes we later on need for adding them to the swap partition.
Enter in the terminal: lvresize /dev/vg_redhat66tp/lv_root -L -2G You get something like:

  WARNING: Reducing active and open logical volume to 15.51 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_root? [y/n]: Y

Accept that and you now have 2 extra Gigabytes free for usage with the swap partition. So lets extend it!
lvresize /dev/vg_redhat66tp/lv_swap -L +2G The output will likely be:

Size of logical volume vg_redhat66tp/lv_swap changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
  Logical volume lv_swap successfully resized

Thats it, you're done!