二维码

CentOS Linux如何无损调整分区大小(XFS文件系统)

1718 人阅读 | 时间:2021年03月23日 16:59
系统环境: CentOS 7.2 64-bit
情况:
/home:873GB
/:50GB
/ 分区不够用
分区类型:XFS  (分区类别可以用命令blkid 来查看,输出结果第一行最后就可以看到)
思路:
把home分区的空间划一部分到root分区

 

操作:
1、通过df -Th查看分区情况

 

CentOS Linux如何无损调整分区大小(XFS文件系统)


  

2、lvdisplay 查看各分区的信息

 

(base) [root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                xdonVW-skI2-1P3T-JQuh-WwY4-qfrV-vbmVQk
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-01-27 05:01:01 +0800
  LV Status              available
  # open                 2
  LV Size                <7.88 GiB
  Current LE             2016
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                n2a4OV-oaif-5jSE-RJh8-Pc6t-NxFf-FwegR9
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-01-27 05:01:01 +0800
  LV Status              available
  # open                 1
  LV Size                <965.12 GiB
  Current LE             247070
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                dj27sN-lnZX-9THU-TrO5-2VPg-q8bS-mYFiYF
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-01-27 05:01:01 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0


   


3、减少/dev/centos/home的空间


(base) [root@localhost ~]# lvreduce -L 50G /dev/mapper/centos-home
  Volume group "cl" not found
  Cannot process volume group cl
(base) [root@localhost ~]#

报错,需要将home 卸载


(base) [root@localhost ~]#  umount /home

# 命令设置 /dev/centos/home 分区 50G空间

(base) [root@localhost ~]# lvreduce -L 50G /dev/mapper/centos-home
  WARNING: Reducing active logical volume to 50.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce centos/home? [y/n]: y
  Size of logical volume centos/home changed from <965.12 GiB (247070 extents) to 50.00 GiB (12800 extents).
  Logical volume centos/home successfully resized.

 

4、增加/dev/centos/root的空间

 

(base) [root@localhost ~]#  lvextend -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 965.12 GiB (247071 extents).
  Logical volume centos/root successfully resized.


 

5、扩展XFS文件空间大小

 

(base) [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 253000704


CentOS Linux如何无损调整分区大小(XFS文件系统)

  

到此/dev/centos/root的扩展结束,不过还有一些后遗症,调整后的/dev/mapper/cl-home 显示的大小一直不正常,这样也会导致重启的时候无法根据/etc/fstab里面的规则挂载正确的/home,直接进入紧急模式(welcome to emergency mode),由于我们/home里面没有什么文件,所以我们用格式化的办法,进行了修复。

 

[root@localhost ~]# mkfs.xfs -f /dev/mapper/centos-home
这样再卸载和挂载就没有问题了
[root@localhost ~]# umount /home
 
[root@localhost ~]# mount /home


[root@MOMOCO-02 ~]# mkfs.xfs   /dev/mapper/centos-home【这个时候我们选择xfs格式】
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.

【提示说我们里面有个文件系统里,如果你要继续这样格式就加上-f选项】

[root@MOMOCO-02 ~]# mkfs.xfs  -f /dev/sdb1【意思就是强制的】
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=196608 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=786432, 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

 

至此整个的调整分区圆满结束。

 

留下一个小问题做思考,就是如果同时想保留/dev/mapper/centos-home里面的数据的话,如何无损调整分区?

 

2018年1月17日更新:暂时没有找到把调整小了的分区(/dev/mapper/centos-home)里面的数据完整保留下来的办法。


©著作权归作者所有:来自ZhiKuGroup博客作者没文化的原创作品,如需转载,请注明出处,否则将追究法律责任 来源:ZhiKuGroup博客,欢迎分享。

评论专区
  • 昵 称必填
  • 邮 箱选填
  • 网 址选填
◎已有 0 人评论
搜索
作者介绍
30天热门
×
×
本站会员尊享VIP特权,现在就加入我们吧!登录注册×
»
会员登录
新用户注册
×
会员注册
已有账号登录
×