lvm分区将home删除合并到根路径扩充目录磁盘空间

lvm分区将home删除合并到根路径扩充目录磁盘空间


1、分区结构删除home划分到根

[root@docker registry-1.docker.io]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 50G 2.1G 48G 5% /
/dev/mapper/centos-home 146G 33M 146G 1% /home
/dev/sda1 1014M 151M 864M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0

2、备份/home/*路径下的所有文件

cp   -ra     /home    /tmp/home

3、卸载home分区并删除home
删除前

[root@docker /]# vgdisplay
— Volume group —
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 12yqlJ-K0VP-dzvN-Vq3J-yBWN-UeOP-vcP6Bo

卸载分区前不要在home路径里不然会报错路径在占用无法卸载

  #  umount  /home/
  #  lvremove  /dev/centos/home 

删除后

[root@docker /]# vgdisplay
— Volume group —
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 13792 / <53.88 GiB
Free PE / Size 37151 / 145.12 GiB
VG UUID 12yqlJ-K0VP-dzvN-Vq3J-yBWN-UeOP-vcP6Bo

4、扩展分区大小根据vgdisplay中的free输入

# lvextend  -L  145.1G  /dev/centos/root 

5、查看分区格式为xfs,输入xfs_growfs扩展

[root@docker /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 50G 2.1G 48G 5% /
/dev/sda1 xfs 1014M 151M 864M 15% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/sr0 iso9660 4.5G 4.5G 0 100% /mnt

# xfs_growfs  /dev/centos/root 

meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 38037504

6、删除或注释启动挂载home配置

# vi /etc/fstab

# /etc/fstab
# Created by anaconda on Wed Oct 14 18:05:19 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-root / xfs defaults 0 0
UUID=acbe3d77-dbc5-41f7-aec1-ce6c521b15e0 /boot xfs defaults 0 0
#/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0

7、如果有home备份的还原回来,查看扩容是否成功,

#mv  /tmp/home  /home

[root@docker /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 146G 2.1G 144G 2% /
/dev/sda1 1014M 151M 864M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0
/dev/sr0 4.5G 4.5G 0 100% /mnt

你可能感兴趣的:(linux,#,centos,linux,centos,lvm)