1.查看root和home下的容量
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 50G 952M 50G 2% / devtmpfs 63G 0 63G 0% /dev tmpfs 63G 0 63G 0% /dev/shm tmpfs 63G 9.1M 63G 1% /run tmpfs 63G 0 63G 0% /sys/fs/cgroup /dev/sda2 1014M 139M 876M 14% /boot /dev/mapper/cl-home 5.3T 33M 5.3T 1% /home tmpfs 13G 0 13G 0% /run/user/0home下面有5.3T的容量,root下面的容量只有50G
2.先将home下面的所有文件备份到/tmp下,一会要重新分配home,不备份数据将会丢失
[root@localhost home]# tar cvfP /tmp/home.tar /home /home/tar命令后面不加P,会报错tar: Removing leading `/' from member names,原因是tar默认是相对路径,用绝对路径会报错,加上P就可以了。
3.将/home目录卸载掉
[root@localhost home]# umount -v /home umount: /home: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))竟然报错,home正忙,根据提示用fuser命令
[root@localhost home]# fuser -km /home/ -bash: fuser: command not found新机器这个命令没有安装,装一下
[root@localhost home]# yum install -y psmisc Resolving Dependencies --> Running transaction check ---> Package psmisc.x86_64 0:22.20-16.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================ Package Arch Version Repository Size ============================================================================================================================================ Installing: psmisc x86_64 22.20-16.el7 base 141 k Transaction Summary ============================================================================================================================================ Install 1 Package Total download size: 141 k Installed size: 475 k Downloading packages: warning: /var/cache/yum/x86_64/7/base/packages/psmisc-22.20-16.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY-- ETA Public key for psmisc-22.20-16.el7.x86_64.rpm is not installed psmisc-22.20-16.el7.x86_64.rpm | 141 kB 00:00:02 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package : centos-release-7-3.1611.el7.centos.x86_64 (@anaconda) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : psmisc-22.20-16.el7.x86_64 1/1 Verifying : psmisc-22.20-16.el7.x86_64 1/1 Installed: psmisc.x86_64 0:22.20-16.el7 Complete!装好了,再重复 fuser -km /home/和umount -v /home即可
4.删除/home的lv
[root@localhost ~]# lvremove /dev/mapper/cl-home Do you really want to remove active logical volume cl/home? [y/n]: y Logical volume "home" successfully removed5.把home中的5T拿来给root
[root@localhost ~]# lvextend -L +5T /dev/mapper/cl-root Size of logical volume cl/root changed from 50.00 GiB (12800 extents) to 5.05 TiB (1323520 extents). Logical volume cl/root successfully resized.6.扩展root文件系统
[root@localhost ~]# xfs_growfs /dev/mapper/cl-root meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=3276800 blks = sectsz=4096 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=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 13107200 to 13552844807.重新创建/home lv.要计算好分配的容量,我这从剩下的分配200G
[root@localhost ~]# lvcreate -L 200G -n /dev/mapper/cl-home Logical volume "home" created.8.创建文件系统
[root@localhost ~]# mkfs.xfs /dev/mapper/cl-home meta-data=/dev/mapper/cl-home isize=512 agcount=4, agsize=13107200 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=52428800, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=25600, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=09.挂载home
[root@localhost ~]# mount /dev/mapper/cl-home10.还原备份的/home文件
[root@localhost ~]# tar xvfP /tmp/home.tar -C /home/ /home/11.查看分区情况
[root@iiebigdata3 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl-root 5.1T 1.1G 5.1T 1% / devtmpfs 63G 0 63G 0% /dev tmpfs 63G 0 63G 0% /dev/shm tmpfs 63G 9.1M 63G 1% /run tmpfs 63G 0 63G 0% /sys/fs/cgroup /dev/sda2 1014M 139M 876M 14% /boot tmpfs 13G 0 13G 0% /run/user/0 /dev/mapper/cl-home 200G 33M 200G 1% /homeroot变成了5.1T,home变成了200G,成功分配