1. Create a new disk partition as a swap partition
2. Use the file as a swap partition (easier to operate, I'm more used)
A. Create a new disk partition as a swap partition
1. # swapoff-a #停止所有的swap分区
2. Use the Fdisk command (example: # FDISK/DEV/SDB) to partition the disk, add a swap partition, create a new partition, and use the "T" command in Fdisk to change the newly added partition ID to ". Linux swap Type". Finally, the operation is actually written to the hard disk with W (the operation is not valid until W is useless).
3. # mkswap/dev/sdb2 #格式化swap分区, the sdb2 here depends on the actual partition device name displayed after you add the P command
4. # SWAPON/DEV/SDB2 #启动新的swap分区
5. In order for the system to start automatically enable this swap partition, you can edit/etc/fstab, add the following line
/DEV/SDB2 swap swap defaults 0 0
Second, use the file as a swap partition
1. Create a file to be a swap partition: increase the 10GB size of the swap partition (the principle of the swap partition is not changed), then the command is written as follows, where count equals the number of blocks (bs*count= file size) you want.
# dd If=/dev/zero of=/root/swapfile bs=1m count=10240
2. Format the swap partition file:
# mkswap/root/swapfile #建立swap的文件系统
3. Enable the Swap partition file:
# swapon/root/swapfile #启用swap文件
4. Make the system self-enabled when booting, add a line in file/etc/fstab:
/root/swapfile swap swap defaults 0 0
The commands for new and added swap partitions are: Mkswap, Swapon, and so on, and a command like "SWAPON/DEV/SDB2" is used to shut down a swap partition.
How Linux increases the swap partition