User:Nathanlkoch/Tutorials/Btrfs Drive Migration

From Gentoo Wiki
Jump to:navigation Jump to:search

Btrfs Drive Migration

Moving btrfs volumes to new disks is super easy. You don't have to mess around with resizing partitions because btrfs subvolumes expand as needed.

You would create your new partitions as normal. A fat32 boot for EFI and then your formatted btrfs luks partition like done in the tutorial created. User:Nathanlkoch/Tutorials/BTRFS Encryped Root On UEFI It's pretty straight forward. Mount your luks partitions after unlocking each luks disk. Once you have done the mount /mnt/btrfsmirror* stuff.

You will need to make several directories.

root #mkdir /mnt/btrfsmirror0
root #mkdir /mnt/btrfsmirror1

Then you mount your old drive as /mnt/btrfsmirror0 and the new drive as /mnt/btrfsmirror1.

Create the snapshots on the old drive.

root #btrfs subvolume snapshot /mnt/btrfsmirror0/activeroot /mnt/btrfsmirror0/activeroot.snapshot
root #btrfs subvolume snapshot /mnt/btrfsmirror0/home /mnt/btrfsmirror0/home.snapshot

Make the snapshots read only on the old drive.

root #btrfs subvolume snapshot -r /mnt/btrfsmirror0/activeroot.snapshot /mnt/btrfsmirror0/activeroot.readonly
root #btrfs subvolume snapshot -r /mnt/btrfsmirror0/home.snapshot /mnt/btrfsmirror0/home.readonly

Send the snapshots on the old drive to the new drive.

root #btrfs send /mnt/btrfsmirror0/activeroot.readonly | btrfs receive /mnt/btrfsmirror1/
root #btrfs send /mnt/btrfsmirror0/home.readonly | btrfs receive /mnt/btrfsmirror1/

Make the snapshots read/write on new drive.

root #btrfs subvolume snapshot /mnt/btrfsmirror1/activeroot.readonly /mnt/btrfsmirror1/activeroot
root #btrfs subvolume snapshot /mnt/btrfsmirror1/home.readonly /mnt/btrfsmirror1/home

Next you would just make your /mnt/newroot and mount your new btrfs root and home sub volumes , and boot directory like in the tutorial. Once mounted change your uuid in the /etc/default/grub file, maybe reinstall grub for safe measure, and change your fstab. For the vfat boot partition I just did a straight cp from /mnt/oldboot to /mnt/newboot after mounting the drive.


Then delete the snapshots you created after you have rebooted a few times, reinstalled grub, changed your /etc/default/grub files, and generated a new menu and fstab based on your updated UUID and partition numbers for fstab.

root #btrfs subvolume delete /mnt/btrfsmirror0/activeroot.readonly && btrfs subvolume delete /mnt/btrfsmirror1/activeroot.readonly && btrfs subvolume delete /mnt/btrfsmirror0/home.readonly && btrfs subvolume delete /mnt/btrfsmirror1/home.readonly


Done