Create/Add swap file

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

Create/Add swap file

Postby lik » Wed Jan 05, 2011 2:56 pm

Use dd command to create swapfile. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.

1. Use 'fallocate' to create swapfile of desired size:
Code: Select all
fallocate -l 2G /swapfile

Or use 'dd' create 2048MB swap file (1024 * 2048MB = 2097152 block size):
Code: Select all
dd if=/dev/zero of=/swapfile bs=1024 count=2097152

2. Adjust permissions
Code: Select all
chmod 600 /swapfile

3. Set up a Linux swap area:
Code: Select all
mkswap /swapfile

4. Activate /swapfile swap space:
Code: Select all
swapon /swapfile

5. To activate /swapfile after Linux system reboot, append the following entry to /etc/fstab file:
Code: Select all
/swapfile swap swap defaults 0 0
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to Linux specific

 


  • Related topics
    Replies
    Views
    Last post
cron