Sunday, January 18, 2015

Adding Swap to a Linux VM



Find a device on which you want to put the swap

for our purposes we will put it as a file on the boot device.

[root@ebscloud ~]# mkdir /swap
[root@ebscloud ~]# cd /swap
[root@ebscloud swap]# dd if=/dev/zero of=swapfile1 bs=1048576 count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 0.709267 s, 739 MB/s
[root@ebscloud swap]# ls -lrt
total 512000
-rw-r--r-- 1 root root 524288000 Jan 18 11:40 swapfile1
[root@ebscloud swap]#
[root@ebscloud swap]# mkswap ./swapfile1
Setting up swapspace version 1, size = 511996 KiB
no label, UUID=47543a04-0a4b-4b36-a257-2eb5f4aceb7a
[root@ebscloud swap]#
[root@ebscloud swap]# swapon ./swapfile1
[root@ebscloud swap]#

Don't forget to add the entry into fstab to make it persistent at reboot ( left as exercise for reader ! )

( NB :  If you are following the above is slightly incorrect as we need 600 not 500 but the theory is the same ) 

No comments: