Question

How to change swap size on Ubuntu 14.04 ?

  • Posted October 2, 2014

Now, I am using ubuntu 14.04 with 512 RAM and Swap 512 too. I want to change my swap to 1 GB. Can anyone help me ? Should I repeat this step on this article with different size ?

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

Subscribe
Share

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

No, you don’t have to repeat these step if you already have swapfile in root directory. Check swapfile cd / ls -a

Just follow these steps:

  1. Make all swap off sudo swapoff -a

  2. Resize the swapfile sudo dd if=/dev/zero of=/swapfile bs=1M count=1024

  3. Make swapfile usable sudo mkswap /swapfile

  4. Make swapon again sudo swapon /swapfile

Worked with me I increased my swap size from 1.5 GB to 7 GB. But when I restarted my computer it came back to 1.5 GB, I don’t know why? could you please help.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Thanks for instructions & discussion.

Funny thing, I had to reduce my swap file from 8G to 4G. Gobble up too much disk space.

http://ubercx.io

This comment has been deleted

This comment has been deleted

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1

You could just delete the file and start from scratch, but if you just want to resize it you can do that as well. Just remember to disable it with swapoff first. For example:

# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		1048572	0	-1
# sudo swapoff /swapfile 
# sudo fallocate -l 4G /swapfile
# sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=fb0aadaf-b52f-4928-b57f-c60ef7a0bd49
# sudo swapon /swapfile
# sudo swapon -s
Filename				Type		Size	Used	Priority
/swapfile                               file		4194300	0	-1