76

I used the 12.04 live cd to install Ubuntu over my Windows 7 partition and deleted everything so I just have Ubuntu on my laptop. But since during the installer I chose the simple "erase entire disk" option, did the installer create a swap partition or is that something I should've done with the "something else" option? Btw I have 6GB of RAM

ish
  • 139,926
dswhite85
  • 1,204
  • 7
  • 14
  • 20

8 Answers8

70

Easy, graphical way to check with Disk Utility

  1. Open Disk Utility from the Dash:

    enter image description here

  2. In the left column, look for the words "Hard Disk", and click on that:

    enter image description here

  3. In the right column, see if you can find "Swap" as shown. If so, you have swap enabled; you can click on that portion to see details. It will look something like this:

    enter image description here


Alternately, open a terminal with Ctrl+Alt+T, and type swapon -s; if you see a line like the below, with statistics, swap is enabled:

enter image description here

ish
  • 139,926
42

In terminal, type:

free -m

If you happen to have swap, you will see how much swap memory you have left.

Radu Rădeanu
  • 169,590
27

Use

cat /proc/swaps

In addition to the size, it will tell the type of swap (partition/file). It appears to give exactly the same output as swapon -s (posted here, but apparently deprecated).

Or

cat /etc/fstab

which will not give you the correct info in the (unusual) case of a swap added manually, as per comment by Carlo Wood.

  • The info in /etc/fstab is neither a guarantee nor always available. That file is used to configure a swap during boot and/or running swapon -a, but if you added a swap manually then it won't necessarily be in /etc/fstab. – Carlo Wood Apr 30 '20 at 12:09
  • @CarloWood - Good to know. So you say cat /proc/swaps is reliable in those cases that cat /etc/fstab is not? – sancho.s ReinstateMonicaCellio Apr 30 '20 at 12:43
  • Yes - I had an empty /etc/fstab, but /proc/swaps still showed me the swap that I just added manually. – Carlo Wood May 05 '20 at 15:19
  • /proc/swaps shows nothing, free -m shows swap 0, df shows nothing,'blkidshows/dev/sda2lsblk -o name,fstype,sizeshowsswap 5 G /dev/sda2. So I haveswapbut a hidden one? When I dosystemctl hibernateI getFailed to hibernate system via logind: Not enough swap space for hibernation. What can I do?cat /proc/meminfo` shows 6 GB of RAM. Is 1 GB of swap space missing? – Timo Aug 04 '21 at 19:15
12

I'd use this method to verify presence of a swap partition

Open a terminal with CTRL + ALT + T and type

    sudo blkid | grep swap  

If you see an entry with TYPE="swap", be sure that, you have a swap partition.

My output is like below: You can see that /dev/sda7 is a swap partition.

/dev/sda7: UUID="4656a2a6-4de0-417b-9d08-c4a5b807f8dd" TYPE="swap" 

enter image description here

The Installer should create a swap partition automatically. And also note that, You may never need a swap partition, unless you use "Hibernation" feature or use many more applications at a time. You can check these interesting question about swap size

I have 16GB RAM. Do I need 32GB swap?

what is SWAP and how large a swap partition should I create?

If it happens that, You did not create a swap partition, check this question for a help

How do I create a swap partition for hibernation?

Anwar
  • 76,649
  • See also: http://askubuntu.com/questions/33697/adding-swap-partition-after-system-installation and (for a swap file in case we can't partition) http://askubuntu.com/questions/126018/adding-a-new-swap-file-how-to-edit-fstab-to-enable-swap-after-reboot – Takkat Jul 05 '12 at 06:17
  • As Anwar Shah mentioned, this can show you whether you have a partition designated as swap, but this doesn't mean you're using it. Doing this to find swap partitions and verifying with idx's suggestion of 'swapon -s' that they match would be a great solution. – mightypile May 28 '15 at 02:03
4

Do lsblk and check for SWAP near the end.

In simple terms, lsblk | grep SWAP
output:

├─sdb2   8:18   0   7.6G  0 part [SWAP]

If you're not familiar with lsblk, lsblk lists partitions , their mountpoint, their size etc.

Anwar
  • 76,649
rrao
  • 145
  • 1
    Can you explain this a little better? Not everyone is familiar with terminal commands. It might benefit others if you explain what this means. For example, what is lsblk, and what does it do? What does the output mean? Things like that :) – AnotherKiwiGuy Nov 20 '16 at 12:50
  • On debian I had to lsblk -o fstype, size to show swap. – Timo Aug 04 '21 at 19:23
  • @AnotherKiwiGuy, man lsblk will give you a starting kick in. – Timo Aug 04 '21 at 19:24
1

Open gparted in a terminal:

sudo gparted

It will show all the partitions, you can see if you have a swap or not. You will also be able to 'swapon' or 'swapoff' with gparted.

Matt
  • 9,993
1

You could use gparted as told in the previous post to see all the partitions including swap on your system. gparted comes along with the LiveCD but you'll need to install it if you're not using the LiveCD. The command to do that is

sudo apt-get update && sudo apt-get install gparted

Alternatively, you could also use sudo fdisk -l from the terminal to take a look at all the partitions.

nits@nits-excalibur:~$ sudo fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x27edc0d3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sda2          206848   188743679    94268416    7  HPFS/NTFS/exFAT
/dev/sda3       224569342   976771071   376100865    5  Extended
/dev/sda4       188743680   224567295    17911808   83  Linux
/dev/sda5       224569344   434284543   104857600    7  HPFS/NTFS/exFAT
/dev/sda6       434286592   644001791   104857600   83  Linux
/dev/sda7       644003840   684001279    19998720   83  Linux
/dev/sda8       684003328   704002047     9999360   83  Linux
/dev/sda9       804003840   972767231    84381696   83  Linux
/dev/sda10      704004096   744001535    19998720   83  Linux
/dev/sda11      744003584   803987455    29991936   83  Linux
/dev/sda12      972769280   976771071     2000896   82  Linux swap / Solaris

Partition table entries are not in disk order

The line stating the FileSystem type as Linux Swap/ Solaris is the Swap partition (in my case the last line). You could also peek into your /etc/fstab file to see if swap is enabled by default on boot. If it was created during installation, you'll almost always find it here.

nits@nits-excalibur:~$ cat /etc/fstab | grep -i swap
# swap was on /dev/sda12 during installation
UUID=5604929a-9d9e-4ab0-907f-b9479a3b55e5 none            swap    sw              0       0
1

The default install creates a SWAP partition, Open system monitor from dash home and resources tab as an alternate way to verify. Something else allows you to do more extensive partitioning if desired.

user73761
  • 11
  • 3