BTRFS: migration to a new disk (without rushing)
I needed a way for gradually migrate a my magnetomechanic disk to a new SSD storage unit, providing for a RAID1 period in order to see how the new SSD unit behaved.First of all, the new SSD unit needs to be formatted, using the “ -f ” option in the following command:
# sdA => source disk ; sdB => destination SSD unit mount /dev/sdA1 /m/mountedA/ btrfs device add -f /dev/sdB1 /m/mountedA/
After that you need to convert this filesystem in a RAID1 (for now the disks are used as stripes):
btrfs balance start -v -mconvert=raid1 -dconvert=raid1 /m/mountedA/
Now both filesystems have the same data, but they can't be mounted normally. If you want to mount a single disk you need to use the degraded mode (with read/write access).
mount -o degraded /dev/sdB1 /m/temp1/
When you want to make the SSD an indipendent disk, you can attach to the computer alone, mount it in degraded mode and execute the following command:
btrfs balance start -f -mconvert=dup -dconvert=single /m/mountedB/
Now you can remove the source device. Before that, you need to print the devid of recognized devices:
btrfs filesystem show /m/mountedB/
You need to remove the one with 0 bytes used.
# X => devid number. It's a little integer, like “1” or “2”. btrfs device remove X /m/mountedB/
You can execute the same procedure on the source disk as well. Source disk may not show what is the devid for removal. In this case, take the higher value shown in the list and add 1.
For example, if “
btrfs filesystem show /m/mountedB/
” prints this:devid 1 size ... used ... path /dev/sdB1 *** some devices missing
... you can execute:
btrfs device remove 2 /m/mountedB/
2022
Apr, 23
Apr, 23