Adding Linux swap file

  1. Switch to the root account

  2. 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.

  3. Set permissions swap file. This step is for safety.
    chown root:root /swapfile
    chmod 0600 /swapfile

  4. The file format for the swap file
    mkswap /swapfile

  5. Enable swap file
    swapon /swapfile

  6. Let the system boot automatically enabled. Need to edit the /etc/fstabfile, add the following in this file:
    /swapfile swap swap defaults 0 0

  • Disable swap file
    swapoff /swapfile
  • Check swap file usage information
    swapon -s
Published 42 original articles · won praise 5 · Views 2979

Guess you like

Origin blog.csdn.net/Function_RY/article/details/102763535