SUMMARY Simple method to convert EXT4 to XFS without data restore
Hello esteemed forum members.
For a specific project, I was asked to test if conversion of EXT4 to XFS could work without data restores on RHEL 7.9.
I did it by using EPEL tool fstransform (available in RHEL repositories).
Maybe this information helps someone else in the future.
Step 1
Install tool from EPEL repository:
$ sudo yum -y install fstransform
Step 2
Check current setup for file system /myfs:
$ uname -a && sudo lsblk -f | awk '$NF=="/myfs" {print $NF,"is file system type",$2}'
Linux myhost.domain.dom 3.10.0-1160.25.1.el7.x86_64 #1 SMP Tue Apr 13 18:55:45 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux
/myfs is file system type ext4
$ sudo mount | grep myfs
/dev/mapper/myvg-mylv on /myfs type ext4 (rw,noatime,data=ordered)
Step 3
Unmount file system /myfs and run the conversion:
$ sudo umount /myfs
$ sudo fstransform /dev/mapper/myvg-mylv xfs
Step 4
Change file system type in /etc/fstab and remount /myfs:
$ sudo sed -i -e "s#/myfs.*ext4#/myfs xfs#" /etc/fstab
$ sudo mount /myfs
$ uname -a && sudo lsblk -f | awk '$NF=="/myfs" {print $NF,"is file system type",$2}'
Linux myhost.domain.dom 3.10.0-1160.25.1.el7.x86_64 #1 SMP Tue Apr 13 18:55:45 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux
/myfs is file system type xfs
Yes, certainly there are some caveats and backups are important in case something goes wrong.
Regards,
Dusan Baljevic (amateur radio VK2COT)
Responses
Hi Dusan and Christian,
The below list contains file systems I would not convert this way:
- / (root)
- /boot
- /var
- /var/lib
- /usr
It is a nice concept.
Hints to add:
- Make a copy of the /etc/fstab before starting the activities.
- make a snapshot if you do this on a virtual machine.
- run a rear backup of compatible backup (e.g. clonezilla) if you want to do this on a physical machine.
Warning: if it fails and you have no disklevel backup, you are on your own
Red Hat does not support EPEL related tools.
Regards,
Jan Gerrit
P.S. in the past an "upgrade" from ext3 to ext4 was not supported either.
Thanks for sharing Baljevic. To me it looks it is worth to try conversion of EXT4 to XFS and obviously need to either have full backup or snapshots in case of virtual machines or even azure linux vms especially you can take os disk snapshot. As in general practice xfs is being used for large file systems not likely for / and /boot and /var.If anything goes wrong you can revert back. Easy in case of virtual machine little difficult in case of physical servers.
I'd only recommend trying this on a system you don't care if it crashes first.
Next, if you do perform this, consider all the good tips from Christian, Dusan, and Jan above.
However, I am here to just simply reinforce what's been said, please... please - if you don't have a backup, and a means to restore, please get one, especially before trying something ultra-risky as above.
Ask yourself, what would happen if the system i care about would no longer work? Ask yourself what steps you could have taken in advance to have a solid back and a means to restore. Please consider this regardless if you try the risky method that none of us recommend.
Consider building a new system, create the services, migrate the data.
Regards,
RJ
fstransform /dev/datavg/lv01 xfs fstransform: starting version 0.9.3, checking environment fstransform: checking for which... '/bin/which' fstransform: checking for expr... '/bin/expr' fstransform: checking for id... '/bin/id' fstransform: parsing command line arguments fstransform: checking for stat... '/bin/stat' fstransform: checking for mkfifo... '/bin/mkfifo' fstransform: checking for blockdev... '/sbin/blockdev' fstransform: checking for losetup... '/sbin/losetup' fstransform: checking for fsck... '/sbin/fsck' fstransform: checking for mkfs... '/sbin/mkfs' fstransform: checking for mount... '/bin/mount' fstransform: checking for umount... '/bin/umount' fstransform: checking for mkdir... '/bin/mkdir' fstransform: checking for rmdir... '/bin/rmdir' fstransform: checking for rm... '/bin/rm' fstransform: checking for dd... '/bin/dd' fstransform: checking for sync... '/bin/sync' fstransform: checking for fsmove... '/sbin/fsmove' fstransform: checking for fsremap... '/sbin/fsremap' fstransform: checking for fsck(source file-system)... '/sbin/fsck' fstransform: checking for fsck(target file-system)... '/sbin/fsck' fstransform: looking for optional commands fstransform: checking for sleep... '/bin/sleep' fstransform: checking for date... '/bin/date' 11:03:21 fstransform: environment check passed. 11:03:21 fstransform: saving output of this execution into /var/tmp/fstransform/fstransform.log.50424 11:03:21 fstransform: preparing to transform device '/dev/datavg/lv01' to file-system type 'xfs' 11:03:21 fstransform: device '/dev/datavg/lv01' not found in the output of command /bin/mount, assuming it is not mounted
11:03:21 ERROR! fstransform: just mounted device '/dev/datavg/lv01' at mount point '/tmp/fstransform.mount.50424' but still cannot find it in the output of command /bin/mount I give up, sorry