Course contentsShow
← Linux
Lesson 733 of 1,8197. Storage Management and Logical VolumesFree lesson

Converting existing filesystems to Btrfs

Execute in-place migrations of legacy filesystems to modern copy-on-write systems.

Converting Existing Filesystems to Btrfs

In this lesson, you will learn how to transition a legacy filesystem, such as ext4, into a modern Btrfs environment using an in-place migration tool.

When you have a drive already formatted as ext4, you don't necessarily need to back up your data, wipe the disk, and copy everything back. The btrfs-convert utility allows you to transform an existing ext4 filesystem into Btrfs while preserving your original data. It works by creating a new Btrfs structure on the existing block device and remapping the old ext4 data blocks into the Btrfs metadata tree.

How the Migration Works

When you run the conversion tool, it performs a few critical steps:

  1. It validates that the ext4 filesystem is healthy (you should always run fsck first!).
  2. It creates an ext2_saved subvolume. This acts as a safety net, containing a snapshot of your original ext4 filesystem data, allowing you to rollback if something goes wrong.
  3. It converts the block mapping to the Copy-on-Write (CoW) Btrfs format.

To perform this migration, you must first unmount the device:

# Ensure the filesystem is clean
sudo e2fsck -f /dev/sdb1

# Convert the filesystem
sudo btrfs-convert /dev/sdb1

Once the conversion completes, you can mount your new Btrfs partition and start using features like subvolumes or snapshots immediately. However, remember that because the data is essentially being "referenced" from the original structure, the disk might not report free space exactly as you expect until you delete the ext2_saved subvolume to reclaim that space.

Important Considerations

While in-place migration is convenient, it is not a replacement for a backup. Any operation that modifies filesystem structures carries a risk of data loss. Additionally, once you finalize the conversion by deleting the ext2_saved subvolume, you cannot revert the drive back to ext4. Only perform this on a system where you have verified your data integrity beforehand.

Key Takeaway: The btrfs-convert utility enables an in-place transition from ext4 to Btrfs by creating a snapshot of the original data, providing a safe, non-destructive path to modern storage management.