通过案例学习 xfs 文件系统相关命令 | Linux 中国

2018 年 2 月 12 日 Linux中国 译者:DarkSun
本文我们来看一些常用的 xfs 管理命令。我们将会通过几个例子来讲解如何创建 xfs 文件系统,如何对 xfs 文件系统进行扩容,如何检测并修复 xfs 文件系统。
-- Kerneltalks

本文导航
编译自 | https://kerneltalks.com/commands/xfs-file-system-commands-with-examples/ 
 作者 | Kerneltalks
 译者 | DarkSun

在我们另一篇文章中,我带您领略了一下什么是 xfs,xfs 的相关特性等内容[1]。本文我们来看一些常用的 xfs 管理命令。我们将会通过几个例子来讲解如何创建 xfs 文件系统,如何对 xfs 文件系统进行扩容,如何检测并修复 xfs 文件系统。

创建 XFS 文件系统

mkfs.xfs 命令用来创建 xfs 文件系统。无需任何特别的参数,其输出如下:

   
     
     
     
  1. root@kerneltalks # mkfs.xfs /dev/xvdf

  2. meta-data=/dev/xvdf              isize=512    agcount=4, agsize=1310720 blks

  3.         =                       sectsz=512   attr=2, projid32bit=1

  4.         =                       crc=1        finobt=0, sparse=0

  5. data     =                       bsize=4096   blocks=5242880, imaxpct=25

  6.         =                       sunit=0      swidth=0 blks

  7. naming   =version 2              bsize=4096   ascii-ci=0 ftype=1

  8. log      =internal log           bsize=4096   blocks=2560, version=2

  9.         =                       sectsz=512   sunit=0 blks, lazy-count=1

  10. realtime =none                   extsz=4096   blocks=0, rtextents=0

注意:一旦 XFS 文件系统创建完毕就不能在缩容而只能进行扩容了。

调整 XFS 文件系统容量

你只能对 XFS 进行扩容而不能缩容。我们使用 xfs_growfs 来进行扩容。你需要使用 -D参数指定挂载点的新容量。-D 接受一个数字的参数,指定文件系统块的数量。若你没有提供 -D 参数,则 xfs_growfs 会将文件系统扩到最大。

   
     
     
     
  1. root@kerneltalks # xfs_growfs /dev/xvdf -D 256

  2. meta-data=/dev/xvdf              isize=512    agcount=4, agsize=720896 blks

  3.         =                       sectsz=512   attr=2, projid32bit=1

  4.         =                       crc=1        finobt=0 spinodes=0

  5. data     =                       bsize=4096   blocks=2883584, imaxpct=25

  6.         =                       sunit=0      swidth=0 blks

  7. naming   =version 2              bsize=4096   ascii-ci=0 ftype=1

  8. log      =internal               bsize=4096   blocks=2560, version=2

  9.         =                       sectsz=512   sunit=0 blks, lazy-count=1

  10. realtime =none                   extsz=4096   blocks=0, rtextents=0

  11. data size 256 too small, old size is 2883584

观察上面的输出中的最后一行。由于我分配的容量要小于现在的容量。它告诉你不能缩减 XFS 文件系统。你只能对它进行扩展。

   
     
     
     
  1. root@kerneltalks #  xfs_growfs /dev/xvdf -D 2883840

  2. meta-data=/dev/xvdf              isize=512    agcount=4, agsize=720896 blks

  3.         =                       sectsz=512   attr=2, projid32bit=1

  4.         =                       crc=1        finobt=0 spinodes=0

  5. data     =                       bsize=4096   blocks=2883584, imaxpct=25

  6.         =                       sunit=0      swidth=0 blks

  7. naming   =version 2              bsize=4096   ascii-ci=0 ftype=1

  8. log      =internal               bsize=4096   blocks=2560, version=2

  9.         =                       sectsz=512   sunit=0 blks, lazy-count=1

  10. realtime =none                   extsz=4096   blocks=0, rtextents=0

  11. data blocks changed from 2883584 to 2883840

现在我多分配了 1GB 的空间,而且也成功地扩增了容量。

1GB 块的计算方式:

当前文件系统 bsize 为 4096,意思是块的大小为 4MB。我们需要 1GB,也就是 256 个块。因此在当前块数,2883584 上加上 256 得到 2883840。因此我为 -D 传递参数 2883840。

修复 XFS 文件系统

