centos調整root的空間大小

來源:互聯網
上載者:User

centos調整root的空間大小

1、首先查看磁碟使用方式
df -h

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_guoyixian-lv_root 50G 35G 12G 75% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 55M 397M 13% /boot
/dev/mapper/vg_guoyixian-lv_home 864G 1.9G 818G 1% /home

2、卸載/home
umount /home
如果提示無法卸載,則是有進程佔用/home,使用如下命令來終止佔用進程
fuser -m /home

3、調整分區大小
resize2fs -p /dev/mapper/vg_guoyixian-lv_home 20G
如果提示運行“e2fsck -f /dev/mapper/vg_guoyixian-lv_home”,則執行相關命令:
e2fsck -f /dev/mapper/vg_guoyixian-lv_home
重新執行一遍
resize2fs -p /dev/mapper/vg_guoyixian-lv_home 20G
註:resize2fs 為重新設定磁碟大小,只是重新指定一下大小,並不對結果有影響,需要下面lvreduce的配合

4、掛載上/home,查看磁碟使用方式
mount /home
df -h

5、設定空閑空間
使用lvreduce指令用於減少LVM邏輯卷佔用的空間大小。可能會刪除邏輯卷上已有的資料,所以在操作前必須進行確認。記得輸入 “y”
lvreduce -L 20G /dev/mapper/vg_guoyixian-lv_home
註:lvreduce -L 20G的意思為設定當前檔案系統為20G,如果lvreduce -l 20G是指從當前檔案系統上減少20G
使用lvreduce減小邏輯卷的大小。
注意:減小後的大小不能小於檔案的大小,否則會遺失資料。

可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看詳細資料。

vgdisplay

註:vgdisplay為顯示LVM卷組的中繼資料資訊

6、把閑置空間掛在到根目錄下
lvextend -L +700G /dev/mapper/vg_guoyixian-lv_root
註:lvextend -L +700G為在檔案系統上增加700G
resize2fs -p /dev/mapper/vg_guoyixian-lv_root

這個過程時間很長,有幾十分鐘

7、最後檢查調整結果
df -h

聯繫我們

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