]> Posts for February 2019 🌐:aligrant.com

Copying a BTRFS volume to another disk, the easy way

Alastair Grant | Wednesday 27 February 2019

I've just picked up a 2TB Sandisk Ultra SSD for £200, finally hit 10p/GB on the big drives, and I've been wanting to consolidate my personal NAS' RAID-0 1.5TB classic hard drives to a single device.  I felt now is the time.

I use btrfs as my file system of choice, largely to the fantastic snapshot support.  This also helps me with the scenario of moving all my files.  I could use "dd" and image the whole drive, but it's nice every now and then to drop some dead wood, and clean things up.  For this, I'm going to snapshot my current subvolumes and move only the latest copy over to the new drive.  I don't need to keep the old snapshots online, if I need to get them again, I'll spin up the old drives.

btrfs comes with a "send" and a "receive" command.  One sends a subvolume, the other receives the data.  This is done at a block-level, so you don't have to worry about preserving permissions, acls and timestamps.  You can only source this from a readonly snapshot.

btrfs subvolume snapshot -r /mnt/old/folder /mnt/old/folder_0

Snapshot created in the folder_0 path.  Now to send it to another disk.

btrfs subvolume send /mnt/old/folder_0 | btrfs subvolume receive /mnt/new

This will create a readonly subvolume on the new drive called folder_0, create a writeable snapshot to complete the move:

brtrfs subvolume snapshot /mnt/new/folder_0 /mnt/new/folder

Clean up your old, temporary snapshots

btrfs subvolume delete /mnt/new/folder_0
btrfs subvolume delete /mnt/old/folder_0

You have to be mindful of embedded subvolumes.  This procedure will only copy a subvolume, if you have another subvolume nested further down your path, then they'll all need to be done too.  If you have a lot to work with, then automating it with a script might be sensible.  List all your subvolumes with

btrfs subvolume list /mnt/old

And unless you really want to, ignore all automated snapshots from that list.

Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.

Entries for: February 2019

Previous Next