Friday, October 24, 2014

Linux convert ext4 to btrfs

Btrfs filesystem tool btrfs-convert can be used for convert ext2/ext3/ext4 to btrfs. Because of the copy on write algorithms of Btrfs it is posible to rollback the conversion even after you start using the converted file system.

The following is sample commands and output from an ext4 conversion to Btrfs in openSUSE 13.1. openSUSE will have Btrfs as the default filesystem from 13.2 which is going to be released next month. Go to openSUSE website for more information:

chris-linux:/home/chris # btrfs-convert /dev/sdb2
/dev/sdb2 is mounted
chris-linux:/home/chris # umount /dev/sdb2
chris-linux:/home/chris # btrfs-convert /dev/sdb2
creating btrfs metadata.
creating ext2fs image file.
cleaning up system chunk.
conversion complete.

After the conversion is complete you can change the fstab to reflect the converted filesystem. A sample follows with lzo compression and ssd optimization options:

# sample fstab entry
/dev/sdb2 /mnt/btrfsfiles btrfs defaults,noatime,compress=lzo 0 0
# for ssd
/dev/sdb2 /mnt/btrfsfiles btrfs defaults,noatime,ssd,compress=lzo 0 0

compress=lzo is a fast compression option that can provide more free space but also performance improvements in reading files.

At the end you can defragment the btrfs volume and at the same time compress all the files. The fstab and mount options will compress files from now on but not the existing files.

# defragment and compress all files after conversion 
btrfs filesystem defragment -r -v -clzo /mnt/linuxfiles

When you are happy with your new Btrfs volume you can delete the ext4 metadata that needed only for rollback to ext4 to save disk space

# Delete backup metadata if you dont need to rollback to ext4 anymore
btrfs subvol delete ext2_saved 

For more information about Btrfs you can visit the official Btrfs wiki.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.