Ubuntu: How to Resize Ubuntu 17.04 Zesty Swap file size? [duplicate]



Question:

This question already has an answer here:

Last night, I was converting movies with handbrake. There was steam and ubuntu software centre running in background. When I woke up, I saw a message 'Ubuntu faced an internal error......' and handbrake is crashed. So, I think it was because of lack of swap memory (2GB swap file). Anyone knows how to increase swap file size? (My PC Have 4GB RAM)


Solution:1

I wouldn't try to resize it literally. Probably it is possible - maybe gparted could to it - but I can't think of a reason to bother and it would be quicker and simpler to just make a new one. First turn off the current one: swapoff -a Delete the old one, then make a new one however big you want, and turn it on. If you give it the same /path/name, you won't even need to change fstab, and you will have EFFECTIVELY, if not literally, enlarged the swap file. Somebody at Redhat here:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/s2-swap-creating-file.html

wrote this (I quote 'cause some fora frown on incorporation by ref, but the block quote button messes with the format, so I'm editing this to just paste it in plain):

# # # QUOTATION FOLLOWS # # #

To add a swap file:

Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.

At a shell prompt as root, type the following command with count being equal to the desired block size:

dd if=/dev/zero of=/swapfile bs=1024 count=65536    Change the persmissions of the newly created file:    chmod 0600 /swapfile    Setup the swap file with the command:    mkswap /swapfile    To enable the swap file immediately but not automatically at boot time:    swapon /swapfile  

To enable it at boot time, edit /etc/fstab to include the following entry:

/swapfile          swap            swap    defaults        0 0  

The next time the system boots, it enables the new swap file.

After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.

# # # END QUOTATION # # #

If you already have a swap file, you probably already know most of that. Anyway, I think that is close to a literal answer to the question as posed.

But if it is only in this one context that you need a bigger swap, and it doesn't happen often, if you are short of drive space, you might consider, instead of REPLACING your swap file, just make and mount an ADDITIONAL one prior to when you need it. They are cumulative. You can have as many as you want. Then you can unmount and delete it when you are through.

Regarding the issue of swap file vs. swap partition that Ravery touched on, much of what you will read on that subject is out of date. Unless your swap partition is on another drive (and maybe I should even say another drive controller) it isn't likely to be any faster than a swap file. And it is definitely less flexible. Unless it is on a separate drive, I can't see a lot of reason to use a swap partition any more.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »