Creating Swap File


I ordered a ECS from Aliyun, it come without a (virtual) swap drive. Here are the steps to create one:

    sudo dd if=/dev/zero of=/swapfile bs=1G count=2
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile

A 2G swap space is created and activated. To make it available at next reboot: sudo vi /etc/fstab

add this:

/swapfile   none    swap    sw    0   0