如何临时增加swap?
2017-08-16 22:55
459 查看
当内存空间不够用,swap又被占用,如何临时的增加swap的大小呢?
【[b]加入swap阵营】[/b]
首先我们先查看下,目前的swap是多大的
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 247M 733M 244K 12M 144M
-/+ buffers/cache: 90M 889M
Swap: 767M 0B 767M
创建一个临时的块文件
[root@oldboyedu39 ~]# dd if=/dev/zero of=/tmp/100m bs=1M count=100 ###这里就以增加100M为例
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.33835 s, 310 MB/s
[root@oldboyedu39 ~]# ls -lh /tmp/100m
-rw-r--r-- 1 root root 100M Aug 15 20:03 /tmp/100m
改变文件类型
[root@oldboyedu39 ~]# file /tmp/100m
/tmp/100m: data
[root@oldboyedu39 ~]# mkswap /tmp/100m
mkswap: /tmp/100m: warning: don't erase bootbitssectors
onwhole disk. Use -f to force.
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=313362e9-56d4-4f39-8f29-bc199122eff4
[root@oldboyedu39 ~]# file /tmp/100m
/tmp/100m: Linux/i386 swap file(new style) 1 (4K pages) size 25599 pages ### 文件类型已改变
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 247M 733M 244K 12M 144M
-/+ buffers/cache: 90M 889M
Swap: 767M 0B 767M ### 并没有改变
将这个文件加入到swap中
[root@oldboyedu39 ~]# swapon /tmp/100m
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 247M 732M 244K 12M 144M
-/+ buffers/cache: 91M 889M
Swap: 867M 0B 867M
最后在来看下swap的大小已经增加。
【退出[b]swap阵营】[/b]
那么既然是临时的,在救急之后,如何恢复呢?直接删除吗?
[root@oldboyedu39 ~]# \rm -f /tmp/100m
rm: cannot remove `/tmp/100m': Operation not permitted
[root@oldboyedu39 ~]# ls -l /tmp/100m
-rw-r--r-- 1 root root 104857600 Aug 15 20:09 /tmp/100m
提示没有权限,看来这个文件正在被占用,是受保护的,那么怎么退出swap阵营呢?
[root@oldboyedu39 ~]# swapoff /tmp/100m
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 293M 686M 248K 37M 150M
-/+ buffers/cache: 106M 874M
Swap: 767M 0B 767M
退出swap之后,这个文件就可以删除了,当然也可以保留皆可。
【[b]加入swap阵营】[/b]
首先我们先查看下,目前的swap是多大的
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 247M 733M 244K 12M 144M
-/+ buffers/cache: 90M 889M
Swap: 767M 0B 767M
创建一个临时的块文件
[root@oldboyedu39 ~]# dd if=/dev/zero of=/tmp/100m bs=1M count=100 ###这里就以增加100M为例
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.33835 s, 310 MB/s
[root@oldboyedu39 ~]# ls -lh /tmp/100m
-rw-r--r-- 1 root root 100M Aug 15 20:03 /tmp/100m
改变文件类型
[root@oldboyedu39 ~]# file /tmp/100m
/tmp/100m: data
[root@oldboyedu39 ~]# mkswap /tmp/100m
mkswap: /tmp/100m: warning: don't erase bootbitssectors
onwhole disk. Use -f to force.
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=313362e9-56d4-4f39-8f29-bc199122eff4
[root@oldboyedu39 ~]# file /tmp/100m
/tmp/100m: Linux/i386 swap file(new style) 1 (4K pages) size 25599 pages ### 文件类型已改变
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 247M 733M 244K 12M 144M
-/+ buffers/cache: 90M 889M
Swap: 767M 0B 767M ### 并没有改变
将这个文件加入到swap中
[root@oldboyedu39 ~]# swapon /tmp/100m
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 247M 732M 244K 12M 144M
-/+ buffers/cache: 91M 889M
Swap: 867M 0B 867M
最后在来看下swap的大小已经增加。
【退出[b]swap阵营】[/b]
那么既然是临时的,在救急之后,如何恢复呢?直接删除吗?
[root@oldboyedu39 ~]# \rm -f /tmp/100m
rm: cannot remove `/tmp/100m': Operation not permitted
[root@oldboyedu39 ~]# ls -l /tmp/100m
-rw-r--r-- 1 root root 104857600 Aug 15 20:09 /tmp/100m
提示没有权限,看来这个文件正在被占用,是受保护的,那么怎么退出swap阵营呢?
[root@oldboyedu39 ~]# swapoff /tmp/100m
[root@oldboyedu39 ~]# free -h
total used free shared buffers cached
Mem: 980M 293M 686M 248K 37M 150M
-/+ buffers/cache: 106M 874M
Swap: 767M 0B 767M
退出swap之后,这个文件就可以删除了,当然也可以保留皆可。
相关文章推荐
- linux操作系统中如何临时增加swap空间
- 如何在Linux下增加Swap
- 如何增加swap空间大小
- 如何在Linux下增加Swap (转)
- 【2017/4/13】linux关于如何增加swap大小
- 临时增加swap空间
- linux临时增加swap空间
- 如何在Linux下增加Swap
- linux增加swap交换分区如何做?
- linux 临时增加swap空间
- 如何在不增加swap分区的情况下使用swap文件来增加swap?
- linux增加swap交换分区如何做?
- Linux临时增加swap空间
- 如何创建,增加SWAP?
- solaris临时增加swap空间
- 如何手工增加SWAP空间
- 如何增加swap 大小
- 增加删除swap临时文件
- linux中如何增加swap
- linux增加swap交换分区如何做?