Author Topic: How to add a swap file in Linux ?  (Read 3237 times)


  • Guest
How to add a swap file in Linux ?
« on: January 03, 2010, 05:33:58 PM »
How to add a swap file in Linux

You must login as the root user.
We use dd and mkswap commands.

To create 512MB swap file (1024 * 512MB = 524288 block size) open terminal and type:

linux-modbus:~ # dd if=/dev/zero of=/swaparea bs=1024 count=524288
524288+0 records in
524288+0 records out
536870912 bytes (537 MB) copied, 3.3722 seconds, 159 MB/s

Set up a Linux swap area:

linux-modbus:/ # mkswap /swaparea
Setting up swapspace version 1, size = 536866 kB

 Activate swaparea

linux-modbus:/ # swapon /swaparea

To activate  /swaparea after Linux system start edit /etc/fstab using text editor such as vi:
linux-modbus:/ # vi /etc/fstab

Append following line:
/swaparea  swap swap defaults 0 0