Ext4 to btrfs conversion: If I accidentally lose power to the system during the conversion, will I lose the data

btrfsext4

I want to convert the 3TB 80% full ext4 block device into btrfs and I want to estimate the risks involved in the process.

If I accidentally lose power to the system during the conversion, will I lose the data?

In my two-year experience with btrfs, the file system proved only to be
moderately safe during the power loss accidents – it destroyed some of
my data, if the power was lost two or more times in the row.

Best Answer

The data loose most possible due controller write operation failure to disk, while its possible that whole disk partition table would be corrupted.

As it was said, make a backup prior, but the conversion operation it self is designed so, that NO ORIGINAL DATA is touched. Btrfs makes snapshot of original FS version and uses free blocks to make further operations.

If you will create fresh ext4 FS on 100GB partition and run

#df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/sda3                          99G   60M   94G   1% /ext4convert2btrfs

then unmount and run conversion:

#unmount /ext4convert2btrfs
#btrfs-convert /dev/sda3
creating btrfs metadata.
creating ext2fs image file.
cleaning up system chunk.
conversion complete.

then mount run df again, and you will see something like this:

Filesystem                        Size  Used Avail Use% Mounted on
/dev/sda3                         100G  1.8G   66G   3% /ext4convert2btrfs

The rest of space is used by primary FS snapshot. Only system administrator will decide when it is safe to remove snapshot and allow original data to be overwritten.

To recover free space and make the conversion permanent, do:

#cd /ext4convert2btrfs
#btrfs subvol delete ext2_saved
#btrfs balance start /ext4convert2btrfs
#df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/sda3                         100G  544K   99G   1% /ext4convert2btrfs

That's it :)

Related Question