CentOS7减小/home分区空间,扩大/f分区空间
方法:
把/home分区内容备份,然后将/home文件系统所在的逻辑卷删除,扩大/文件系统。
新建/home分区,恢复/home分区内容
1、查看默认分区
[root@server ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.3M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos_server-root 50G 4.2G 46G 9% /
/dev/sda1 1014M 172M 843M 17% /boot
/dev/mapper/centos_server-home 47G 33M 47G 1% /home
tmpfs 98M 8.0K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
[root@server ~]#
可以看到两个lvs
/dev/mapper/centos_server-root 对应/
/dev/mapper/centos_server-home 对应/home
2、查看卷组信息
[root@server home]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos_server lvm2 a-- <99.00g 4.00m
[root@server home]# vgs
VG #PV #LV #SN Attr VSize VFree
centos_server 1 3 0 wz--n- <99.00g 4.00m
[root@server home]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos_server -wi-ao---- 46.99g
root centos_server -wi-ao---- 50.00g
swap centos_server -wi-ao---- 2.00g
[root@server home]#
3、把/home内容备份,#备份/home
[root@server home]# tar cvf /tmp/home.tar /home
tar: 从成员名中删除开头的“/”
/home/
/home/admin/
/home/admin/.mozilla/
/home/admin/.mozilla/extensions/
/home/admin/.mozilla/plugins/
/home/admin/.bash_logout
/home/admin/.bash_profile
/home/admin/.bashrc
[root@server home]#
4、然后将/home文件系统所在的逻辑卷删除
#卸载/home,如果无法卸载,先终止使用/home文件系统的进程
[root@server ~]# umount /home
umount: /home:目标忙。
(有些情况下通过 lsof(8) 或 fuser(1) 可以
找到有关使用该设备的进程的有用信息)
[root@server ~]#
[root@server ~]# fuser -km /home
/home: 1527
[root@server ~]#
然后继续卸载
[root@server ~]# umount /home
[root@server ~]#
5、#删除/home所在的lv逻辑卷
[root@server ~]# lvremove /dev/mapper/centos_server-home
Do you really want to remove active logical volume centos_server/home? [y/n]: y
Logical volume "home" successfully removed
[root@server ~]#
6、扩大/文件系统
#扩展/所在的lv,增长10G
[root@server ~]# lvextend -L +10G /dev/mapper/centos_server-root
Size of logical volume centos_server/root changed from 50.00 GiB (12800 extents) to 60.00 GiB (15360 extents).
Logical volume centos_server/root successfully resized.
[root@server ~]#
7、#扩展/文件系统
[root@server ~]# xfs_growfs /dev/mapper/centos_server-root
meta-data=/dev/mapper/centos_server-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 shome" created.
[root@server ~]#
9、#建立文件系统
[root@server ~]# mkfs.xfs /dev/mapper/centos_server-home
meta-data=/dev/mapper/centos_server-home isize=512 agcount=4, agsize=1966080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@server ~]#
#挂载
[root@server ~]# mount /dev/mapper/centos_server-home /home
[root@server ~]#
10、查看
[root@server ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.3M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos_server-root 60G 4.2G 56G 7% /
/dev/sda1 1014M 172M 843M 17% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/centos_server-home 30G 33M 30G 1% /home
[root@server ~]#
11、文件恢复
[root@server home]# tar xvf /tmp/home.tar -C /
home/
home/admin/
home/admin/.mozilla/
home/admin/.mozilla/extensions/
home/admin/.mozilla/plugins/
home/admin/.bash_logout
home/admin/.bash_profile
home/admin/.bashrc
[root@server home]# ls
admin
[root@server home]#
12、查看卷组信息
[root@server home]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos_server lvm2 a-- <99.00g <7.00g
[root@server home]# vgs
VG #PV #LV #SN Attr VSize VFree
centos_server 1 3 0 wz--n- <99.00g <7.00g
[root@server home]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home centos_server -wi-ao---- 30.00g
root centos_server -wi-ao---- 60.00g
swap centos_server -wi-ao---- 2.00g
[root@server home]#