Create SWAP at Linux

SWAP_FILE=/swapfile
BLOCK_SIZE=1024
SWAP_SIZE=1000 # 1000M
SWAP_BLOCKS=$BLOCK_SIZE*$SWAP_SIZE
 
# Create file
dd if=/dev/zero of=$SWAP_FILE bs=$BLOCK_SIZE count=$SWAP_BLOCKS
 
# Make swap
mkswap $SWAP_FILE
 
# Security
chown root:root $SWAP_FILE
chmod 0600 $SWAP_FILE
 
# Swap enable
swapon $SWAP_FILE
 
# Add to fstab to auto start
echo "$SWAP_FILE swap swap defaults 0 0" >> /etc/fstab
 
# Check if you have new 
free -m
howto/create_swap_at_linux.txt · Last modified: 2022/01/03 16:03 by 127.0.0.1
Back to top
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0