How to move a BTRFS filesystem to another drive?
+1
−0
How to migrate a single device BTRFS filesystem to a new drive? I don't want to send individual subvolumes, but instead the entire filesystem with its subvolume layout intact. Changing the filesystem UUID is fine.
1 answer
+1
−0
A convenient but a little risky method
Don't do this unless you have backups on a separate drive, and are prepared to restore from them.
Properties
Pros
- Easy
- Uses native BTRFS tools
- Can be done on a live system, even if
/
is on this filesystem.- Though you will need to update mount configs, initramfs and bootloader if you intend to boot into the migrated filesystem.
Cons
- The filesystem on the old drive will be left unusable.
- An interruption (like powerloss) during the operation can lead to data loss.
Neutral
- This method will leave the filesystem UUID unchanged, so you don't have to update your configs in places like
/etc/fstab
.
Instructions
We leverage the fact that BTRFS is a multi-drive capable filesystem. First we add the new drive to the filesystem, and then we remove the old one. BTRFS will take care of moving the data behind the scenes.
Make sure that the new drive is at least as big as the old one. Don't create a new filesystem there prior.
# btrfs device add /dev/newdrive /path/to/the/filesystem
# btrfs device remove /dev/olddrive /path/to/the/filesystem
Notes
- I speak of "drives" but this can mean any type of block device. E.g. a partition or an opened dm-crypt container.
- This method generalizes to any number of drives. E.g. changing 2 drives from a 5 drive filesystem.
0 comment threads