Swap and Lubuntu (FAQ)

Q: What is swap?

I’ll refer to general instructions here - please look at SwapFaq - Community Help Wiki which includes instructions on setting up swap too.

Q: Can Lubuntu use swap?

Yes; all releases of Lubuntu have allowed the use of swap. Lubuntu 20.04 LTS allows you to create swap partitions in the Manual partitioning area, and post-install you can setup and use swap files (see How to create a swapfile in Lubuntu 20.04 & 20.10).

Lubuntu 21.04 and later provide more options too. :slight_smile:

Q: Can Lubuntu 21.04 (and later releases) create swapfile during install?

Yes if you use the erase disk option.

Other install options do not offer to create a swap file; eg. Manual partitioning, Replace a partition do not offer you the chance to create a swap file, but you can add one if you like post-install by referring to the previously provided link.

With the Manual partitioning option you can also create new swap partitions if required.

Q: Which is better? Swap partition or swap file?

Each has benefits and of course costs. Swap files are easier with encryption and far easier should you need to change the size, so being simpler I’d suggest using swapfile over swap partition.

However if you have a dual boot system you can share a swap partition between two releases of GNU/Linux eg. *I have a swap partition that is shared between Lubuntu 20.04 LTS & Lubuntu impish; I can’t hibernate one & switch to the other of course with a shared swap partition, but it saves space over having a swapfile for each OS.

Q: Can I use swap partition & swapfile?

Yes you can.

Q: Replace a partition? Does a prior swapfile get re-used/created?

I looked at this using the current impish system and this type of install causes a 512MB swapfile to be created. :slight_smile: This type of install is clean so all files are new on install.

Note: As the calamares currently used in impish is identical to that of 21.04/hirsute I’d expect 21.04 to be the same.

Q: Manual partitioning; install into existing partition(s) without format; does it cause swap to get re-used

This install involves re-using existing partitions and not formatting, ie. an unclean install… I think of it as a quick fix because of a package stuff up (but not user configs, as that isn’t touched; any user config problem will remain!) as this is a very fast way to re-install & get back to being functional. It causes the installer to

  • notes your packages installed
  • erases system directories
  • installs new system
  • adds back the additional packages you had installed (if they’re available in Ubuntu repositories)

without touching user files (assuming you don’t format!).

I tested this using the current impish system and this type of install kept a 512MB swapfile which was used on reboot. :slight_smile:

This type of install is unclean so the swapfile in my case was not re-created (going by file creation timestamp) so if you’d increased size beyond the default 512MB I’d expect the larger size to have survived (/ is not a system directory which is wiped). Alas I didn’t think of changing the size prior to this test :frowning:

Note: As the calamares currently used in impish is identical to that of 21.04/hirsute I’d expect 21.04 to be the same.

Q: How do I know if I have swap enabled? or what size do I have?

Enter the command swapon --show , eg.

guiverc@d960-ubu2:~$   swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/sda2 partition 9.5G 2.9G   -2

and it’ll show what swap you have enabled (be it swapfile or swap partition). No output will mean you don’t have swap enabled.

If you want an alternate way you can use the command free -h and you’ll see output like

guiverc@d960-ubu2:~$   free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       5.7Gi       497Mi        95Mi       1.5Gi       1.6Gi
Swap:          9.5Gi       2.9Gi       6.7Gi

In both cases you’ll see the same result: I’m using a swap partition*, and the size is 9.5GiB.

Q: I’ve installed and only have 512MB of swap, how can I increase the size ?

Please refer to the instructions found in How to create a swapfile in Lubuntu 20.04 & later which walk through the creation of a 8GB swap file. Those instructions cover if you have no swapfile, or want to disable/erase the existing swapfile and create a 8GB file. If you want a different size than 8GB, just alter the value in the creation step.

Q: Can I enable RAM compression?

Please refer to Enabling RAM Compression on Lubuntu

Q: Should swap go on the same disk or my other disk?

A large percentage of users are likely using hardware with only a single disk drive, but if your machine has multiple disks, there can be sizable speed advantages by having swap on a different disk to the disk where most of your disk activity (file read/writes) occur. These results can be hardware specific, and please note: here I mean physical disks, & not partitions.

8 Likes