-
Switch to the root account
-
Swap file is created, create a file 8G here
dd if=/dev/zero of=/swapfile bs=1024 count=8388608
where
if = / dev / zero: reading data from / dev / zero file.
of = / swapfile: file set here to create the swap file, the contents read from / dev / zero in.
bs = 1024: each read and write 1024 BYTES.
count = 8388608: number of blocks to be written, bs block sizes are provided. Calculated as the number of blocks of 1024 × 1024 × 8 = 8388608. The first is the size of bs of 1024, 1024BYTE, for the 1M. A second means 1024 1024 1M, as 1G. 8 The third refers to 8G. -
Set permissions swap file. This step is for safety.
chown root:root /swapfile
chmod 0600 /swapfile
-
The file format for the swap file
mkswap /swapfile
-
Enable swap file
swapon /swapfile
-
Let the system boot automatically enabled. Need to edit the
/etc/fstab
file, add the following in this file:
/swapfile swap swap defaults 0 0
- Disable swap file
swapoff /swapfile
- Check swap file usage information
swapon -s