Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 建立與移除 swap 交換分區/檔案完整操作指南

編輯:關於 Linux

swap 相當於 Windows 虛擬記憶體,物理記憶體不足時交換閒置頁面至磁碟。可建立獨立分區或交換檔案。

建立交換檔案(以 1GB 為例)

  1. dd if=/dev/zero of=/swap/swap bs=1024 count=1024000(建立 1GB 空檔)。
  2. mkswap /swap/swap(格式化為 swap 區)。
  3. swapon /swap/swap(立即啟用)。
  4. 驗證:free -m 顯示 Swap 行非零。
  5. 永久掛載:編輯 /etc/fstab 加入 /swap/swap swap swap defaults 0 0。

移除 swap

  1. swapoff /swap/swap(停用)。
  2. rm -rf /swap/swap(刪除檔案)。
  3. 編輯 /etc/fstab 刪除對應行,或 sed -i '/\/swap\/swap/d' /etc/fstab。

若為獨立分區,步驟 1 改用 mkswap /dev/sdXn,/etc/fstab 掛載裝置路徑。建議 swap 大小為實體記憶體 1-2 倍(大記憶體機器可適當減少)。

Copyright © Windows教程網 All Rights Reserved