Linux系統中增加Swap分割槽檔案步驟方法

mrhaozi發表於2010-11-03
檢查沒有swap,下面就需要增加,判定新交換檔案的大小,將大小乘以1024來判定塊的大小。例如,大小為64MB的交換檔案的塊大小為65536,在 shell 提示下以根使用者身份鍵入以下命令,其中的 count 等於想要的塊大小。

1、檢查當前的情況(使用free -m或cat /proc/s )

[root@db2 root]# free -m
              total       used       free     shared    buffers     cached
 Mem:          1006         84        922          0         11         38
 -/+ buffers/cache:         35        971
 :            0          0          0
 [root@db2 root]#

2、增加交換檔案及大小

檢查沒有,下面就需要增加,判定新交換檔案的大小,將大小乘以1024來判定塊的大小。例如,大小為64MB的交換檔案的塊大小為65536,在 shell 提示下以根使用者身份鍵入以下命令,其中的 count 等於想要的塊大小。

[root@db2 root]# dd if=/dev/zero of=/home/ bs=1024 count=1024000
 1024000+0 records in
 1024000+0 records out
 [root@db2 root]#

使用以下命令來設定交換檔案:

[root@db2 root]# mk /home/
 Setting up space version 1, size = 1023996 KiB
 [root@db2 root]#

3、啟用交換檔案

要立即啟用交換檔案而不是在引導時自動啟用,使用以下命令:

[root@db2 root]# on /home/

檢查增加後的交換情況:

[root@db2 root]# free -m
              total       used       free     shared    buffers     cached
 Mem:          1006        994         12          0          4        929
 -/+ buffers/cache:         60        946
 :          999          0        999
 [root@db2 root]#

要在引導時啟用,編輯 /etc/fstab 檔案來包含以下行(/home/ defaults 0 0 ):

[root@db2 root]# vi /etc/fstab
 LABEL=/                 /                   ext3    defaults        1 1       
 LABEL=/boot             /boot               ext2    defaults        1 2      
/home/                                       defaults        0 0
 none                    /dev/pts                devpts  gid=5,mode=620  0 0      
none                    /proc                   proc    defaults        0 0      
none                    /dev/shm                tmpfs   defaults        0 0      
LABEL=/usr              /usr                    ext3    defaults        1 2      
/dev/sda5                                       defaults        0 0      
/dev/cdrom              /mnt/cdrom              iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0   
/home/                                       defaults        0 0

下次引導時,它就會啟用新建的交換檔案,再次檢查新增後的情況:

[root@db2 oracledb]# free -m                                             
                     total       used       free     shared    buffers     cached
        Mem:          1006        979         27          0          6        917
        -/+ buffers/cache:         54        952                                 
        :          999          0        999                                 
        [root@db2 oracledb]#
[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16396910/viewspace-1040849/,如需轉載,請註明出處,否則將追究法律責任。

相關文章