Article Title: create virtual memory in linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
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.