系统安装好后,发现home分区过大,想从home分区中拿出100G给/分区
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 205G 2.2G 203G 2% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 49M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 139M 59M 71% /boot
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/mapper/centos-home xfs 718G 33M 718G 1% /home
[root@localhost ~]# umount /home/
[root@localhost ~]# lvreduce -L -100G /dev/mapper/centos-home
WARNING: Reducing active logical volume to 618.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
Size of logical volume centos/home changed from 718.00 GiB (183808 extents) to 618.00 GiB (158208 extents).
Logical volume centos/home successfully resized.
如下,很显然xfs文件系统不能执行分区减小的调整!
[root@localhost ~]# xfs_growfs /dev/mapper/centos-home
xfs_growfs: /dev/mapper/centos-home is not a mounted XFS filesystem
[root@localhost ~]# mount /dev/mapper/centos-home /home/
mount: /dev/mapper/centos-home:不能读超级块
这样,只能通过重新格式化这个分区,格式化后才能再次挂载到home下
[root@localhost ~]# mkfs.xfs /dev/mapper/centos-home -f
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=41156608 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=164626432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=80384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount /dev/mapper/centos-home /home/
再次查看分区,发现home分区已经减小了100G,只不过这个分区里之前的数据都没有了。
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 205G 2.2G 203G 2% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 49M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 139M 59M 71% /boot
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/mapper/centos-home xfs 618G 73M 578G 1% /home
---------------------------------------------------------------------------
上面在重新格式的时候,也可以将这个格式化为ext4格式。
[root@localhost ~]# mkfs.ext4 /dev/mapper/centos-home
[root@localhost ~]# cat /etc/fstab //将home分区的开机挂载设置里的xfs改为ext4
---------------------------------------------------------------------------
然后将上面从home分区拿出的100G放到/分区下
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 9
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.80 GiB
PE Size 4.00 MiB
Total PE 238285
Alloc PE / Size 211456 / 826.00 GiB
Free PE / Size 26829 / 104.80 GiB
VG UUID a5hiAh-LB8M-9lRv-Ps1a-z35L-J4fk-sP3KrF
[root@localhost ~]# lvextend -L +100G /dev/mapper/centos-root
Size of logical volume centos/root changed from 205.00 GiB (52480 extents) to 305.00 GiB (78080 extents).
Logical volume centos/root successfully resized.
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256 agcount=5, agsize=13107200 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=53739520, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=25600, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 53739520 to 79953920
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 305G 2.2G 203G 2% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 49M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 139M 59M 71% /boot
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/mapper/centos-home xfs 618G 73M 578G 1% /hom
|