Swap (virtual memory) setting method in ubuntu

ubuntu (virtual machine) version 16.04 LTS

Add swap

Use free to view the swap partition size

free -m

Create a swap folder

mkdir swap
cd swap
sudo dd if=/dev/zero of=swapfile bs=1024 count=100000

The size of count corresponds to the size of swap, as shown in the above code, count=100000 is about 100M

Note: Pay attention when setting the count value. If you set the swap size to exceed the size of the hard disk, it will cause the graphical interface of the virtual machine ubuntu to not enter after the setting is restarted.

Convert the generated file into a swap file

mkswap swapfile

Activate the swap file

swapon swapfile

If you need to automatically start every time you enter, you need to modify /etc/fstab to automatically mount:

Add to the file

/disk2/swap swap defaults 00

(Because I created the swap file in disk2, the path is /disk2/swap)

If it does not start automatically, it will enter the swap folder after every restart and activate it with the swapon swapfile command

Check the size of the swap partition again and confirm that the swap setting is successful

free -m

Delete swap

After use, delete the swap area

Enter the swap folder and close swap

cd swap
swapoff swapfile

Turn off automatic mounting (skip this step if /etc/fstab has not been modified)

vi /etc/fstab

Add # before the statement added or delete it

Note: If there is no permission to modify /etc/fstab, it will prompt that this file is read-only and cannot be modified. Solution: Use the following statement to save

:w !sudo tee%

delete

rm -r swapfile

Problems I encountered during configuration:

When setting the swap size, the size of the virtual machine's hard disk exceeded the size of the virtual machine's hard disk, which caused the ubuntu graphical interface of the virtual machine to be unable to enter after restarting. Use the following methods to solve:

ctrl+alt+F1 enters text mode

Check the disk space to see if it is because the disk space is full that you cannot enter the graphical interface

df -h

Found that the disk space is full, some files need to be deleted

You can use the rm -r statement to delete some files, or you can delete swap using the method mentioned above, and reconfigure

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Swap (virtual memory) setting method in ubuntu
How to add swap partition in Ubuntu
Install Ubuntu 18.04 in the virtual machine VMware
Detailed Ubuntu 16.04 pycharm setting desktop shortcut startup method
Use Ubuntu and windows system in virtual machine
Detailed explanation of static DNS configuration method in Ubuntu
How to create a Python virtual environment in Ubuntu 14.04
Tutorial for setting up FTP server in Ubuntu 16.04 environment
Install mysql-pytho in Ubuntu
Nagios3 in ubuntu serve
Use supervisor in ubuntu
Python virtual environment: Ubuntu16.04
Install python in Ubuntu
Install JDK in Ubuntu19.10
Encountered in the process of building a virtual environment in ubuntu
Method of setting up PHP operating environment under Ubuntu server