Posts Tagged ‘swap’

CentOS – create a swap file.

I have done a few times before but don’t have to do it very often, just noting it here.

Create an empty file. The following will create a 1GB file.:

# dd if=/dev/zero of=/var/swapfile bs=1024 count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 10.9243 s, 96.0 MB/s

Change the permission:

# chmod 0600 /var/swapfile

Create the swap area:

# mkswap /var/swapfile
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=957c2a0c-30f9-4dd7-89ed-d88b9f471294

Enable the swap area:

# swapon /var/swapfile

Enable the swap area at boot by adding it to the /etc/fstab:

# vi /etc/fstab

/var/swapfile swap swap defaults 0 0

Disable the swap area:

# swapoff /var/swapfile

How to add more swap space in linux.

I used this procedure to add swap space to a server, where I not more available partitions, but had space on a previously formated partition.

# mkdir /var/swap

Create container files:
# dd if=/dev/zero of=/var/swap/swapfile1 bs=1024 count=65536
# dd if=/dev/zero of=/var/swap/swapfile2 bs=1024 count=65536
# dd if=/dev/zero of=/var/swap/swapfile3 bs=1024 count=65536
# dd if=/dev/zero of=/var/swap/swapfile4 bs=1024 count=65536

Format as swap:
# mkswap /var/swap/swapfile1
# mkswap /var/swap/swapfile2
# mkswap /var/swap/swapfile3
# mkswap /var/swap/swapfile4

Add them to startup:
# vi /etc/fstab

/var/swap/swapfile1 swap swap defaults 0 0
/var/swap/swapfile2 swap swap defaults 0 0
/var/swap/swapfile3 swap swap defaults 0 0
/var/swap/swapfile4 swap swap defaults 0 0

Enable them:
# swapon -a
Check them:
# swapon -sh

Return top

INFORMATION