How to convert a ext3 or ext4 filesystem to Btrfs

Btrfs is a new copy on write filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, repair and easy administration. Initially developed by Oracle, Btrfs is licensed under the GPL.

Note that Btrfs does not yet have a fsck tool that can fix errors. While Btrfs is stable on a stable machine, it is currently possible to corrupt a filesystem irrecoverably if your machine crashes or loses power on disks that don't handle flush requests correctly. This will be fixed when the fsck tool is ready.

Features

Linux has a wealth of filesystems to choose from, but we are facing a number of challenges with scaling to the large storage subsystems that are becoming common in today's data centers. Filesystems need to scale in their ability to address and manage large storage, and also in their ability to detect, repair and tolerate errors in the data stored on disk.

The main Btrfs features available at the moment include:

  • Extent based file storage
  • 2^64 byte == 16 EiB maximum file size
  • Space-efficient packing of small files
  • Space-efficient indexed directories
  • Dynamic inode allocation
  • Writable snapshots, read-only snapshots
  • Subvolumes (separate internal filesystem roots)
  • Checksums on data and metadata
  • Compression (gzip and LZO)
  • Integrated multiple device support
  • RAID-0, RAID-1 and RAID-10 implementations
  • Efficient incremental backup
  • Background scrub process for finding and fixing errors on files with redundant copies
  • Online filesystem defragmentation

Additional features in development, or planned, include:

  • RAID-5 and RAID-6
  • Object-level mirroring and striping
  • Alternative checksum algorithms
  • Online filesystem check
  • Efficient incremental filesystem mirroring

To Convert Ext3 or Ext4 in Btrfs Filesystem

1) First install the btrfs-progs package

[root@server ~]# yum install btrfs-progs
2) umount the device which you want to convert
[root@server ~]# umount /dev/sdb1
3) Always run fsck first
[root@server ~]# fsck.ext3 -f /dev/sdb1
4) Convert from Ext3/4->Btrfs
[root@server ~]# btrfs-convert /dev/sdb1
5) Mount the resulting Btrfs filesystem
[root@server ~]# mount -t btrfs /dev/sdb1 /btrfs
You can also mount the ext3/4 snapshot inside it
[root@server ~]# mount -t btrfs -o subvol=ext2_saved /dev/sdb1 /ext2_saved
[root@server ~]# mount -t ext3 -o loop,ro /ext2_saved/image /ext3

In the example above, the files in /ext3 and in /btrfs will be identical. Any modifications made in /btrfs will not show up in /ext3. If you wish to roll back the conversion:

1) Completely unmount the Btrfs filesystem
[root@server ~]# umount /ext3
[root@server ~]# umount /ext2_saved
[root@server ~]# umount /btrfs
2) Roll back the conversion
[root@server ~]# btrfs-convert -r /dev/sdb1
3) Use the original filesystem while mounting
[root@server ~]# mount -t ext3 /dev/sdb1 /ext3

Or, if you wish to recover the space used by the original Ext3/4 FS and make the conversion permanent, simply delete /ext2_saved/image.

Reference: https://btrfs.wiki.kernel.org/index.php/Conversion_from_Ext3

ALSO READ:

How to convert a ext2 filesystem to ext3
How to convert a ext3 filesystem to ext4
How to convert a ext2 filesystem to ext4