使用 Fstransform 转换文件系统
转换 文件系统
![](/data/attachment/album/201808/31/002635apr7rhc1jdd46j9c.jpg)


很少有人知道他们可以将文件系统从一种类型转换为另一种类型而不会丢失数据（即非破坏性的）。这可能听起来像魔术，但 [Fstransform](https://github.com/cosmos72/fstransform) 可以几乎以任意组合将 ext2、ext3、ext4、jfs、reiserfs 或 xfs 分区转换成另一类型。更重要的是，它可以直接执行，而无需格式化或复制数据。除此之外，还有一点好处：Fstransform 也可以处理 ntfs、btrfs、fat 和 exfat 分区。


### 在运行之前


Fstransform 存在一些警告和限制，因此强烈建议在尝试转换之前进行备份。此外，使用 Fstransform 时需要注意一些限制：


* 你的 Linux 内核必须支持源文件系统和目标文件系统。听起来很明显，如果你想使用 ext2、ext3、ext4、reiserfs、jfs 和 xfs 分区，这样不会出现风险。Fedora 支持所有分区，所以没问题。
* 将 ext2 升级到 ext3 或 ext4 不需要 Fstransform。请使用 Tune2fs。
* 源文件系统的设备必须至少有 5％ 的可用空间。
* 你需要在开始之前卸载源文件系统。
* 源文件系统存储的数据越多，转换的时间就越长。实际速度取决于你的设备，但预计它大约为每分钟 1GB。大量的硬链接也会降低转换速度。
* 虽然 Fstransform 被证明是稳定的，但请备份源文件系统上的数据。


### 安装说明


Fstransform 已经是 Fedora 的一部分。使用以下命令安装：



```
sudo dnf install fstransform
```

### 转换


![](/data/attachment/album/201808/31/002635d86ur6fn7u8rlizf.png)


`fstransform` 命令的语法非常简单：`fstransform <源设备> <目标文件系统>`。请记住，它需要 root 权限才能运行，所以不要忘记在开头添加 `sudo`。这是一个例子：



```
sudo fstransform /dev/sdb1 ext4
```

请注意，无法转换根文件系统，这是一种安全措施。请改用测试分区或实验性 USB 盘。与此同时，Fstransform 会在控制台中有许多辅助输出。最有用的部分是预计完成时间，让你随时了解该过程需要多长时间。同样，在几乎空的驱动器上的几个小文件将使 Fstransform 在一分钟左右完成其工作，而更多真实世界的任务可能需要数小时的等待时间。


### 更多支持的文件系统


如上所述，可以尝试在 ntfs、btrfs、fat 和 exfat 分区使用 Fstransform。这些类型是早期实验性的，没有人能保证完美转换。尽管如此，还是有许多成功案例，你可以通过在测试分区上使用示例数据集测试 Fstransform 来添加自己的成功案例。可以使用 `--force-untested-file-systems` 参数启用这些额外的文件系统：



```
sudo fstransform /dev/sdb1 ntfs --force-untested-file-systems
```

有时，该过程可能会因错误而中断。请放心再次执行命令 —— 它可能最终会在两、三次尝试后完成转换。




---


via: <https://fedoramagazine.org/transform-file-systems-in-linux/>


作者：[atolstoy](https://fedoramagazine.org/author/atolstoy/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Few people know that they can convert their filesystems from one type to another without losing data, i.e. non-destructively. It may sound like magic, but [Fstransform](https://github.com/cosmos72/fstransform) can convert an ext2, ext3, ext4, jfs, reiserfs or xfs partition to another type from the list in almost any combination. More importantly, it does so in-place, without formatting or copying data anywhere. Atop of all this goodness, there is a little bonus: Fstransform can also handle ntfs, btrfs, fat and exfat partitions as well.

## Before you run it

There are certain caveats and limitations in Fstransform, so it is strongly advised to back up before attempting a conversion. Additionally, there are some limitations to be aware of when using Fstransform:

- Both the source and target filesystems must be supported by your Linux kernel. Sounds like an obvious thing and exposes zero risk in case you want to use ext2, ext3, ext4, reiserfs, jfs and xfs partitions. Fedora supports all of that just fine.
- Upgrading ext2 to ext3 or ext4 does not require Fstransform. Use the Tune2fs utility instead.
- The device with source file system must have at least 5% of free space.
- You need to be able to unmount the source filesystem before you begin.
- The more data your source file system stores, the longer the conversion will last. The actual speed depends on your device, but expect it to be around one gigabyte per minute. The large amount of hard links can also slow down the conversion.
- Although Fstransform is proved to be stable, please back up data on your source filesystem.

## Installation instructions

Fstransform is already a part of Fedora. Install with the command:

sudo dnf install fstransform

## Time to convert something

![](https://fedoramagazine.org/wp-content/uploads/2018/08/Screenshot_20180805_230116.png)

Converting one file system to another in-place can take a while

The syntax of the *fstransform* command is very simple: *fstransform <source device> <target file system>*. Keep in mind that it needs root privileges to run, so don’t forget to add *sudo* in the beginning. Here goes an example:

sudo fstransform /dev/sdb1 ext4

Note that it is not possible to convert a root file system, which is a security measure. Use a test partition or an experimental thumb drive instead. In the meantime, Fstransform will through a lot of auxiliary output in the console. The most useful part is the estimated time of completion, which keep you informed about how long the process will take. Again, few small files on an almost empty drive will make Fstransform do its job in a minute or so, whereas more real-world tasks may involve hours of wait time.

## More file systems are supported

As mentioned above, it is possible to try Fstransform with ntfs, btrfs, fat and exfat partitions. These types are very experimental, and nobody can guarantee that the converion will flow perfect. Still, there are many success stories, and you can add your own by testing Fstransform with a sample data set on a test partition. Those additional file systems can be enabled by the use of the* –force-untested-file-systems* parameter:

sudo fstransform /dev/sdb1 ntfs --force-untested-file-systems

Sometimes the process may iterrupt with an error. Feel free to repeat the command *again* — it may eventually complete the conversion from second or third attempt.

## Oadmin

Am one of the few people who didn’t know you can change filesystems type without losing data.

Great write up.

## Triet

Btrfs has it’s own conversion utility, so if that’s the route you’re taking, then btrfs-convert may be your best bet.

## Barry

“The more data your source file system stores, the longer the conversion will last. ”

Should this be the longer the conversion will take?

## mingjun.wang

The transfer-tool sounds great. After simple search, found it’s an open source project. Cool…

## Hayden James

I was not aware of it. Thank you for sharing!!

## Costa A.

That tool is going to be useful if and only if the time it takes to convert from a file system to another is less than backing up your data, convert with gdisk/fdisk, restore data.

## Jim O

I wanted to convert a 875 GB partition from xfs to ext4. There are about 110 GB of files on the partition. I first saved the contents of the partition to another partition and ran fstransform. After copying the files to a loop file, fstransform reported an error on the unmount. I stopped fstransform, unmounted the partition and ran fstransform again. This time it ran for about 5 hours and eventually completed. The partition is now ext4 as I wanted. Opening the partition in Files gives “Folder is Empty”. Starting GParted shows the partition as 119 GiB used. So why is the “folder” empty?

Seems to me that copying the contents of the partition to another partition, unmounting and deleting the partition, then formatting it for ext4, mounting the partition, and then copying the files back would be a lot faster (1 to 1 1/2 hours in total) and would actually work. Am I missing something?

## Stuart D Gathman

You are not missing anything. If you have the space for a backup on reasonably fast media, backup, reformat, restore is the safest and fastest option. I have had systems that had incremental remote backup only (for disaster recovery), and no space for a copy. In that situation, this would be handy. If fstransform fails – just reformat and spend a day or so restoring from the remote backup.

## ray

can I convert an old msdos game on cd to run on linux?