1.df -h查看使用情况
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 45G 15G 30G 34% / devtmpfs 897M 0 897M 0% /dev tmpfs 912M 0 912M 0% /dev/shm tmpfs 912M 9.0M 903M 1% /run tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sda1 1014M 180M 835M 18% /boot /dev/mapper/centos-home 22G 33M 22G 1% /home tmpfs 183M 20K 183M 1% /run/user/0 /dev/sr0 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64
2.备份home目录到/boot目录(或其他目录也行,主要是为了以后还原)
[root@localhost ~]# alias cp='cp' [root@localhost ~]# alias cp alias cp='cp' [root@localhost ~]# cp -rf /home /root/
3.查看备份的home目录
[root@localhost ~]# ls /root anaconda-ks.cfg initial-setup-ks.cfg 模板 图片 下载 桌面 home 公共 视频 文档 音乐
4.取消/home的挂载
umount /home
5.删除之前home挂载的逻辑卷
[root@localhost ~]# lvremove /dev/mapper/centos-home Do you really want to remove active logical volume centos/home? [y/n]: y Logical volume "home" successfully removed
6.扩展/root目录
物理上扩展10G
[root@localhost ~]# lvextend -L +10G /dev/mapper/centos-root Size of logical volume centos/root changed from <45.02 GiB (11524 extents) to <55.02 GiB (14084 extents). Logical volume centos/root successfully resized.
逻辑上设置跟物理边界一样大
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2950144 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=11800576, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5762, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 11800576 to 14422016
7.重新创建home lv
[root@localhost ~]# lvcreate -L 10G -n /dev/mapper/centos-home Logical volume "home" created.
8.创建文件系统
[root@localhost ~]# mkfs.xfs /dev/mapper/centos-home meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
9.挂载home
[root@localhost ~]# mount /dev/mapper/centos-home /home
10.home文件恢复
[root@localhost ~]# cp -rf /root/home/* /home/ [root@localhost ~]# ls /home/ jy
11.查看root扩大后的磁盘情况
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 55G 16G 40G 28% / devtmpfs 897M 0 897M 0% /dev tmpfs 912M 0 912M 0% /dev/shm tmpfs 912M 9.0M 903M 1% /run tmpfs 912M 0 912M 0% /sys/fs/cgroup /dev/sda1 1014M 180M 835M 18% /boot tmpfs 183M 24K 183M 1% /run/user/0 /dev/sr0 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64 /dev/mapper/centos-home 10G 33M 10G 1% /home
本文由傻鸟发布,不代表傻鸟立场,转载联系作者并注明出处:https://shaniao.net/linux/304.html