系統類型:RedHat Enterprise Linux5
登入使用者:root
原有交換分區:1G
現在要通過添加交換檔案的形式擴大系統的交換分區,為系統添加1G的交換分區。
1. 首先可以通過free -m指令來檢視原有的Swap分區的大小Total為1019M。
[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 1010 610 400 0 35 405
-/+ buffers/cache: 169 841
Swap: 1019 0 1019
2.建立/swapfile檔案
[[email protected] ~]# dd if=/dev/zero of=/swapfile bs=1024 count=1024000
幾秒中後會出現下面的提示:
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 49.1357 seconds, 21.3 MB/s
3.設定交換分區
[[email protected] ~]# mkswap /swapfile
Setting up swapspace version 1, size = 1048571 kB
4.馬上啟用交換分區
[[email protected] ~]# swapon /swapfile
5.如果再通過free -m來檢查記憶體的時候就可以看到内容變大了
[[email protected] ~]# free -m
total used free shared buffers cached
Mem: 1010 991 19 0 1 803
-/+ buffers/cache: 186 824
Swap: 2019 0 2019
6.設定系統啟動是自動打開交換分區,在/etc/fstab檔案中加入一行
/swapfile swap swap defaults 0 0
即:
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/swapfile swap swap defaults 0 0
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5 0 0
# End of the block added by the VMware software
儲存退出,這樣下次啟動系統之後自動啟用了該swap。
打完收工。。。 。。。
Thomas Yang
2010/01/22