Add Swap Area In Ubuntu Linux

In UNIX environment we have swap partition that used as virtual memory. Beside dedicated swap partition, we can add certain file as swap area. Below is the example how to add a file as additional swap area in Ubuntu Linux :


tedy@satekambing:~$ sudo dd if=/dev/zero of=/SWAP.img bs=1M count=128 
128+0 records in 
128+0 records out 
134217728 bytes (134 MB) copied, 1.24483 s, 108 MB/s 
tedy@satekambing:~$ sudo losetup /dev/loop7 /SWAP.img 
tedy@satekambing:~$ sudo mkswap /dev/loop7 
Setting up swapspace version 1, size = 131068 KiB 
no label, UUID=db4ead3d-72d8-4fcd-97e1-7ace5ad55275 
tedy@satekambing:~$ sudo swapon /dev/loop7 
tedy@satekambing:~$ 

If you login as root then the command will be like this :


# dd if=/dev/zero of=/SWAP.img bs=1M count=128 
# losetup /dev/loop7 /SWAP.img 
# mkswap /dev/loop7 
# swapon /dev/loop7 

Leave a Reply