----------------------------------------
1、[root@test-1 ~]# free -m #查看当前的系统swap大小
total used free shared buffers cached
Mem: 1972 1800 172 0 86 121
-/+ buffers/cache: 1592 379
Swap: 3967 2119 1848
2、[root@test-1 ~]# dd if=/dev/zero of=/swap_file bs=1024 count=2097152 #复制磁盘空间,
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB) copied, 45.1339 s, 47.6 MB/s
3、[root@test-1 ~]# mkswap /swap_file #格式化swaps分区
mkswap: /swap_file: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=e70c01f7-1117-46a5-ba36-955027112db6
4、[root@bcec-pud-1 ~]# swapon /swap_file #开启swap分区
5、[root@bcec-pud-1 ~]# free -m #再次查看swap空间增大
total used free shared buffers cached
Mem: 1972 1720 251 0 35 273
-/+ buffers/cache: 1411 560
Swap: 6015 2288 3727
其中第二步,count指的的是需要的磁盘大小,我的是2G,所以2048*bs 即2048*1024=2097152,空间大小只改变count后面的数字即可
服务器重启之后swap分区会变成原来,要想开机也是增加后的大小,编辑/etc/fstab 在末端添加如下行
cat /etc/fstab
/swap_file swap swap defaults 0 0
补充:
要停止使用新创建的swap文件,只要执行 swapoff /swapfree命令即可,如果swap交换文件不再使用,可以删除此文件。
检查swap
#swapon -s
开机时自动启动新添加的swap分区
如果每次开机后都要执行swapon命令启动swap分区或者文件,这太麻烦了.这时可以利用文字编辑器在/etc/fstab文件加一行,好让开机时自动启动swap分区及文件:
/dec/hdb5 swap swap defaults 0 0 (开机时启动此swap分区)
/swapfree swap swap defaults 0 0 (开机时启动此swap文件) .
---------------------------------
redhat linux swap分区扩展的三种方法
swap 介绍:
当物理内存占用完了后,当系统还需要更多的物理内存时,物理内存中inactive pages ,就move到swap空间。swap 空间是在位于硬盘上的,因此访问速度较物理内存慢。
当机器的物理内存发生变化时,swap 分区也要做相应的扩展:
有三种方法可以对swap 分区进行扩展:
一、扩展正在使用的swap 分区的逻辑卷(推荐使用此种方式)
二、新建swap 分区,
三、新建swap file,
具体步骤如下:
一、扩展正在使用的swap 分区的逻辑卷
设定用作swap 分区的逻辑卷为:/dev/VolGroup00/LogVol01
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01
Resize the LVM2 logical volume by 256 MB:
# lvm lvresize /dev/VolGroup00/LogVol01 -L +256M
Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon -va
Test that the logical volume has been extended properly:
# cat /proc/swaps 或者# free
二、新建swap 分区
设定新建的swap 分区的逻辑卷为:/dev/VolGroup00/LogVol02
Create the LVM2 logical volume of size 256 MB:
# lvm lvcreate VolGroup00 -n LogVol02 -L 256M
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 -va
Test that the logical volume has been extended properly:
# cat /proc/swaps 或者# free
三、新建swapfile
通过此种方式进行swap 的扩展,首先要计算出block的数目。具体为根据需要扩展的swapfile的大小,以M为单位。block=swap分区大小*1024, 例如,需要扩展64M的swapfile,则:block=64*1024=65536.
然后做如下步骤:
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
After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps 或者 free.
总结:三种方法都能对swap 分区进行扩展,但是推荐使用第一种方法。
1、[root@test-1 ~]# free -m #查看当前的系统swap大小
total used free shared buffers cached
Mem: 1972 1800 172 0 86 121
-/+ buffers/cache: 1592 379
Swap: 3967 2119 1848
2、[root@test-1 ~]# dd if=/dev/zero of=/swap_file bs=1024 count=2097152 #复制磁盘空间,
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB) copied, 45.1339 s, 47.6 MB/s
3、[root@test-1 ~]# mkswap /swap_file #格式化swaps分区
mkswap: /swap_file: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=e70c01f7-1117-46a5-ba36-955027112db6
4、[root@bcec-pud-1 ~]# swapon /swap_file #开启swap分区
5、[root@bcec-pud-1 ~]# free -m #再次查看swap空间增大
total used free shared buffers cached
Mem: 1972 1720 251 0 35 273
-/+ buffers/cache: 1411 560
Swap: 6015 2288 3727
其中第二步,count指的的是需要的磁盘大小,我的是2G,所以2048*bs 即2048*1024=2097152,空间大小只改变count后面的数字即可
服务器重启之后swap分区会变成原来,要想开机也是增加后的大小,编辑/etc/fstab 在末端添加如下行
cat /etc/fstab
/swap_file swap swap defaults 0 0
补充:
要停止使用新创建的swap文件,只要执行 swapoff /swapfree命令即可,如果swap交换文件不再使用,可以删除此文件。
检查swap
#swapon -s
开机时自动启动新添加的swap分区
如果每次开机后都要执行swapon命令启动swap分区或者文件,这太麻烦了.这时可以利用文字编辑器在/etc/fstab文件加一行,好让开机时自动启动swap分区及文件:
/dec/hdb5 swap swap defaults 0 0 (开机时启动此swap分区)
/swapfree swap swap defaults 0 0 (开机时启动此swap文件) .
---------------------------------
redhat linux swap分区扩展的三种方法
swap 介绍:
当物理内存占用完了后,当系统还需要更多的物理内存时,物理内存中inactive pages ,就move到swap空间。swap 空间是在位于硬盘上的,因此访问速度较物理内存慢。
当机器的物理内存发生变化时,swap 分区也要做相应的扩展:
有三种方法可以对swap 分区进行扩展:
一、扩展正在使用的swap 分区的逻辑卷(推荐使用此种方式)
二、新建swap 分区,
三、新建swap file,
具体步骤如下:
一、扩展正在使用的swap 分区的逻辑卷
设定用作swap 分区的逻辑卷为:/dev/VolGroup00/LogVol01
Disable swapping for the associated logical volume:
# swapoff -v /dev/VolGroup00/LogVol01
Resize the LVM2 logical volume by 256 MB:
# lvm lvresize /dev/VolGroup00/LogVol01 -L +256M
Format the new swap space:
# mkswap /dev/VolGroup00/LogVol01
Enable the extended logical volume:
# swapon -va
Test that the logical volume has been extended properly:
# cat /proc/swaps 或者# free
二、新建swap 分区
设定新建的swap 分区的逻辑卷为:/dev/VolGroup00/LogVol02
Create the LVM2 logical volume of size 256 MB:
# lvm lvcreate VolGroup00 -n LogVol02 -L 256M
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 -va
Test that the logical volume has been extended properly:
# cat /proc/swaps 或者# free
三、新建swapfile
通过此种方式进行swap 的扩展,首先要计算出block的数目。具体为根据需要扩展的swapfile的大小,以M为单位。block=swap分区大小*1024, 例如,需要扩展64M的swapfile,则:block=64*1024=65536.
然后做如下步骤:
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
After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps 或者 free.
总结:三种方法都能对swap 分区进行扩展,但是推荐使用第一种方法。