Manage swap space in rhel5 __server

Source: Internet
Author: User

One, add swap space:

1. Extend an existing swap space:

<1> prohibit the swap space in use first:

[Root@server4 ~]# Swapoff/dev/mapper/tools-swap

<2>, re-resize/dev/mapper/tools-swap:

[Root@server4 ~]# LVM lvresize/dev/tools/swap-l +300m
Extending logical volume Swap to 500.00 MB
Logical Volume swap successfully resized

<3> reformatting using Mkswap:

[Root@server4 ~]# Mkswap/dev/tools/swap
Setting up Swapspace version 1, size = 524283 KB

<4>, enable swap:

[Root@server4 ~]# Swapon-av
Swapon On/dev/mapper/tools-swap

<5> View Swap Size:

  [root@server4 ~]# cat/proc/swaps
filename                                  type            size     used    Priority
/dev/sda3                                 partition       1044216 0      -2
/ dev/mapper/tools-swap                   partition       511992  0       -4

[Root@server4 ~]# Free-m
Total used free shared buffers Cached
mem:194 172 21 0 19 78
-/+ buffers/cache:75 119
swap:1519 0 1519

2. Add a new swap space (based on LVM):

[Root@server4 ~]# LVM lvcreate tools-n swap1-l 100M
Logical volume "Swap1" created
[Root@server4 ~]# Mkswap/dev/tools/swap1
Setting up Swapspace version 1, size = 104853 k

Change/etc/fstab file and join/dev/tools/swap1.

To enable the newly created swap space:

[Root@server4 ~]# Swapon-av
Swapon On/dev/mapper/tools-swap1

[Root@server4 ~]# Free-m
Total used free shared buffers Cached
mem:194 173 20 0 19 78
-/+ buffers/cache:75 118
swap:1619 0 1619

3. Create swap file:

[Root@server4/]# dd If=/dev/zero of=/swapfile bs=1k count=102400
102400+0 Records in
102400+0 Records out
104857600 bytes (MB) copied, 1.23157 seconds, 85.1 MB/s

[Root@server4/]# Mkswap/swapfile
Setting up Swapspace version 1, size = 104853 KB

[Root@server4/]# Swapon/swapfile

Add the following line to the/etc/fstab file:

/swapfile Swap Defaults 0 0

Second, delete swap space:

1. Reduce a swap space:

[root@server4/]# swapoff/dev/mapper/tools-swap
[root@server4/]# lvm lvreduce/dev/tools/swap-l -400M
  ; Warning:reducing Active Logical Volume to 100.00 MB
  i DESTROY YOUR DATA (filesystem etc.)
Do your really want to reduce swap? [y/n]: y
  reducing logical volume swap to 100.00 MB
  Logical Volume swap successfully resized
[roo T@server4/]# mkswap/dev/tools/swap
Setting up swapspace version 1, size = 104853 KB
[root@server4/]# Swapon-va
Swapon On/dev/mapper/tools-swap

[Root@server4/]# LVs
LV VG Attr lsize Origin snap% move Log copy% Convert
Swap Tools-wi-ao 100.00M
Swap1 Tools-wi-ao 100.00M

2. Remove an LVM-based swap:

[Root@server4/]# Swapoff/dev/tools/swap1
[Root@server4/]# LVM Lvremove/dev/tools/swap1
Do your really want to remove active logical Volume "SWAP1"? [y/n]: Y
Logical volume "Swap1" successfully removed

Then remove it from the/etc/fstab file.

3. Delete a swap file:

[Root@server4/]# swapoff-v/swapfile

[Root@server4/]# Rm-rf/swapfile

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.