萬盛學電腦網

 萬盛學電腦網 >> 服務器教程 >> Linux系統怎麼調整swap分區大小?

Linux系統怎麼調整swap分區大小?

   這裡介紹Linux系統中調整swap大小的方法。

40.jpg
41.jpg

  1、使用free命令帶上m參數,查看swap文件大小,官方建議在RAM是2到4.5G時,swap是RAM的2倍;如果RAM大於等於4G則swap等於RAM即可

42.jpg

  2、也可用cat 查看etc目錄下的swaps文件,如下圖

44.jpg

  3、創建一個swap文件

  復制內容到剪貼板

  ########

  dd if=/dev/zero of=/tmp/swap bs=1MB count=1024

  ########

  以下僅供參考:不用看

  Creating a swap file

  First of, make sure the file system the disk you wish to swap on is properly mounted. For the purposes of this tutorial we will assume the disk is mounted as /mnt and we want to use the file /mnt/myswap.swp for swapping.

  使用下面的命令創建一個1G的swap文件

  復制內容到剪貼板

  Use the following command to create a 1024MB file that we will use for swapping

  ########

  dd if=/dev/zero of=/mnt/myswap.swp bs=1024MB count=1

  ########

45.jpg

  4、制作一個swap文件,如果覺得繁瑣,可以將mkswap文件掛載到tmp目錄下,例如:

  復制內容到剪貼板

  ########

  mkswap /tmp/swap

  ########

  以下僅供參考:不用看

  Preparing the swap file

  Before we enable the swap file we must first set it up. The following command accomplishes just that:

  ########

  mkswap /mnt/myswap.swp

  ########

  5、使用swapon 啟動/tmp/swap

  復制內容到剪貼板

  ########

  swapon /tmp/swap

  ########

  使用一個swap分區,如果已經有一個swap分區,該步驟可以省略

  以下僅供參考:不用看

  Using a swap partition

  Setting up a swap partition is a bit more difficult, as the partition must be first created then formatted using the linux-swap file system. Once that is done, assuming the swap partition is at/dev/scsi/host0/bus0/target0/lun0/part5 (common for v24 USB drives with mutiple partitions), the only command that needs be issued is:

46.jpg

  6、再次使用free查看增加後的swap大小

47.jpg

  7、如果只想增加swap大小,請忽略以下的操作,重要!!如果不使用剛才增加的1G的swap文件,使用下面的swapoff命令,可以關閉,這樣swap文件就縮小了1G

  使用swapoff關閉swap文件

  復制內容到剪貼板

  ########

  swapoff /tmp/swap

  ########

  注意事項:如果只想增加swap大小,請忽略第7步的所有操作。

copyright © 萬盛學電腦網 all rights reserved