Monday, January 21, 2019

When we need to use swap partition in Linux?

Recently i have an issue on my LightSail small instance which have 512MB of RAM,

I can not run react-script build on it

npm run build
Because of the issue: https://github.com/kitze/custom-react-scripts/blob/master/packages/react-scripts/template/README.md#npm-run-build-exits-too-early

So create a Linux swap is life saver.

Firstly, check if swap available :

sudo swapon --show
if it show nothing, then you don't have any swap yet.

Now, create a swap file, it should be 2x or 4x of your RAM capacity
sudo fallocate -l 1G /swapfile

To verify the swap is created
ls -lh /swapfile
To enable swap, you may need to change the permission

sudo chmod 600 /swapfile
make swap file
          sudo mkswap /swapfile        
then
sudo swapon /swapfile
check if it is ready
sudo swapon --show
 To enable swap permanent

Backup file
sudo cp /etc/fstab /etc/fstab.bak
Add the line at the end of file

/swapfile swap swap defaults 0 0

No comments:

Post a Comment