Is it possible to perform an in-place migration from ext4 to XFS?
Environment
- Red Hat Enterprise Linux 6
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
Issue
- Is it possible to perform an in-place migration from ext4 to XFS?
Resolution
There is no way to perform an in-place migration from ext4 to XFS. The only way to migrate would be to perform a copy of the entire file system from the existing volume to a new volume using a method such as rsync. For example the process would be to:
- Format a new volume with XFS.
- Mount the new volume.
- Perform a copy of the files from the ext4 filesystem to the newly formatted XFS device with:
# rsync -avPHAX /ext4-mountpoint /xfs-mountpoint
(-a for archive, -v for verbose, -P for progress, -H for hard links, -A preserves ACLs, and -X copies extended attributes).
This should be done while the file system is not in use by other users - e.g. when the server is in single user mode. Copying files which are currently being written to on the source file system will result in incomplete or inconsistent files on the target file system. This can lead to corruption, especially of databases.
When using LVM, this can be done with the root partition (e.g. to prepare for a RHEL 7 to 8 upgrade) in a way that provides an easy fall-back plan should the upgrade fail:
- Make sure that the existing 'root' file system is not mounted on root (i.e. by booting off a live USB key)
- Create the new LVM LV
- Format it with XFS
- Mount the old and new root LVs to different directories not under one another
- Use
rsyncas above to copy the entire file system from the old LV to the new - Unmount both LVs
- Use
lvrenameto rename the 'old' LV (e.g. toold_root_lv) - Use
lvrenameto rename the 'new' LV to the name of the previous root LV (e.g.root_lv)
As long as the boot config uses the LV's name (e.g. root=/dev/mapper/RHEL7-root_lv) then the new XFS root volume should be read without the boot configuration or /etc/fstab needing to change. If it uses UUIDs, or the root volume is stored on a disk partition, then this method cannot be used.
To back out the change, simply boot of the live USB key, rename the new LV to something else, and rename the old root LV back to its original name.
Root Cause
The metadata, root inode, and other structures in XFS are fundamentally different from those in EXT4.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.