I have 4 GB RAM on my laptop, and i allocated 3 GB for swap area while installing.So is having that much swap area harmful for my laptop? And if yes, then how can i change the size of swap area.How much swap area should i have allocated? When i run command
swapon --show
It shows
NAME TYPE SIZE USED PRIO
/swapfile file 2G 59M -2
But here, it shows only 2 GB, .So Does that mean swapfile and swapspace different? I don't know what to do. I am new to Ubuntu. Please help.
Best Answer
To Enlarge Swap Space:
Delete your existing swap file located at root
Create the new swap file:
sudo fallocate -l XG /swapfile
Where X is the swapfile size in GB (4GB in your case)
Reboot:
sudo reboot
To enable Hibernation (optional):
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX resume_offset=XXXXX"
Use UUID from root.
Use offset from
sudo filefrag -v /swapfile
cscameron@cscameron-T:~$ filefrag -v /swapfile Filesystem type is: ef53 File size of /swapfile is 4819255296 (1176576 blocks of 4096 bytes) ext: logical_offset: physical_offset: length: expected: flags: 0: 0.. 0: 303104.. 303104: 1: 1: 1.. 2047: 303105.. 305151: 2047: unwritten 2: 2048.. 4095: 311296.. 313343: 2048: 305152: unwritten
resume_offset=303104
Update GRUB
sudo update-grub
Test hibernation
sudo systemctl hibernate
There is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for
swapon: swapfile has holes
to ensure there will be no data loss.A hibernate button can be added using gnome extensions.
Proof of concept that hibernation works with a swapfile
Showing swapfile, resume and UUID's Showing hibernation popup Showing resume from UUID is root partition and not from swap partition