Swap
Check size
_$: swapon -s
Filename Type Size Used Priority
/dev/mapper/ubuntu--test-swap_1 partition 1044476 0 -1
_$: free -m
total used free shared buffers cached
Mem: 995 425 569 0 83 255
-/+ buffers/cache: 86 908
Swap: 1019 0 1019
So swap has 1019 MB.
Increase swap size
_$: df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--test-root ext4 48G 1.8G 44G 4% /
udev devtmpfs 489M 4.0K 489M 1% /dev
tmpfs tmpfs 200M 236K 199M 1% /run
none tmpfs 5.0M 0 5.0M 0% /run/lock
none tmpfs 498M 0 498M 0% /run/shm
/dev/sda1 ext2 228M 25M 192M 12% /boot
_$: cd /media
_$: mkdir myswap
We will increase its size in 1 GiB:
_$: dd if=/dev/zero of=/media/myswap/swapfile.img bs=1024 count=1M
_$: mkswap /media/myswap/swapfile.img
And add it to /etc/fstab
:
/etc/fstab:
-----------
...
# Swap file
/media/myswap/swapfile.img swap swap sw 0 0
_$: swapon /media/myswap/swapfile.img
_$: cat /proc/swaps
Filename Type Size Used Priority
/dev/dm-1 partition 1044476 0 -1
/media/myswap/swapfile.img file 1048572 0 -2 <=== It is a file
_$: grep 'Swap' /proc/meminfo
SwapCached: 0 kB
SwapTotal: 2093048 kB
SwapFree: 2093048 kB
_$: free -m
total used free shared buffers cached
Mem: 995 876 119 0 48 731
-/+ buffers/cache: 96 899
Swap: 2043 0 2043
So swap now has 2043 MiB
_$: df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--test-root ext4 48G 2.8G 43G 7% / <===
udev devtmpfs 489M 4.0K 489M 1% /dev
tmpfs tmpfs 200M 236K 199M 1% /run
none tmpfs 5.0M 0 5.0M 0% /run/lock
none tmpfs 498M 0 498M 0% /run/shm
/dev/sda1 ext2 228M 25M 192M 12% /boot