可以使用 xfs_repair 命令进行文件系统一致性检查和修复。使用 -n 参数则并不对文件系统做出什么实质性的修改。它只会搜索并报告要做哪些修改。若不带 -n 参数,则会修改文件系统以保证文件系统的纯净。

请注意,在检查之前,你需要先卸载 XFS 文件系统。否则会报错。

   
     
     
     
  1. root@kerneltalks # xfs_repair -n /dev/xvdf

  2. xfs_repair: /dev/xvdf contains a mounted filesystem

  3. xfs_repair: /dev/xvdf contains a mounted and writable filesystem

  4. fatal error -- couldn't initialize XFS library

卸载后运行检查命令。

   
     
     
     
  1. root@kerneltalks # xfs_repair -n /dev/xvdf

  2. Phase 1 - find and verify superblock...

  3. Phase 2 - using internal log

  4.        - zero log...

  5.        - scan filesystem freespace and inode maps...

  6.        - found root inode chunk

  7. Phase 3 - for each AG...

  8.        - scan (but don't clear) agi unlinked lists...

  9.        - process known inodes and perform inode discovery...

  10.        - agno = 0

  11.        - agno = 1

  12.        - agno = 2

  13.        - agno = 3

  14.        - agno = 4

  15.        - process newly discovered inodes...

  16. Phase 4 - check for duplicate blocks...

  17.        - setting up duplicate extent list...

  18.        - check for inodes claiming duplicate blocks...

  19.        - agno = 0

  20.        - agno = 1

  21.        - agno = 2

  22.        - agno = 3

  23.        - agno = 4

  24. No modify flag set, skipping phase 5

  25. Phase 6 - check inode connectivity...

  26.        - traversing filesystem ...

  27.        - traversal finished ...

  28.        - moving disconnected inodes to lost+found ...

  29. Phase 7 - verify link counts...

  30. No modify flag set, skipping filesystem flush and exiting.

你可以看到,命令在每个阶段都显示出了为了文件系统变得健康可能做出的修改。若你希望命令在扫描时实际应用这些修改,则不带任何参数运行命令即可。

   
     
     
     
  1. root @ kerneltalks # xfs_repair /dev/xvdf

  2. Phase 1 - find and verify superblock . . .

  3. Phase 2 - using internal log

  4.        - zero log . . .

  5.        - scan filesystem freespace and inode maps . . .

  6.        - found root inode chunk

  7. Phase 3 - for each AG . . .

  8.        - scan and clear agi unlinked lists . . .

  9.        - process known inodes and perform inode discovery . . .

  10.        - agno = 0

  11.        - agno = 1

  12.        - agno = 2

  13.        - agno = 3

  14.        - agno = 4

  15.        - process newly discovered inodes . . .

  16. Phase 4 - check for duplicate blocks . . .

  17.        - setting up duplicate extent list . . .

  18.        - check for inodes claiming duplicate blocks . . .

  19.        - agno = 0

  20.        - agno = 1

  21.        - agno = 2

  22.        - agno = 3

  23.        - agno = 4

  24. Phase 5 - rebuild AG headers and trees . . .

  25.        - reset superblock . . .

  26. Phase 6 - check inode connectivity . . .

  27.        - resetting contents of realtime bitmap and summary inodes

  28.        - traversing filesystem . . .

  29.        - traversal finished . . .

  30.        - moving disconnected inodes to lost + found . . .

  31. Phase 7 - verify and correct link counts . . .

  32. done

你会发现 xfs_repair 命令对文件系统做出了修改让其变得健康。

查看 XFS 版本以及它的详细信息

查看 xfs 文件系统版本很简单。使用 -V 参数运行 xfs_info 再加上挂载点就行了。

   
     
     
     
  1. root@kerneltalks # xfs_info -V /shrikant

  2. xfs_info version 4.5.0

若要查看 XFS 文件系统的详细信息,比如想计算扩容 XFS 文件系统时要新增多少个块,需要了解块大小,块的个数等信息,则不带任何选项运行 xfs_info 加上挂载点。

   
     
     
     
  1. root@kerneltalks # xfs_info /shrikant

  2. meta-data=/dev/xvdf              isize=512    agcount=5, agsize=720896 blks

  3.         =                       sectsz=512   attr=2, projid32bit=1

  4.         =                       crc=1        finobt=0 spinodes=0

  5. data     =                       bsize=4096   blocks=2883840, imaxpct=25

  6.         =                       sunit=0      swidth=0 blks

  7. naming   =version 2              bsize=4096   ascii-ci=0 ftype=1

  8. log      =internal               bsize=4096   blocks=2560, version=2

  9.         =                       sectsz=512   sunit=0 blks, lazy-count=1

  10. realtime =none                   extsz=4096   blocks=0, rtextents=0

则会显示 XFS 文件系统的所有详细信息,就跟创建 XFS 文件系统时显示的信息一样。

此外还有一些 XFS 文件系统管理命令可以修改并管理 XFS 的元数据。我们将在另一篇文章中来讲解。


via: https://kerneltalks.com/commands/xfs-file-system-commands-with-examples/

作者:kerneltalks[3] 译者:lujun9972 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

LCTT 译者
DarkSun(lujun9972) 🌟 🌟 🌟 🌟
共计翻译: 75 篇
贡献时间:76 天

推荐文章

< 左右滑动查看相关文章 >

点击图片、输入文章 ID 或识别二维码直达




登录查看更多
0

相关内容

Linux 是一系列类 Unix 计算机操作系统的统称。该操作系统的核心为 Linux 内核。Linux 操作系统也是软件和开放源代码发展中最著名的例子之一。
【实用书】学习用Python编写代码进行数据分析,103页pdf
专知会员服务
190+阅读 · 2020年6月29日
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
专知会员服务
165+阅读 · 2020年6月4日
算法与数据结构Python,369页pdf
专知会员服务
160+阅读 · 2020年3月4日
【新书】Python中的经典计算机科学问题,224页pdf
专知会员服务
143+阅读 · 2019年12月28日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
吐血整理!140种Python标准库、第三方库和外部工具都有了
炼数成金订阅号
14+阅读 · 2019年7月30日
通过Docker安装谷歌足球游戏环境
CreateAMind
11+阅读 · 2019年7月7日
Linux挖矿病毒的清除与分析
FreeBuf
14+阅读 · 2019年4月15日
如何编写完美的 Python 命令行程序?
CSDN
5+阅读 · 2019年1月19日
Python3.8新特性概览
Python程序员
4+阅读 · 2018年12月8日
Python | Jupyter导出PDF,自定义脚本告别G安装包
程序人生
7+阅读 · 2018年7月17日
实战 | 用Python做图像处理(二)
七月在线实验室
17+阅读 · 2018年5月25日
Arxiv
24+阅读 · 2020年3月11日
Arxiv
43+阅读 · 2019年12月20日
Arxiv
13+阅读 · 2018年4月18日
Arxiv
6+阅读 · 2018年3月31日
Arxiv
7+阅读 · 2018年3月22日
VIP会员
相关VIP内容
【实用书】学习用Python编写代码进行数据分析,103页pdf
专知会员服务
190+阅读 · 2020年6月29日
一份简明有趣的Python学习教程,42页pdf
专知会员服务
76+阅读 · 2020年6月22日
专知会员服务
165+阅读 · 2020年6月4日
算法与数据结构Python,369页pdf
专知会员服务
160+阅读 · 2020年3月4日
【新书】Python中的经典计算机科学问题,224页pdf
专知会员服务
143+阅读 · 2019年12月28日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
相关资讯
吐血整理!140种Python标准库、第三方库和外部工具都有了
炼数成金订阅号
14+阅读 · 2019年7月30日
通过Docker安装谷歌足球游戏环境
CreateAMind
11+阅读 · 2019年7月7日
Linux挖矿病毒的清除与分析
FreeBuf
14+阅读 · 2019年4月15日
如何编写完美的 Python 命令行程序?
CSDN
5+阅读 · 2019年1月19日
Python3.8新特性概览
Python程序员
4+阅读 · 2018年12月8日
Python | Jupyter导出PDF,自定义脚本告别G安装包
程序人生
7+阅读 · 2018年7月17日
实战 | 用Python做图像处理(二)
七月在线实验室
17+阅读 · 2018年5月25日
相关论文
Arxiv
24+阅读 · 2020年3月11日
Arxiv
43+阅读 · 2019年12月20日
Arxiv
13+阅读 · 2018年4月18日
Arxiv
6+阅读 · 2018年3月31日
Arxiv
7+阅读 · 2018年3月22日
Top
微信扫码咨询专知VIP会员