先来查询一下系统的swap
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 375 369 6 0 7 83
-/+ buffers/cache: 278 97
Swap: 1027 128 899
[root@localhost ~]#
现在系统中swap是1024M
扩展是swap分区有两种方法,
(1) 利用磁盘的剩余空间来扩展swap
首先分区并改变分区的类型
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1958.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
First cylinder (1316-1958, default 1316):
Using default value 1316
Last cylinder or +size or +sizeM or +sizeK (1316-1958, default 1958): +500M
Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): 82
Changed system type of partition 8 to 82 (Linux swap / Solaris)
Command (m for help): wq
格式化swap
[root@localhost ~]# mkswap /dev/sda8
Setting up swapspace version 1, size = 509927 kB
[root@localhost ~]#
启动swap
[root@localhost ~]# swapon /dev/sda8
[root@localhost ~]#
现在我在查询一下swap的大小
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 375 369 6 0 7 82
-/+ buffers/cache: 278 96
Swap: 1513 128 1385
[root@localhost ~]#
可以看到的swap分区已经增大了500M
最后,要想下次系统重启生效,必须写在/etc/fstab文件中
/dev/sda8 swap swap defaults 0 0
~
(2) 利用分区的剩余空间来扩展swap
首先我一样要查询一下系统中swap分区的大小
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 375 368 7 0 7 81
-/+ buffers/cache: 278 96
Swap: 1513 128 1385
[root@localhost ~]#
然后利用dd工具来创建一个swap文件
[root@localhost ~]# dd if=/dev/zero of=swapfile bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.632534 seconds, 166 MB/s
[root@localhost ~]#
格式化swap
[root@localhost ~]# mkswap swapfile
Setting up swapspace version 1, size = 104853 kB
[root@localhost ~]#
把这个文件当做一个分区来对待
启动swap
[root@localhost ~]# swapon swapfile
[root@localhost ~]#
现在来查询一下swap分区的大小
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 375 368 6 0 1 90
-/+ buffers/cache: 276 98
Swap: 1613 128 1485
[root@localhost ~]#
可以看到系统的swap分区已经扩大100M
最后,要想下次系统重启生效,必须写在/etc/fstab文件中
/swapfile swap swap defaults 0 0