如何缩小 XFS 文件系统?

如何缩小 XFS 文件系统?

sda我们有一台带有 2 个磁盘(和)的 RHEL 7 服务器sdb。我们的//var/log正在,正在。我们使用 LVM 和 XFS。swapsda/varsdb

sda太大 (160 GB),我们想将其缩小到 40 GB。然后我们可以使用免费的 120 GB 来扩展sdb

[root@foo ~]# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda2  rhel      lvm2 a--  134.77g 9.77g
  /dev/sdb1  vg_var    lvm2 a--  200.00g    0


[root@foo ~]# lvs
  LV        VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root      rhel      -wi-ao---- 117.19g
  swap      rhel      -wi-ao----   3.91g
  var_log   rhel      -wi-ao----   3.91g
  lv_var    vg_var    -wi-ao---- 200.00g

[root@foo ~]# fdisk -l

Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x3235298e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   419430399   209714176   8e  Linux LVM

Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0009b153

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   283656191   141315072   8e  Linux LVM

Disk /dev/mapper/rhel-root: 125.8 GB, 125829120000 bytes, 245760000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/rhel-swap: 4194 MB, 4194304000 bytes, 8192000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/vg_var-lv_var: 214.7 GB, 214744170496 bytes, 419422208 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/rhel-var_log: 4194 MB, 4194304000 bytes, 8192000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

我们怎样才能安全地实现这一目标?我已经在测试机上尝试过此操作,但失败了:

  1. 添加新磁盘
  2. 创建一个LVM分区,pvcreate并在其上添加一个新的LV。
  3. 使用救援盘启动
  4. 挂载sda并将/mnt/sysimage新磁盘的LV挂载到/mnt/sdb
  5. cp -ax /mnt/sysimage/* /mnt/sdb
  6. 更新/mnt/sysimage/etc/fstab使用/dev/mapper/rhel-lv_root
  7. 最后重启失败,原因是INT18 boot failure

答案1

目前 [2019] XFS 文件系统无法收缩。

http://xfs.org/index.php/Shrinking_Support

RH网站上是这么说的:

  • 目前无法使用 xfs 文件系统减小分区或逻辑卷的大小。如果您对此功能感兴趣,请联系红帽支持并参考红帽 bugzilla 1062667,并提供您需要 XFS 减少/收缩的用例。
  • 作为某些环境中可能的解决方法,精简配置的 LVM 卷可以被视为 XFS 文件系统下方的附加层。

https://access.redhat.com/solutions/540013

相关内容