Linix下如何创建,增大,缩小,删除swap分区

1. Creating an LVM2 Logical Volume for Swap
To add a swap volume group (assuming /dev/VolGroup00/LogVol02 is the swap volume you want to add):
Create the LVM2 logical volume of size 2 GB:
# lvcreate VolGroup00 -n LogVol02 -L 2G
Format the new swap space:
# mkswap /dev/VolGroup00/LogVol02
Add the following entry to the /etc/fstab file:
# /dev/VolGroup00/LogVol02 swap swap defaults 0 0
Enable the extended logical volume:
# swapon -v /dev/VolGroup00/LogVol02
To test if the logical volume was successfully created, use cat /proc/swaps or free to inspect the swap space.

2. Extending Swap on an LVM2 Logical Volume
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01
Resize the LVM2 logical volume by 2 GB:
# lvresize /dev/VolGroup00/LogVol01 -L +2G
Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon -v /dev/VolGroup00/LogVol01
To test if the logical volume was successfully extended, use cat /proc/swaps or free to inspect the swap space

3. Add a swap file
Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.
At a shell, type the following command with count being equal to the desired block size:
# dd if=/dev/zero of=/swapfile bs=1024 count=65536
Setup the swap file with the command:
# mkswap /swapfile
To enable the swap file immediately but not automatically at boot time:
# swapon /swapfile
To enable it at boot time, edit /etc/fstab to include the following entry:
/swapfile swap swap defaults 0 0
The next time the system boots, it enables the new swap file.
To test if the new swap file was successfully created, use cat /proc/swaps or free to inspect the swap space.

4. Reducing an LVM2 swap logical volume
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01
Reduce the LVM2 logical volume by 512 MB:
# lvreduce /dev/VolGroup00/LogVol01 -L -512M
Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon -v /dev/VolGroup00/LogVol01
To test if the swap's logical volume size was successfully reduced, use cat /proc/swaps or free to inspect the swap space.

5. Remove a swap volume group
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol02
Remove the LVM2 logical volume of size 512 MB:
# lvremove /dev/VolGroup00/LogVol02
Remove the following entry from the /etc/fstab file:
/dev/VolGroup00/LogVol02 swap swap defaults 0 0
To test if the logical volume size was successfully removed, use cat /proc/swaps or free to inspect the swap space.

6. Remove a swap file
At a shell prompt, execute the following command to disable the swap file (where /swapfile is the swap file):
# swapoff -v /swapfile
Remove its entry from the /etc/fstab file.
/swapfile swap swap defaults 0 0
Remove the actual file:
# rm /swapfile


你可能感兴趣的:(linux,centos,redhat,swap,RHEL6)