Create virtual memory in linux-Linux Enterprise Application-Linux server application information. The following is a detailed description. Virtual Memory is to plan a hard disk range so that memory data can be read through the hard disk.
In linux, create a swap file. The basic procedure is to create a swap device or file, format it as a swap, and mount it to the system.
Method 1: create a virtual memory device
Directly add a hard disk and plan a partition as a swap file system.
1. (1) fdisk/dev/hd [a-d]
(2) Change the ID of the partition to 82, of which 82 is the disk file format code of swap
2. Mkswap/dev/hd [a-d] [1-16]
Format the partition in preceding 1 as the archive format of swap
3. Swapon/dev/hd [a-d] [1-16]
Start swap. By the way, the command to disable swap is swapoff.
Method 2: create a virtual memory file
This method does not need to add a new hard disk.
Basic Process:
1. Create a swapfile using the dd command;
For example, use dd to add a 64 MB file under/tmp.
Dd if =/dev/zero of =/tmp/swap bs = 4 k count = 16382
# Dd is used to convert files and copy files.
# If indicates the input file format to be converted./dev/zero can be viewed by man zero.
# Of refers to the output file, which is output to the/tmp/swap file.
# Bs indicates that a slice occupies several kb;
# Count refers to the number of bs to be used, so the final capacity is bs * count = 4 k * 16832 ~ 64 MB
2. format the swapfile as a swap file using mkswap.
3. Start the file with swapon To Make It swap. After execution, you can use free to view the file.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service