日期:2014-05-16  浏览次数:20851 次

Linux下增加交换分区

有时候,Linux下需要临时增加交换分区的大小,如果通过分区来做,显然比较麻烦,最简单的方法就是用一个大文件来模拟分区,下面是详细步骤:
?? ?? ? 系统当前交换分区如下:

??? ?? [dbtest@test55 ~]$ free
???????????? total?????? used?????? free???? shared??? buffers???? cached
??? ??? ??? Mem:?????? 2074840??? 1275356???? 799484????????? 0???? 168264???? 864196
??? ??? ??? -/+ buffers/cache:???? 242896??? 1831944
??? ??? ??? Swap:????? 2096472????????? 0??? 2096472

??? ?? 1、创建一个8M的空文件:
??? ?? [root@test55 ~]# dd?? if=/dev/zero?? of=swap1?? bs=1024?? count=8192
??? ??? 8192+0 records in
??? ??? 8192+0 records out
??? ??
??? ?? 2、创建交换分区:
??? ?? [root@test55 ~]# /sbin/mkswap?? swap1?? 8192
??? ??? Setting up swapspace version 1, size = 8384 kB

??? ?? 3、打开交换分区:
??? ?? [root@test55 ~]# /sbin/swapon?? swap1?

?????? 4、查看交换分区大小,发现已经增加了8M:
??? ?? [root@test55 ~]# free
???????????? total?????? used?????? free???? shared??? buffers???? cached
??? ??? ??? Mem:?????? 2074840??? 1330460???? 744380????????? 0???? 214796???? 872264
??? ??? ??? -/+ buffers/cache:???? 243400??? 1831440
??? ??? ??? Swap:????? 2104656????????? 0??? 2104656

????? 5、如果要去掉这个新的交换分区,用如下命令:
??? ?? [root@test55 ~]# /sbin/swapoff?? swap1?
??? ??? [root@test55 ~]# free
???????????? total?????? used?????? free???? shared??? buffers???? cached
??? ??? ??? Mem:?????? 2074840??? 1330524???? 744316????????? 0???? 214812???? 872248
??? ??? ??? -/+ buffers/cache:???? 243464??? 1831376
??? ??? ??? Swap:????? 2096472????????? 0??? 2096472

??? ??? ??? 显然,交换分区缩小了。