centos7 逻辑卷缩容(xfs格式)翻车现场

目的:

原数据盘最大是/home。想拆分一部分做/data。如下图:

拆分后:

 解决方案:

首先查看磁盘情况,然后再进行判断。

我这边收到的服务器是进行了逻辑卷划分,格式是xfs的。那么我可以进行正对xfs格式的逻辑卷缩容后,重新划分出一个较大的逻辑卷挂载在/data

操作步骤:

1. 查看磁盘情况

# fdisk -l

跟据上面情况可以看出,是做了逻辑卷处理。

2. 查看物理卷

# pvscan

 一个物理卷,名叫centos 

查看物理卷状态:

#pvdisplay

物理卷我们不需要操作。

3.查看卷组和逻辑卷

卷组:

# vgdisplay

 逻辑卷:

# lvscan

 查看逻辑卷详情

# lvdisplay

[root@vonedaonode2 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                GkhFxa-GTcs-Ppy3-Hyuu-vb0U-I8vs-3Q4sgm
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-03-18 17:59:06 +0800
  LV Status              available
  # open                 0
  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                90OFWF-eKjq-jpQf-Euy8-jPoB-uw2o-tyPPQF
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-03-18 17:59:06 +0800
  LV Status              available
  # open                 1
  LV Size                <141.12 GiB
  Current LE             36126
  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                0AldrL-0PJy-ivsB-nTBj-gQUb-IZmT-AJfW7T
  LV Write Access        read/write
  LV Creation host, time localhost, 2020-03-18 17:59:07 +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

对/dev/centos/home逻辑卷进行缩容,/dev/centos/home是xfs格式的。

4. 逻辑卷缩容

xfs不支持缩容,不需要卸载。

重新设置逻辑卷大小:# lvresize -L 20G /dev/mapper/centos-home 

查看逻辑卷重新分配的情况,/dev/centos/home已经变小

查看物理卷,物理卷多出121.12G空闲

使df -h查看时生效:# xfs_growfs /dev/mapper/centos-home

发现执行后没生效:

卸载后重新挂载也是失败:

 修复,失败:

 翻车现场....!!!  所以,不管怎样,操作之前需要将/home 备份下。翻车后还能补救。

额....新服务器,/home下没有什么内容.....

格式化重新挂载吧。

# mkfs.xfs -f /dev/mapper/centos-home

 查看:

5. 创建逻辑卷

#  lvcreate --name data -l 100%Free centos

# lvcreate --name 逻辑卷名称 -l  大小  卷组名称

6. 格式化逻辑卷,挂载

# mkfs.xfs /dev/centos/data

# mkdir /data

# mount /dev/centos/data /data

加入到/etc/fstab中:

原文地址:https://www.cnblogs.com/zoujiaojiao/p/12537405.html