记录调整CentOS的分区大小
2020-04-24 本文已影响0人
ljyfree
因为主要使用/root目录,所以/home下的空间需要腾出大部分给/root。下面记录一下操作过程,/home因为没有使用,因此不需要做备份。
初始磁盘分配情况
[root@master01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 48G 1.6G 47G 4% /
/dev/mapper/centos-home 24G 33M 24G 1% /home
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@master01 ~]#
删除/home
[root@master01 ~]# umount /home
[root@master01 ~]#
[root@master01 ~]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
Logical volume "home" successfully removed
[root@master01 ~]#
将多出的空间“充值”给/root
[root@master01 ~]# lvextend -L +22G /dev/mapper/centos-root
Size of logical volume centos/root changed from <47.79 GiB (12233 extents) to <69.79 GiB (17865 extents).
Logical volume centos/root successfully resized.
[root@master01 ~]#
[root@master01 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3131648 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=12526592, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6116, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 12526592 to 18293760
[root@master01 ~]#
量力而行创建/home,貌似不创建重启后无法进入系统
[root@master01 ~]# lvcreate -L 2G -n home centos
Volume group "centos" has insufficient free space (342 extents): 512 required.
[root@master01 ~]#
[root@master01 ~]# lvcreate -L 1G -n home centos
Logical volume "home" created.
[root@master01 ~]#
[root@master01 ~]#
[root@master01 ~]# mkfs.xfs /dev/centos/home
meta-data=/dev/centos/home isize=512 agcount=4, agsize=65536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=262144, 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
[root@master01 ~]#
[root@master01 ~]# mount /dev/centos/home /home
[root@master01 ~]#
查看调整后的分区大小,/root从48G扩展为70G
[root@master01 ~]#
[root@master01 ~]#
[root@master01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 70G 1.5G 69G 3% /
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/centos-home 1014M 33M 982M 4% /home
[root@master01 ~]#