CentOS 版本:6.6
- 檢查邏輯磁卷的相關資訊
 lvdisplay
 顯示內容如下:(部分敏感內容以 OOXX 取代)
 [dev]$ lvdisplay
 --- Logical volume ---
 LV Path /dev/vg_OOXX/lv_root
 LV Name lv_root
 VG Name vg_OOXX
 LV UUID oPVxAh-cu2y-4750-9hNJ-XmBY-It8B-KgWGGf
 LV Write Access read/write
 LV Creation host, time OOXX, 2015-06-10 12:12:10 +0800
 LV Status available
 # open 1
 LV Size 50.00 GiB
 Current LE 12800
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:0
 --- Logical volume ---
 LV Path /dev/vg_OOXX/lv_home
 LV Name lv_home
 VG Name vg_OOXX
 LV UUID hTClT0-QN8A-4pNP-U7Wp-RIoa-oj5i-rQd4Re
 LV Write Access read/write
 LV Creation host, time OOXX, 2015-06-10 12:12:22 +0800
 LV Status available
 # open 1
 LV Size 441.68 GiB
 Current LE 113070
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:2
 --- Logical volume ---
 LV Path /dev/vg_OOXX/lv_swap
 LV Name lv_swap
 VG Name vg_OOXX
 LV UUID d3WPau-VfG9-2ida-CkiS-t7pp-k7om-VEtRri
 LV Write Access read/write
 LV Creation host, time OOXX, 2015-06-10 12:13:36 +0800
 LV Status available
 # open 1
 LV Size 7.83 GiB
 Current LE 2004
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:1
 
- 檢查既有磁碟掛載項目
 df -h
 顯示內容如下:
 [dev]$ df -h
 Filesystem Size Used Avail Use% Mounted on
 /dev/mapper/vg_OOXX-lv_root 50G 49G 0 100% /
 tmpfs 3.9G 0 3.9G 0% /dev/shm
 /dev/sda1 679G 89M 644G 1% /boot
 /dev/mapper/vg_OOXX-lv_home 435G 166M 413G 1% /home
 
 上述的 root 已無空間可使用,故要縮小 home 的磁卷大小,將釋放出的空間給 home 使用
 
- 卸載 home 磁卷
 umount /home/
 
 此步驟若是出現無法正常卸載,則利用
 fuser -m /home 查詢哪一個執行序正在使用該磁卷(Ref. 2)
 將該執行緒刪除即可
 若是遠端連入操作,則刪除時極有可能會把遠端連線刪除,故建議一定要在本機上操作
 
- 卸載 /home 之後,先檢查該磁卷狀態,若無錯誤訊息,繼續執行下一個步驟
 e2fsck -f /dev/mapper/vg_OOXX-lv_home
 
- 在檔案系統中,將 home 大小從 435G 縮減為 30G
 resize2fs /dev/mapper/vg_OOXX-lv_home 30G
 
- 檢查邏輯磁卷是否已經更新
 lvdisplay | less
 參數 | less 用於讓顯示結果一頁一頁顯示,避免還需往回捲動察看
 
- 檢查磁卷群組可使用的閒置空間(Free space)
 vgdisplay
 
 此步驟由於尚未進行縮減邏輯磁卷的動作,所以 Free space 的地方仍會顯示 0
 
- 將邏輯磁卷 home 的大小縮減為 30G
 lvreduce -L 30G /dev/mapper/vg_OOXX-lv_home
 
 執行過程會詢問是否縮減,請按下 y
 
- 檢查可用來擴充的空間大小有多少
 vgdisplay
 
 此例顯示的 Free Space 為 411.68 G
 
- 再次執行縮減 home 空間的指令,此步驟以確認為主,執行結果應會顯示 Nothing to do.
 resize2fs /dev/mapper/vg_OOXX-lv_home 30G
 
- 將可用的 411G 分配給 root 磁卷
 lvextend -L +411G /dev/mapper/vg_OOXX-lv_root
 
- 確認邏輯磁卷 root 的空間大小是否已經完成調整
 lvdisplay | less
 
- 確認 root 空間大小是否已經更新
 df -h
 由於尚未在檔案系統中重新調整大小,此處的 root 空間仍會顯示舊有資訊
 
- 在檔案系統中更改 root 的空間大小
 resize2fs /dev/mapper/vg_OOXX-lv_root
 此過程所需運作時間視空間大小而不同,空間越大所需時間越久,以本例而言,約 10 分鐘
 
- 檢查磁卷大小是否已經更新
 df -h
 
- 將一開始卸載的磁區重新掛載
 mount -a
 
- 確認是否有將之前 umount 的磁卷重新掛載
 df -h
參考網址:
1. reduce and extend logical volume in centos, https://youtu.be/zJYjh_r00zA
2. https://blog.longwin.com.tw/2008/11/debian-ubuntu-linux-umount-device-busy-2008/
