1. resize root LVM (重置 centos root 分区大小)
<!-- TOC -->
1.1. 摘要
安装centos7时使用默认分区,使用docker,运行 redis, mysql, jira, confluence, gitlab 2个月后,发现 root 分区空间不足,现有2种解决方案
* 方案一:将docker默认路径移至home目录下, 移动后,发现jira, confluence 无法启动
* 方案二:增加root LVM分区容量。(以下内容就是方案二的详细操作)
1.2. 操作
-
虚拟机进行快照
-
查看当前空间占用
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 50G 28G 23G 56% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 9.2M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda1 1014M 276M 739M 28% /boot /dev/mapper/centos-home 943G 153M 943G 1% /home overlay 50G 28G 23G 56% /var/lib/docker/... overlay 50G 28G 23G 56% /var/lib/docker/... overlay 50G 28G 23G 56% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... shm 64M 4.0K 64M 1% /var/lib/docker/... tmpfs 1.6G 0 1.6G 0% /run/user/0 overlay 50G 28G 23G 56% /var/lib/docker/... overlay 50G 28G 23G 56% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/...
-
备份home目录
[root@localhost ~]# tar cf /tmp/home.tar /home/ [root@localhost ~]# ll -h /tmp/home.tar -rw-r--r--. 1 root root 117M 7月 2 15:08 /tmp/home.tar
-
安装 fuser (可跳过此步骤,直接执行 5,5失败再执行此步骤)
[root@localhost ~]# yum -y install psmisc ## kill掉所有占用/home 目录的进程 [root@localhost ~]# fuser -m /home
-
卸载/home
[root@localhost ~]# umount /home
-
删除卷 home
[root@localhost ~]# lvremove /dev/centos/home Do you really want to remove active logical volume centos/home? [y/n]: y Logical volume "home" successfully removed
-
为root分区增加 450G空间
[root@localhost ~]# lvextend -L +450G /dev/centos/root Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 500.00 GiB (128000 extents). Logical volume centos/root successfully resized.
-
调整 root分区大小
[root@localhost ~]# xfs_growfs /dev/mapper/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 131072000
-
把剩余空间全部建给 home
[root@localhost ~]# lvcreate -l 100%FREE -n /dev/centos/home Logical volume "home" created.
-
格式化 home 空间
[root@localhost ~]# mkfs.xfs /dev/centos/home meta-data=/dev/centos/home isize=512 agcount=4, agsize=32317184 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=129268736, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=63119, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime=none extsz=4096 blocks=0, rtextents=0
-
挂载 home 空间
[root@localhost ~]# mount /dev/centos/home /home
-
查看空间分配
[root@localhost ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 500G 28G 473G 6% / devtmpfs 7.8G 0 7.8G 0% /dev tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 7.8G 9.2M 7.8G 1% /run tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup /dev/sda1 1014M 276M 739M 28% /boot tmpfs 1.6G 0 1.6G 0% /run/user/0 overlay 500G 28G 473G 6% /var/lib/docker/... overlay 500G 28G 473G 6% /var/lib/docker/... overlay 500G 28G 473G 6% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... shm 64M 488K 64M 1% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... overlay 500G 28G 473G 6% /var/lib/docker/... overlay 500G 28G 473G 6% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... shm 64M 0 64M 0% /var/lib/docker/... /dev/mapper/centos-home 493G 33M 493G 1% /home
-
解压备份的home文件
[root@localhost ~]# tar xvf /tmp/home.tar -C /
大功告成
欢迎摘录,如有疑问可留言。
参考文献
来源:oschina
链接:https://my.oschina.net/u/1581726/blog/3068615