I have an Ubuntu 18.04.5 system (ext4) with 1 GB of swap in a logical volume. I need to increase the total swap space to 5 GB.

Currently, I have this configuration:

$ sudo pvs
  PV         VG        Fmt  Attr PSize    PFree
  /dev/sda1  ubuntu-vg lvm2 a--  <931.51g    0 
  /dev/sdb1  ubuntu-vg lvm2 a--    <1.82t    0 
$ sudo vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  ubuntu-vg   2   2   0 wz--n- <2.73t    0 
$ sudo lvs
  LV     VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   ubuntu-vg -wi-ao----  <2.73t                                                    
  swap_1 ubuntu-vg -wi-ao---- 976.00m   
$ sudo pvscan
  PV /dev/sdb1   VG ubuntu-vg       lvm2 [<1.82 TiB / 0    free]
  PV /dev/sda1   VG ubuntu-vg       lvm2 [<931.51 GiB / 0    free]
  Total: 2 [<2.73 TiB] / in use: 2 [<2.73 TiB] / in no VG: 0 [0   ]
$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                Dt0Ebq-IBqb-J2WE-rCNW-lAZ2-BTxf-V45T0f
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2018-11-16 18:18:30 -0700
  LV Status              available
  # open                 1
  LV Size                <2.73 TiB
  Current LE             715153
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                FDmki1-o0Jk-aXP5-bip8-du01-HCoZ-AdFiGC
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2018-11-16 18:18:30 -0700
  LV Status              available
  # open                 2
  LV Size                976.00 MiB
  Current LE             244
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
$ sudo vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <2.73 TiB
  PE Size               4.00 MiB
  Total PE              715397
  Alloc PE / Size       715397 / <2.73 TiB
  Free  PE / Size       0 / 0   
  VG UUID               MU6s8C-OQZp-n7m7-BWF7-JyYi-QRbe-Tq1klP

I read this article Ubuntu – How to modify the size of swap with LVM partitions, and the process seems straightforward. However, I did some more reading, Increase the size of an LVM logical volume, and the process seems much more involved and fraught with serious issues if I make a mistake.

Is the first article correct for my system, or do I need to follow the second article to increase the swap size? I could also just make an additional swap file of 4 GB instead of changing the current swap volume. Is that equivalent to increasing the current 1 GB swap volume from a performance standpoint?



  • 1
    Notice you can simply add another swap LV or an additional swap file without degrading performance. That might be easier than resizing the existing one. Just make sure you add it to /etc/fstab as well.
    – HuHa
    Commented Jul 10, 2021 at 17:20
  • I would not put the swap partition on a logical volume. Do you have other storage available not allocated to the LVM?
    – mondotofu
    Commented Jul 10, 2021 at 17:26
  • @mondotofu: There is absolutely nothing wrong with using an LVM LV as swap. Why do you think that might be bad?
    – HuHa
    Commented Jul 10, 2021 at 17:29
  • There's no need to spread this over multiple devices -- even worse if you're applying a RAID policy on the LV swap volume. It's meant as an immediate storage area to store the process state and related data when the load gets too high to allow other processes to run, and then to read back in as needed. Having the overhead of a logical volume to manage which device and disk blocks to find to enable swap delays the speeding of paging and swapping, and can reduce performance.
    – mondotofu
    Commented Jul 10, 2021 at 17:41
  • All the storage I have is in the LVM in /dev/sda1 and /dev/sdb1. My post is focused on the two articles I cited, which show very different ways to increase my swap size using the LVM. The first article cited is very simple and straightforward, the second one involves many more steps, and indicates that the steps in the first article are actually wrong. I am not sure which one to believe or follow. Do you have any recommendations? Commented Jul 10, 2021 at 22:14

1 Answer 1


If you're not going to redo your LVM architecture, per my comments, then there are shortcuts:

you can use the swapoff technique in the first article. [Ubuntu – How to modify the size of swap with LVM partitions][1],

But first, let's be sure of your swap location (whether a file or a partition).

sudo swapon --show

I would expect something like this:

NAME                  TYPE      SIZE USED PRIO
/dev/ubuntu-vg/swap_1 partition 976M   0B   -2

If that's the case, then you can perform the following command:

sudo swapoff /dev/ubuntu-vg/swap_1

Then you can create a new swapfile in the root directory following the directions here in Where is the swapfile created?

Instead of a 2GB file, aim for a 5GB file. If the swap area is still not large enough, you can repeat the techniques until you get the right size for your needs.

sudo fallocate -l 5g /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Afterwards you won't require the LV for the swap.

Note this is a shortcut. Please give strong consideration to your architecture and storage needs. You can still redo it and give yourself flexibility by integrating good backup and recovery plans.

  • I don't understand your recommendation to redo my LVM architecture. I am not tied to this architecture, it came with the computer which only has 2 physical devices. At this point, I would like to make a permanent swap space, just not sure what is the best approach. Perhaps a 5 GB swap file and somehow reclaim the 1 GB swap lv for normal storage. I have no idea how to do that. Commented Jul 11, 2021 at 4:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .