Centos home空間重分配

1、操做過程

1.df -h查看分區大小狀況;node

[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 1.9G 45G 5% /
tmpfs 7.5G 0 7.5G 0% /dev/shm
/dev/sda1 477M 90M 362M 20% /boot
/dev/mapper/VolGroup-lv_home
860G 101M 816G 1% /home
tmpfs 4.0G 0 4.0G 0% /var/spool/MailScanner/incoming

2.卸載home分區app

[root@localhost /]# umount /home

3.查看卸載狀況ui

[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 1.9G 45G 5% /
tmpfs 7.5G 0 7.5G 0% /dev/shm
/dev/sda1 477M 90M 362M 20% /boot
tmpfs 4.0G 0 4.0G 0% /var/spool/MailScanner/incoming

4.從新整合home分區code

[root@localhost /]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup-lv_home: 50/57212928 files (10.0% non-contiguous), 3649291/228843520 blocks

5.重新設定home分區的大小:orm

[root@localhost /]# resize2fs -p /dev/mapper/VolGroup-lv_home 50G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 13107200 (4k) blocks.
Begin pass 2 (max = 32849)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 6984)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 17)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 13107200 blocks long.

6.從新掛載home分區ci

[root@localhost /]# mount /home

7.查看掛載狀況it

[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 1.9G 45G 5% /
tmpfs 7.5G 0 7.5G 0% /dev/shm
/dev/sda1 477M 90M 362M 20% /boot
tmpfs 4.0G 0 4.0G 0% /var/spool/MailScanner/incoming
/dev/mapper/VolGroup-lv_home
50G 81M 47G 1% /home

8.將lv_home邏輯分區減少到指定大小io

[root@localhost /]# lvreduce -L 50G /dev/mapper/VolGroup-lv_home
Rounding size to boundary between physical extents: 52.00 MiB.
WARNING: Reducing active and open logical volume to 52.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce VolGroup/lv_home? [y/n]: y
Size of logical volume VolGroup/lv_home changed from 872.97 GiB (223480 extents) to 52.00 MiB (13 extents).
Logical volume lv_home successfully resized.

9.查詢卷組的信息:table

[root@localhost /]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 930.51 GiB
PE Size 4.00 MiB
Total PE 238210
Alloc PE / Size 14743 / 57.59 GiB
Free PE / Size 223467 / 872.92 GiB  #Free PE / Size指定的應該是如今可在分配的空間
VG UUID Acapyj-Dw5o-Hi3c-RLVe-AmHl-AD83-Nek4Qv

10.增長root分區的大小
[root@localhost /]# lvextend -L +870G /dev/mapper/VolGroup-lv_root
11.重新設定root分區的大小:form

[root@localhost /]# resize2fs -p /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 58
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 241696768 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 241696768 blocks long.

12.從新查看分區大小

[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
908G 1.9G 860G 1% /
tmpfs 7.5G 0 7.5G 0% /dev/shm
/dev/sda1 477M 90M 362M 20% /boot
tmpfs 4.0G 0 4.0G 0% /var/spool/MailScanner/incoming
/dev/mapper/VolGroup-lv_home
50G 81M 47G 1% /home

2、遇到問題解決辦法

一、在卸載/home目錄的時候失敗
可先執行以下fuser命令,而後再umount便可:

[root@CentOS-78 /]# fuser -m /home

二、設定完lv_home的大小,再次mount該分區時,發現用df命令沒法看到給分區,此時只要在mount一次便可 三、在設定lv_root的大小時,不要把Free PE / Size的空間所有都用上,這極可能會出現Free PE空間不足的現象,建議保留一點Free PE的空間。

相關文章
相關標籤/搜索