XFS总结

1. How to check XFS filesystem version?

Since version 3.15, the kernel tells you the version of XFS used in each filesystem as it mounts it; dmesg | grep XFS should give you something like

[1578018.463269] XFS (loop0): Mounting V5 Filesystem

Instead of loop0 on your system you'll get the underlying device, and V5 will be replaced by whatever version your filesystem uses.

 

2. Checking and Repairing an XFS File System

Note

If you have an Oracle Linux Premier Support account and encounter a problem mounting an XFS file system, send a copy of the /var/log/messages file to Oracle Support and wait for advice.

If you cannot mount an XFS file system, you can use the xfs_check command to check its consistency. Usually, you would only run this command on the device file of an unmounted file system that you believe has a problem. If xfs_check displays any output when you do not run it in verbose mode, the file system has an inconsistency.

# xfscheck device

If you can mount the file system and you do not have a suitable backup, you can use xfsdump to attempt to back up the existing file system data, However, the command might fail if the file system's metadata has become too corrupted.

You can use the xfs_repair command to attempt to repair an XFS file system specified by its device file. The command replays the journal log to fix any inconsistencies that might have resulted from the file system not being cleanly unmounted. Unless the file system has an inconsistency, it is usually not necessary to use the command, as the journal is replayed every time that you mount an XFS file system.

# xfs_repair device

If the journal log has become corrupted, you can reset the log by specifying the -L option to xfs_repair.

Warning

Resetting the log can leave the file system in an inconsistent state, resulting in data loss and data corruption. Unless you are experienced in debugging and repairing XFS file systems using xfs_db, it is recommended that you instead recreate the file system and restore its contents from a backup.

If you cannot mount the file system or you do not have a suitable backup, running xfs_repair is the only viable option unless you are experienced in using xfs_db.

xfs_db provides an internal command set that allows you to debug and repair an XFS file system manually. The commands allow you to perform scans on the file system, and to navigate and display its data structures. If you specify the -x option to enable expert mode, you can modify the data structures.

# xfs_db [-x] device

For more information, see the xfs_check(8)xfs_db(8) and xfs_repair(8) manual pages, and the help command within xfs_db.

3. xfs_repair

If you're attempting to run xfs_repair, getting the error message that suggests mounting the filesystem to replay the log, and after mounting still receiving the same error message, you may need to perform a forced repair (using the -L flag with xfs_repair). This option should be a last resort.

For example, I'll use a case where I had a corrupt root partition on my CentOS 7 install. When attempting to mount the partition, I continually received the below error message:

mount: mount /dev/mapper/centos-root on /mnt/centos-root failed: Structure needs cleaning

Unfortunately, forcing a repair would involve zeroing out (destroying) the log before attempting a repair. When using this method, there is a potential of ending up with more corrupt data than initially anticipated; however, we can use the appropriate xfs tools to see what kind of damage may be caused before making any permanent changes.

Using xfs_metadump and xfs_mdrestore, you can create a metadata image of the affected partition and perform the forced repair on the image rather than the partition itself. The benefits of this is the ability to see the damage that comes with a forced repair before performing it on the partition.

To do this, you'll need a decent sized USB or external hard drive. Start by mounting the USB drive - my USB was located at /dev/sdb1, yours may be named differently.

mkdir -p /mnt/usb
mount /dev/sdb1 /mnt/usb

Once mounted, run xfs_metadump to create a copy of the partition metadata to the USB - again, your affected partition may be different. In this case, I had a corrupt root partition located at /dev/mapper/centos-root:

xfs_metadump /dev/mapper/centos-root /mnt/usb/centos-root.metadump

Next, you'll want to restore the metadata in to an image so that we can perform a repair and measure the damage.

xfs_mdrestore /mnt/usb/centos-root.metadump /mnt/usb/centos-root.img

I found that in rescue mode xfs_mdrestore is not available, and instead you'll need to be in rescue mode of a live CentOS CD.

