一、操作过程
1.df -h查看分区大小情况;
-
[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分区
[root@localhost /]# umount /home
3.查看卸载情况
-
[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分区
-
[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分区的大小:
-
[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分区
[root@localhost /]# mount /home
7.查看挂载情况
-
[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逻辑分区减小到指定大小
-
[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.查询卷组的信息:
-
[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分区的大小:
-
[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
二、遇到问题解决办法
1、在卸载/home目录的时候失败
可先执行如下fuser命令,然后再umount即可:
[root@CentOS-78 /]# fuser -m /home
2、设定完lv_home的大小,再次mount该分区时,发现用df命令无法看到给分区,此时只要在mount一次即可
3、在设定lv_root的大小时,不要把Free PE / Size的空间全部都用上,这很可能会出现Free PE空间不足的现象,建议保留一点Free PE的空间。