Problem
You may want/need to create and enable a swap file on your Linux machine (or server). For example, on some AWS EC2 instances you don't get ephemeral (temporary) storage disks that can be used for swap, so you might want to create a swap file on the main EBS volume to alleviate potential memory issues.
Solution
You can create a swap file on your Linux server via a terminal. Note, you'll need sudo
access for this.
...
The following will create and enable a 8GB swap file at /var/swap.0swapfile
Code Block |
---|
|
sudo dd if=/dev/zero of=/var/swap.0swapfile bs=1M count=8120
sudo mkswap /var/swap.0swapfile
sudo chmod 600 /var/swap.0swapfile
sudo swapon /var/swap.0swapfile |
Making swap persistent
Doing the above will simply enable swap. After a server reboot swap won't be enabled. Do the following to make it persistent:
Code Block |
---|
|
sudo cp /etc/fstab /etc/fstab.backup
echo '/var/swap.0 swapswapfile none swap defaults 0 0' | sudo tee -a /etc/fstab |
...
References
- https://stackoverflow.com/questions/17173972/how-do-you-add-swap-to-an-ec2-instance
Related articles
Content by Label |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | TKB |
---|
showSpace | false |
---|
sort | modified |
---|
reverse | true |
---|
type | page |
---|
cql | label in ("swap","ec2") and type = "page" and space = "TKB" |
---|
labels | ec2 swap |
---|
|
...