Lyte's Blog

Bad code, bad humour and bad hair.

Moving My Butter (Btrfs)

I recently had need to migrate a btrfs mount to a new physical device and I wasn’t immediately finding the answer with Google (shock horror!) so when I figured out the commands I thought I’d share them here.

So uhm, before doing anything dangerous to a drive you’ve taken a backup right?

Moving on…

I chose to use a process that let me do a live migration underneath the file system while there was still data being written to the file system… you know, for fun.

Adding in the new device is as simple as:

1
$ btrfs device add $new_device $existing_mount_point

Which is quick! Suddenly you have a whole bunch more data available.

Removing the old device takes a lot longer but the command is just as simple:

1
$ btrfs device delete $old_device $existing_mount_point

To get a vague idea of progress watch:

1
2
3
4
5
6
7
$ btrfs-show
Label: none  uuid: 05d0397c-2dfc-4c2b-a508-22bf23099776
        Total devices 2 FS bytes used 682.24GB
        devid    1 size 931.48GB used 688.29GB path /dev/sdb1
        devid    2 size 1.82TB used 13.00GB path /dev/sdd

Btrfs Btrfs v0.19

In this case /dev/sdb1 is the old drive and /dev/sdd is the new drive. The usage of the new drive will gradually grow until it catches up with the old one. In the capture above it’s about 19% (13.00GB / 688.29GB) complete.

Eventually when it completes /dev/sdb1 no longer shows in the device list:

1
2
3
4
5
6
$ btrfs-show
Label: none  uuid: 05d0397c-2dfc-4c2b-a508-22bf23099776
        Total devices 1 FS bytes used 682.04GB
        devid    2 size 1.82TB used 686.52GB path /dev/sdd

Btrfs Btrfs v0.19

Comments