Linux下磁碟保留空間的調整,解決df看到的空間和實際磁碟大小不一致的問題

來源:互聯網
上載者:User

標籤:硬碟   5%   

linux的硬碟分區程式會自動為root或指定的使用者保留一定的磁碟空間預設是5%,在較大的分區或是不重要的分區上這種設定會佔據過多不必要的空間, 利用mke2fs的-m reserved-percentage選項可以調整這個設定來獲得更多的磁碟空間且不影響效能。而在建立了檔案系統之後,使用者可以用tune2fs來修 改這個設定比如tune2fs -m 1 /dev/sda4 可以將保留的空間設定為1%

看 mkfs.ext3 的man page,就可以知道原因了,其中有這麼一句:
-m reserved-blocks-percentage
Specify the percentage of the filesystem blocks reserved for the
super-user.   This  avoids  fragmentation, and allows root-owned
daemons, such as syslogd(8), to continue to  function  correctly
after non-privileged processes are prevented from writing to the
filesystem.  The default percentage is 5%.

也就是說,ext檔案系統,包括ext2、ext3、ext4都會預設預留5%的磁碟空間,留給root使用者維護系統或者記錄系統關鍵日誌的時候使用(比如磁碟使用空間已經100%的情況下的處理),這也就是導致普通使用者無法使用部分磁碟空間的原因了。

如:

$ df -hl /dev/sda6
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 42G 34G 5.8G 86% /linux/sda6

$ tune2fs -m 0 /dev/sda6
tune2fs 1.41.3 (12-Oct-2008)
Setting reserved blocks percentage to 0% (0 blocks)

$ df -hl /dev/sda6
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 42G 34G 7.9G 81% /linux/sda6

另外一個具體操作過程如下,已經加了詳細注釋:

--之前的保留區有 732463 塊
# tune2fs -l /dev/sda7 | grep "Reserved block count"
Reserved block count:     732463

--已用空間+可用空間 和 總空間 相比,還少了近3個G
# df
檔案系統             1K-塊      已用      可用 已用% 掛載點
/dev/sda7             57677500  47662588   7085060  88% /home

--調整:
# tune2fs -r 25600 /dev/sda7
tune2fs 1.41.9 (22-Aug-2009)
Setting reserved blocks count to 25600

--再來看看空間
# df
檔案系統             1K-塊      已用      可用 已用% 掛載點
/dev/sda7             57677500  47662584   9912516  83% /home

--確認調整成功
# sudo tune2fs -l /dev/sda7 | grep "Reserved block count"
Reserved block count:     25600

多了3G多的空間。而且還不是直接完全去掉保留區塊,也留了百多兆以防不時之需。

聯繫我們

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