Linux下設定swap(虛擬記憶體區)__Linux

來源:互聯網
上載者:User

[root@gamedb ~]# free –m

[root@gamedb tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000

[root@gamedb tmp]# du -sh /tmp/big_swap

[root@gamedb tmp]# mkswap /tmp/big_swap

[root@gamedb tmp]# swapon /tmp/big_swap

[root@gamedb tmp]# free –m

[root@gamedb tmp]# vi /etc/fstab

# LABEL=SWAP-hda2         swap                    swap    defaults        0 0

  /tmp/big_swap           swap                    swap    defaults        0 0

 

=========================================================================================== 

一、查看記憶體和swap大小,發現swap是記憶體大小的一半

 [root@gamedb ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1001        338        662          0          8        307

-/+ buffers/cache:         22        978

Swap:          509          0        509

=========================================================================================== 

二、決定修改swap大小,首先在空間合適處建立用於分區的swap檔案:

[root@gamedb tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000

讀入了 2000000+0 個塊

輸出了 2000000+0 個塊

(注意:if 表示 infile,of 表示outfile,bs=1024 表示寫入的每個塊的大小為1024B=1KB(1024B位元組=1024*8bit位)

 ===========================================================================================

三、查看建立的檔案大小是否符合要求:

[root@gamedb tmp]# du -sh big_swap

2.0G    big_swap

[root@gamedb tmp]# ls -al big_swap

-rw-r--r--  1 root root 2048000000  6月 18 11:55 big_swap

 ===========================================================================================

四、將目的檔案設定為swap分區檔案:

[root@gamedb tmp]# mkswap big_swap

Setting up swapspace version 1, size = 2047995 kB

 ===========================================================================================

五、啟用swap,立即啟用交換分區檔案:

[root@gamedb tmp]# swapon big_swap

 ===========================================================================================

六、再次查看記憶體和虛擬記憶體,發現已經被正常修改:

[root@gamedb tmp]# free -m

             total       used       free     shared    buffers     cached

Mem:          1001        984         16          0          2        931

-/+ buffers/cache:         50        950

Swap:         2462          0       2462

 ===========================================================================================

七、若要想使開機時自啟用,則需修改檔案/etc/fstab中的swap行:

[root@gamedb tmp]# vi /etc/fstab

# LABEL=SWAP-hda2         swap                    swap    defaults        0 0

  /tmp/big_swap           swap                    swap    defaults        0 0

 ===========================================================================================

 

 

附:fstab檔案詳解:

fstab中存放了與分區有關的重要訊息,其中每一行為一個分區記錄,每一行又可分為六個部份,下面以 /dev/hda7 / ext2 defaults 1 1 為例逐個說明:

  1. 第一項是您想要mount的儲存裝置的實體位置,如hdb或/dev/hda6。

  2. 第二項就是您想要將其加入至哪個目錄位置,如/home或/,這其實就是在安裝時提示的掛入點。

  3. 第三項就是所謂的local filesystem,其包含了以下格式:如ext、ext2、msdos、iso9660、nfs、swap等,或如ext2,可以參見/prco/filesystems說明。

  4. 第四項就是您mount時,所要設定的狀態,如ro(唯讀)或defaults(包括了其它參數如rw、suid、exec、auto、nouser、<

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.