linux中增加swap分區檔案,linux增加swap分區

來源:互聯網
上載者:User

linux中增加swap分區檔案,linux增加swap分區

inux中增加swap分區檔案的步驟方法:

1、檢查當前的swap情況(使用free -h或cat /proc/swaps或swapon -s ):

[root@compute ~]# free -h              total        used        free      shared  buff/cache   availableMem:           1.8G        329M        1.2G        8.3M        242M        1.3GSwap:          511M          0B        511M

 

2、查看硬碟使用方式(df -hal):

[root@compute ~]# df -lhFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   15G  2.4G   13G  16% /devtmpfs                 909M     0  909M   0% /devtmpfs                    920M     0  920M   0% /dev/shmtmpfs                    920M  8.4M  912M   1% /runtmpfs                    920M     0  920M   0% /sys/fs/cgroup/dev/mapper/centos-home   55G   33M   55G   1% /home/dev/sda1                797M  180M  618M  23% /boottmpfs                    184M     0  184M   0% /run/user/0

 

3、使用dd命令建立名為swapfile 的swap分頁檔(檔案名稱和目錄任意):

dd  if=/dev/zero  of=/var/swapfile  bs=1024  count=2048k

  

   科普:if(即輸入檔案,input file),of(即輸出檔案,output file)。dev/zero是Linux的一種特殊字元裝置(輸入裝置),可以用來建立一個指定長度用於初始化的空檔案,如臨時分頁檔,該裝置無窮盡 地提供0,可以提供任何你需要的數目。 bs=1024  :單位元據塊(block)同時讀入/輸出的塊位元組大小為1024  個位元組即1KB,bs(即block size)。count=2048000  :資料區塊(block)數量為2048000 ,即2048000個1KB。可以計算swap分區的容量為:1KB *2097152=1KB *1024(k)*1024*2=2097152=2G。(dd命令裡的單位M表示1024*1024,k表示1024)。

        斷行符號後,會執行2g的讀寫操作,系統會卡一段時間,耐心等待執行結果。

執行完畢,對分頁檔格式化並轉換為swap分區:

mkswap  /var/swapfile

 

4、掛載並啟用分區:

swapon   /var/swapfile

 

5、這時候可以用 free –h 或 swapon –s命令查看新swap分區是否正常添加並啟用使用。

修改 fstab 配置,設定開機自動掛載該分區:

vim    /etc/fstab

/swapfile               swap                    swap    defaults        0 0

 

 參考:http://blog.csdn.net/ausboyue/article/details/73433990

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.