SWAP partition creation and memory release under CentOS

method one:


1. Check the current partition status of the system:

>free -m
2. Create a file for swap partition:

>dd if=/dev/zero of=/whatever/swap bs=block_size (10M) count=number_of_block(3000)

3 、Set the swap partition file:
>mkswap   /export/swap/swapfile

4. Enable the swap partition file immediately:
>swapon /whateever/

swap Line:

/whatever/swap swap swap defaults 0 0


Method 2
To increase the space of the swap partition:
1. Check /etc/fstab to determine the current partition
2.swapoff /dev/hd**
3.free Check if it is stopped
4. fdisk deletes the stopped swap partition 5.
re-use FDISK to create a new SWAP partition
6. mkswap /dev/hd** make the new partition into swap
7. swapon /dev/hd** open swap
8 .Modify /etc/fstab



operation example:
1. Check the system Swap space usage
# free
total used free sharedbufferscached
Mem:
513980493640203400143808271780
-/+ buffers/cache: 
78052435928
Swap:
1052248212561030992

2.在空间合适处创建swap文件
# mkdir swap
# cd swap
# dd if=/dev/zero of=swapfile bs=1024 count=10000
10000+0 records in
10000+0 records out
# ls -al
total 10024
drwxr-xr-x
 2 root root4096 7月 28 14:58 .
drwxr-xr-x
 19 root root4096 7月 28 14:57 ..
-rw-r--r--
 1 root root10240000 7月 28 14:58 swapfile


# mkswap swapfile
Setting up swapspace version 1, size = 9996 KiB

3.激活swap文件
# swapon swapfile
# ls -l
total 10016
-rw-r--r--
 1 root root10240000 7月 28 14:58 swapfile
# free
totalusedfreesharedbuffers

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326785992&siteId=291194637