Learn Devops tools online from the blog. Devops Institute Ahmedabad.

Add a Swap Partition:

you need to create a new partition of desired size in the file system.you have created a partition say /dev/sda7 having size 1GB.

[root@den ]# mkswap /dev/sda7Setting up swapspace version 1, size = 1057092 KiB no label, UUID=5ad400b1-3a7f-449c-9605-c257e56ba381  
[root@den ]# free
total used free shared buffers cached
Mem: 3040320 467800 2572520 0 28032 255368
-/+ buffers/cache: 184400 2855920
Swap: 4289312 0 4289312

The free command above shows around 4GB of swap space. Now lets activate the swap partition.
[root@den ]# swapon /dev/sda7 
[root@den ]# free
total used free shared buffers cached
Mem: 3040320 659016 2381304 0 29296 328196
-/+ buffers/cache: 301524 2738796
Swap: 5346400 0 5346400

Notice that the free memory space rose to around 5GB
To make the changes permanent you can put an entry in the /etc/fstab file as

/dev/sda7 swap swap defaults 0 0
Add a Swap File: 
[root@den ]# dd if=/dev/zero of=/swap_file bs=1024 count=524288
524288+0 records in
524288+0 records out
536870912 bytes (537 MB) copied, 3.79122 s, 142 MB/s
[root@den ]# mkswap /swap_file
mkswap: /swap_file: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=8d200179-e61b-4f04-8aff-8140d667781
[root@den ]# swapon /swap_file

To enable it at boot time, add an entry like the below line in the /etc/fstab file.

/swap_file swap swap defaults 0 0

To verify that the swap has been enabled or not you can use the free command as discussed above or also you can see the contents of the file

cat /proc/swaps

Vishal Vyas

No comments:

Post a Comment