centos7 home目录空间释放添加到指定分区
- 备份home目录
cd /home
tar czvf /home.tgz /home
这样,会在/下生成名叫home.tgz的压缩包,您可以在扩大/home目录后将这个包 解回到新的/home目录中
cd /
tar zxvf /home.tgz -C /
如果/home中确实没有什么有用的数据,这一步也可以省略。
在配置中删除home
vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Sep 14 10:59:58 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos_llilei-root / xfs defaults 0 0
UUID=f9d37ca9-9024-40e5-9587-b0262b887d2f /boot xfs defaults 0 0
UUID=C9FE-4CEC /boot/efi vfat umask=0077,shortname=winnt 0 0
/dev/mapper/centos_llilei-data /data xfs defaults 0 0
/dev/mapper/centos_llilei-swap swap swap defaults 0 0
~
~
~
删除需要删除的分区后保存
卸载home分区
umount /home
合并分区
- 卸载分区后空间还没有合并过来
[/]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.8G 4.0K 7.8G 1% /dev/shm
tmpfs 7.8G 34M 7.7G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos_llilei-root 50G 23G 28G 45% /
/dev/sda2 1014M 308M 707M 31% /boot
/dev/sda1 200M 12M 189M 6% /boot/efi
/dev/mapper/centos_llilei-data 800G 561G 240G 71% /data
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/997
- 我们使用 lvscan 命令查看lv的逻辑分区
[/]# lvscan
ACTIVE '/dev/centos_llilei/root' [50.00 GiB] inherit
ACTIVE '/dev/centos_llilei/swap' [3.75 GiB] inherit
ACTIVE '/dev/centos_llilei/data' [800.00 GiB] inherit
ACTIVE '/dev/centos_llilei/home' [<76.56 GiB] inherit
- 可以看到最后一行就是我们需要删除的分区
[/]# lvremove /dev/centos_llilei/home
Do you really want to remove active logical volume centos_llilei/home? [y/n]: y
Logical volume "home" successfully removed
- 使用lvremove 删除后再次查看
[/]# lvscan
ACTIVE '/dev/centos_llilei/root' [50.00 GiB] inherit
ACTIVE '/dev/centos_llilei/swap' [3.75 GiB] inherit
ACTIVE '/dev/centos_llilei/data' [800.00 GiB] inherit
- 之后合并分区
[/]# vgdisplay
--- Volume group ---
VG Name centos_llilei
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.31 GiB
PE Size 4.00 MiB
Total PE 238160
Alloc PE / Size 218560 / 853.75 GiB
Free PE / Size 19600 / 76.56 GiB
VG UUID kDKNjq-224i-XkRp-e22W-kXWJ-fs1K-vqPve7
可以看到空闲空间有76G
将空闲分区加到data分区上
[/]# lvextend -l +100%free /dev/mapper/centos_llilei-data
Size of logical volume centos_llilei/data changed from 800.00 GiB (204800 extents) to 876.56 GiB (224400 extents).
Logical volume centos_llilei/data successfully resized.
再次查看
[/]# vgdisplay
--- Volume group ---
VG Name centos_llilei
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
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.31 GiB
PE Size 4.00 MiB
Total PE 238160
Alloc PE / Size 238160 / 930.31 GiB
Free PE / Size 0 / 0
VG UUID kDKNjq-224i-XkRp-e22W-kXWJ-fs1K-vqPve7
- 现在使用 df -h查看空间还是没有的,需要使用xfs_growfs命令刷新一下
[/]# xfs_growfs /dev/mapper/centos_llilei-data
meta-data=/dev/mapper/centos_llilei-data isize=512 agcount=4, agsize=52428800 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=209715200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=102400, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 209715200 to 229785600
home文件夹数据恢复
解压刚才备份的文件
[/]# tar zxvf /home.tgz -C /
home/
home/black/
home/www/
home/www/.bash_logout
home/www/.bash_profile
home/www/.bashrc
home/super/
home/super/.bash_logout
home/super/.bash_profile
home/super/.bashrc
最后数据无价还是提醒下朋友做好备份
标题:centos7 home目录空间释放添加到指定分区
作者:llilei
地址:http://solo.llilei.work/articles/2021/10/07/1633587139875.html