Centos修改與刪除Swap虛擬記憶體大小方法

來源:互聯網
上載者:User

一、修改swap的全部步驟:

[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

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

[root@localhost tmp]# free -m
total used free shared buffers cached
Mem: 772 91 681 0 6 30
-/+ buffers/cache: 53 718
Swap: 1567 0 1567

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

[root@localhost tmp]# dd if=/dev/zero of=/tmp/big_swap bs=1024 count=2000000
記錄了2000000+0 的讀入
記錄了2000000+0 的寫出
2048000000位元組(2.0 GB)已複製,69.5342 秒,29.5 MB/秒
(注意:if 表示 infile,of 表示outfile,bs=1024 表示寫入的每個塊的大小為1024B=1KB(1024B位元組=1024*8bit位)

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

[root@localhost tmp]# du -sh big_swap
2.0G        big_swap
[root@localhost tmp]# ls -al big_swap

-rw-r--r-- 1 root root 2048000000 12月 1 14:25 big_swap

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

[root@localhost tmp]# mkswap big_swap
mkswap: big_swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1999996 KiB
no label, UUID=25c3eaf2-43f9-487b-87b7-f76a712f5376

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

[root@localhost tmp]# swapon big_swap
6、再次查看記憶體和虛擬記憶體,發現已經被正常修改:

[root@localhost tmp]# free -m
total used free shared buffers cached
Mem: 772 705 66 0 2 627
-/+ buffers/cache: 75 697

Swap: 3521 0 3521
7、若要想使開機時自啟用,則需修改檔案/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


二.刪除swap分區

有時可能會需要刪除swap分區,該如何正確進行刪除分區哪?
首先停止swap分區

swapoff   /swap/swap

刪除swap分區檔案

rm -rf /swap/swap

刪除"/etc/swap"指定檔案

sed  -i "/'\/swa\/swap   swap   swap  defaults 0 0'//"  /etc/fstab

這樣就可以手工添加和刪除swap分區。

相關文章

聯繫我們

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