fallocate: fallocate failed: Text file busy in Ubuntu 17.04?

I installed Ubuntu a few weeks ago and I usually run more than 6 programs(sts,web browsers, and so on).

The system is getting stuck.

My RAM size is 6 GB and swap 2 GB. I decided to increase swap size to 15 GB. When I was trying to accomplish this work, I got the following error. I have linked to the tutorial that I was following.

sudo swapon --show
[sudo] password for decoders: 
NAME      TYPE SIZE USED PRIO
/swapfile file   2G   0B   -1
decoders@10decoders:~$ free -h
              total        used        free      shared  buff/cache   available
Mem:           5.7G        1.1G        3.4G        217M        1.1G        4.1G
Swap:          2.0G          0B        2.0G
decoders@10decoders:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.9G     0  2.9G   0% /dev
tmpfs           583M  9.0M  574M   2% /run
/dev/sda1       293G   14G  265G   5% /
tmpfs           2.9G  4.7M  2.9G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.9G     0  2.9G   0% /sys/fs/cgroup
tmpfs           583M  144K  583M   1% /run/user/1000
decoders@10decoders:~$ sudo fallocate -l 15G /swapfile
fallocate: fallocate failed: Text file busy
decoders@10decoders:~$ ls -lh /swapfile
-rw------- 1 root root 2.0G May 19 11:43 /swapfile
decoders@10decoders:~$ 

I followed this tutorial link: http://www.tutorialspoint.com/articles/how-to-increase-swap-space-on-linux-ubuntu


Creating a SWAP partition in Ubuntu, Linux Mint and derivatives


METHOD 1: Command-line Way from Terminal (Fastest way!)

STEP 1: First step is to check if by chance is there any SWAP partition already created in your PC:

sudo swapon --show

Enter your root password. If you see no output, it means that the SWAP doesn’t exist.

STEP 2: Next, let’s see the current partition structure of your computer’s hard disk:

df -h

STEP 3: As heynnema commented, before you start the changes disable the use of swap:

sudo swapoff -a

STEP 4: Now it's time to create the SWAP file. Make sure you have enough space on the hard disk. It is a matter of preference in how much SWAP size you need.

My suggestion is: If you have a maximum of 4GB of RAM I would suggest putting twice the RAM for the SWAP (8GB for SWAP). For PCs with more than 4GB I recommend the same number of RAM for SWAP plus 2GB. Example: In my case it's 8GB, I put 8GB + 2GB, totaling 10GB for SWAP. But you may feel free to make your choice.

sudo dd if=/dev/zero of=/swapfile bs=1G count=10 status=progress

STEP 5: SWAP file is now created. Let’s give root-only permissions to it.

sudo chmod 600 /swapfile

STEP 6: Mark the file as SWAP space:

sudo mkswap /swapfile

STEP 7: Finally enable the SWAP.

sudo swapon /swapfile

STEP 8: You can now check using the same swapon command to check if SWAP is created.

sudo swapon --show

STEP 9: Also check the final partition structure again.

free -h

STEP 10: Once everything is set, you must set the SWAP file as permanent, else you will lose the SWAP after reboot. Run this command:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Finished, now exit the terminal!

You can check SWAP status on System Monitor utility.


METHOD 2: GUI Way using GParted

If you want to go directly through the graphical interface, enter the reference link below that is well explained.


Reference:

  • How do I increase the size of swapfile without removing it in the terminal?

  • https://www.fosslinux.com/1064/how-to-create-or-add-a-swap-partition-in-ubuntu-and-linux-mint.htm