How to Increase Virtual Memory in Linux

Techwalla may earn compensation through affiliate links in this story. Learn more about our affiliate and product review process here.
Increase Virtual Memory in Linux

When a Linux system is initially set up, a swap partition is created on the hard drive that will be used as virtual memory in Linux, along with other partitions used for data. Unfortunately, partitions on the hard drive cannot be re-sized without the loss of data. However, not all is lost if more swap is needed. If there is remaining space on a file system that can be used as swap, a swap file can be created that is used exclusively as additional virtual memory in Linux.

Advertisement

Step 1

Determine the amount of free space available with the "df" command. Decide upon the size of the swap file based upon the amount of free space.

Video of the Day

Step 2

Create a swap file of the size decided upon earlier with the command "sudo dd if=/dev/zero of=/mnt/swapfile bs=1M count=1024" where 1024 is the size of the swap file in megabytes and the full name of the swapfile is /mnt/swapfile.

Advertisement

Step 3

Format the swap file with the command "sudo mkswap /mnt/swapfile."

Step 4

Enable the swap file with the command "sudo swapon /mnt/swapfile."

Advertisement

Step 5

The new swap file will not be used after a reboot unless the system is told to use the swap file. Edit the /etc/fstab file and add the following line in /etc/fstab to make the swap file persistent between reboots "/mnt/swapfile none swap sw 00."

Video of the Day

Advertisement

Advertisement