Finally, we can perform the repair on the image:

xfs_repair -L /mnt/usb/centos-root.img

After the repair has completed and you've assessed the output and potential damage, you can determine as to whether you'd like to perform the repair against the partition.

To run the repair against the partition, simply run:

xfs_repair -L /dev/mapper/centos-root

Don't forget to check the other partitions for corruption as well. After the repairs, reboot the system and you should be able to successfully boot.

Remember that the -L flag should be used as a last resort where there are no other possible options to repair.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: xfs_recover是一个用于修复XFS文件系统的工具。使用方法如下: 1. 以root用户身份登录系统 2. 将硬盘挂载到/mnt目录下 3. 运行xfs_repair -n /mnt/硬盘分区 4. 根据提示输入y确认修复或n取消修复。 注意:在运行xfs_repair之前,请确保硬盘分区没有被挂载,并且在修复过程中不要对硬盘分区进行操作。 ### 回答2: xfs_recover是XFS文件系统的一个命令,用于恢复XFS文件系统中由于异常情况导致的损坏或不一致的数据。下面是使用xfs_recover的步骤: 1. 首先,确保系统上已经安装了XFS工具包,否则需要先安装。 2. 打开终端窗口,并以管理员身份登录。 3. 输入以下命令以查看需要恢复的文件系统的状态: ```shell xfs_db -x /dev/xxx ``` 这里的`xxx`是需要恢复的文件系统的路径,比如`/dev/sda1`。 4. 在xfs_db命令提示下,输入以下命令来关闭文件系统,以便进行恢复操作: ```shell f ``` 5. 关闭文件系统后,可以使用xfs_recover进行恢复操作。输入以下命令: ```shell xfs_recover /dev/xxx ``` 这里的`xxx`是需要恢复的文件系统的路径。 6. 系统会开始扫描文件系统,并尝试恢复损坏或不一致的数据。这个过程可能需要一些时间,具体时间取决于文件系统的大小和数据损坏的程度。 7. 当恢复过程完成后,您应该会看到一条消息显示恢复操作已经成功完成。 8. 最后,重新挂载文件系统以使其可访问: ```shell mount -o rw /dev/xxx /mnt/xxx ``` 这里的`xxx`是需要恢复的文件系统的路径,`/mnt/xxx`是文件系统重新挂载的目标路径。 请注意,在进行恢复操作之前,请务必备份文件系统中的重要数据,以防止数据丢失。此外,如果您对使用xfs_recover不确定或不熟悉,请咨询专业人员的建议。 ### 回答3: xfs_recover是一个用于恢复XFS文件系统的命令行工具。它用于修复文件系统损坏、不一致或丢失的数据,并在可能的情况下尽可能地恢复文件系统的正常状态。 使用xfs_recover需要在root用户下执行以下步骤: 1. 首先,确认文件系统是否已经挂载。如果已挂载,则需要卸载文件系统。可以使用umount命令来卸载文件系统。 例如:umount /dev/sda1 2. 使用以下命令执行文件系统恢复操作: xfs_recover /dev/sda1 这里的/dev/sda1是要恢复的文件系统所在的设备。 3. 在恢复过程中,xfs_recover会扫描文件系统的元数据,找到损坏的区域并尝试修复它们。恢复过程可能需要一段时间,取决于文件系统的大小和损坏的程度。在恢复过程中,xfs_recover会输出一些日志信息,以告知用户当前的恢复进度。 4. 完成恢复后,可以重新挂载文件系统,并查看其状态是否恢复正常。可以使用mount命令来重新挂载文件系统。 例如:mount /dev/sda1 /mnt 需要注意的是,xfs_recover可以修复大多数常见的文件系统损坏问题,但并不能保证100%的恢复成功。在执行之前,建议先备份重要的数据。 总结起来,xfs_recover是一个用于修复损坏的XFS文件系统的命令行工具,通过简单的几个步骤,可以尝试恢复文件系统的正常状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值