banner
年糕

年糕日记

此站为备份站点,最新文章请访问 oior.net
telegram
email

Swap Usage

Add Virtual Memory#

  1. Get file blocks (The number of swap partitions depends on your physical memory and disk usage, usually 1-2 times the size of physical memory)

    dd if=/dev/zero of=/var/swapfile bs=1M count=2048
    
    # The block_size and number_of_block can be customized, for example, bs=1M count=1024 represents setting a 1GB swap partition.
    
  2. Create swap file

    /sbin/mkswap -f /var/swapfile
    
  3. Give 600 permission to swapfile

    chmod 600 /var/swapfile
    
  4. Activate swap file

    /sbin/swapon /var/swapfile
    
  5. Check if swap is correct

    /sbin/swapon -s
    
  6. Add to fstab file for automatic startup during system boot (to prevent swap partition from becoming 0 after restart)

    vi /etc/fstab
    // Add at the end
    /var/swapfile swap swap defaults 0 0
    
  7. Reboot the system

    reboot
    
  8. Check the status of swap partitions

    free -m
    

Remove Virtual Memory#

  1. Stop the swap partition
    /sbin/swapoff /var/swapfile
    
  2. Delete the swap partition file
    rm -rf /var/swapfile
    
  3. Delete the automatic mount configuration command
    vi /etc/fstab
    // Delete the following content
    /var/swapfile swap swap defaults 0 0
    
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.