Converting Filesystems with Fstransform
By
Fstransform converts a filesystem without formatting the media or deleting any files.
Once you opt for a filesystem, it cannot be changed easily – especially if you already have files on it. Massimiliano Ghilardi changed this with the small Fstransform toolkit: One command is all it takes to change the filesystem.
Filesystems are responsible for how files are stored on hard drives. Unfortunately, a number of them currently are out there vying for that right. On Linux, ext4 is currently popular, with Btrfs waiting in the wings as its replacement. Windows uses NTFS, and its ancestor, FAT32, is particularly prevalent on USB sticks.
Normally, you decide which filesystem to use when you install Linux – if the distribution doesn’t take this decision out of your hands. Then, once the system is in place on the disk, making a change is difficult: To be on the safe side, you have to copy the files to a different disk, then reformat the hard disk completely, and finally copy all the files again and hope all the file attributes have been retained.
The command-line programs of the Fstransform toolkit, however, let you convert one filesystem to another. This means a second hard disk is no longer necessary for intermediate storage. Unfortunately, the Fstransform toolkit also has a few drawbacks.
Not Without My Backup
For example, Fstransform only supports the common filesystems on Linux: ext2, ext3, ext4, ReiserFS, JFS, and XFS. The Windows filesystems NTFS, MS-DOS, and FAT32 are explicitly excluded (Figure 1). The frequent need to convert an old Windows partition to ext4 thus remains unfulfilled.
Additionally, the danger always exists with Fstransform that the conversion will dump all your data into a black hole. Ghilardi expressly assumes no liability for data loss and issues a warning to this effect in the documentation: In other words, if you lose data, it’s your problem. Thus, if you want to use Fstransform, you should create a backup copy first, preferably in the form of an image. Then, you can quickly revert to the previous state if necessary. The Clonezilla Live CD is perfect for this.
For Fstransform to convert the filesystem, the partition must have at least five percent free space. The more free space available, the more smoothly the conversion will work. Ghilardi also advises against converting an almost full partition to the XFS filesystem. The hard disk should have at least 10 percent free space available in this case.
Additionally, the appropriate system tools must be installed for the existing and new filesystem. For example, if you want to upgrade a partition to the XFS filesystem on Ubuntu, you also need support for XFS from the xfsprogs package. But that’s not all: You also need to meet the conditions set out in the “Fstransform Requirements” box. However, this should be no problem for any distribution and for the filesystems already mentioned.
Deployment Plan
As a fairly young tool, Fstransform has not yet found its way into the distributions. For example, Canonical will not be adding it to its repositories until Ubuntu 12.10. At the moment, you have no alternative but to build Fstransform yourself. However, this is quickly done: First, install the C++ compiler and make using your package manager. On Ubuntu these two are provided by the packages g++ and make. Then, you can download the current Fstransform version from the homepage, unzip the archive on the hard disk, and run the following three commands in the directory created by the last step:
$ ./configure $ make $ sudo make install
If the partition to be converted is currently mounted, you need read and write access. Additionally, programs and processes are allowed to access the partition during the conversion. In other words, Fstransform needs to be able to unmount the partition. This also means you can’t convert the root partition on the fly. If all conditions are met, the only thing you have to do now is call fstransform as the root user. The required parameters are the device file for the partition to be converted and the target filesystem. For example, the command:
# fstransform /dev/sdc1 xfs
converts the first partition on an external hard disk (sdc1) to the XFS filesystem.
Relocation
In the first step, Fstransform checks to see whether all the tools are present. If you see an error as shown in Figure 2, you should cancel the process by pressing Enter and install the missing programs.
If the partition to be converted is not mounted somewhere, Fstransform mounts it in a directory below /tmp. Some distributions, such as Ubuntu, open the File Manager automatically when this happens. You should immediately close the File Manager window again; otherwise, the next error message will appear in a matter of seconds.
Fstransform now stops once again and offers you one last chance to cancel the entire process by pressing Ctrl+C (Figure 3).
If you want to continue, press the Enter key. After completing the first part of the conversion, Fstransform unmounts the partition you are converting. If anything should go wrong, for some reason, Fstransform lets you know (Figure 4).
An unmountable device is no reason to panic: You can simply open a second terminal window and unmount the partition manually; for example:
$ sudo umount /dev/sdc1
Back in the window with Fstransform, type continue and press Enter.
At some point, a message that Fstransform is ready to go should appear (Figure 5).
Again, press the Enter key then help yourself to a gallon of coffee. The conversion takes about a minute per gigabyte; thus, a partition with 250GB of data can take up to four hours. During this time, you cannot interrupt Fstransform under any circumstances; the best thing is not to touch the system at all until a success message appears (Figure 6).
The fstransform program is just a script; the actual conversion in the background is handled by two programs: fsmove and fsremap. If something should go wrong, you will find several logfiles below /var/tmp/fstransform: fstransform.log.<number> and fsremap.job.<number>/fsremap.log. If fsremap cancels, you can try:
# fsremap --resume-job=Number /dev/sdc1
to continue the task.
Conclusions
Fstransform is extremely useful, especially if you want to convert filesystems that have major technical differences – such as ReiserFS to ext4. Because Fstransform fires some pretty big guns for this job, you should take the warnings very seriously and make sure you have a usable backup. Incidentally, some filesystems come with their own conversion programs, which can be somewhat faster and safer than Fstransform.
To convert older ext filesystems to newer versions, you do not need to rely on Fstransform. The ext developers offer a tool called tune2fs for this task [2]. It can convert an ext3 filesystem to an ext4 filesystem, for example, more conservatively, more quickly, and more safely than Fstransform.
Info
[1] Sparse file
[2] “Configuring Filesystems” by Nathan Willis, Linux Shell Handbook, 3rd edition, pg. 35
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.