Moving root btrfs subvolume to another disk

I bought SSD disk for my laptop and successfully moved my HDD root subvolume to SSD. This post describes steps that I did.

Migrating
  • My HDD - /dev/sdb, btrfs is installed on /dev/sdb3
  • My SSD - /dev/sda, btrfs is installed on /dev/sda1

On my HDD I had two subvolumes, home and root. As always, first step is to backup everything.

$ sudo -i
# btrfs sub snap /home /home_backup
# btrfs sub snap /root /root_backup

I suppose that btrfs is already installed on SSD. Before start copying root on HDD to root on SSD we have to create new subvolume on SSD. To create subvolume on SSD we have to mount SSD:

# mkdir /tmp/ssd
# mount /dev/sda1 /tmp/ssd
# btrfs sub create /tmp/ssd/root

Now create readonly snapshot to copy subvolume:

# btrfs sub snap -r /root /root_ro

Start copying process

# btrfs send /root_ro | btrfs receive /tmp/ssd/root

When finish, we have to install grub on SSD and edit fstab. We will use chroot to do this, but first remount ssd subvolume or you will see this error message:

grub-install: error: cannot find a device for /boot/grub (is /dev mounted?)

# umount /tmp/ssd
# mount -t btrfs -o subvol=/root /dev/sda1 /tmp/ssd/
# for i in dev dev/pts sys proc run; do sudo mount --bind /$i /tmp/ssd/$i; done
# chroot /tmp/ssd
# grub2-install /dev/sda
# grub2-mkconfig -o /boot/grub2/grub.cfg

While in chroot - Don't forget to edit /etc/fstab and set appropriate UUID of new root subvolume. Check it using blkid.

Now exit chroot using Ctrl+D and umount SSD:

# umount -R /tmp/ssd

Reboot your computer and choose your new SSD as boot device, for my ASUS N550JK I have to press ESC to get menu where I can choose boot devices. When you successfully boot to a new root files system you may want to delete/clean previous root subvolumes:

# mkdir /tmp/hdd
# mount -t btrfs -o subvol="/" /dev/sdb3 /tmp/hdd

Check available subvolumes

# btrfs sub list /tmp/hdd

Remove:

# btrfs sub delete /tmp/hdd/root
# btrfs sub delete /tmp/hdd/root_ro
# btrfs sub delete /tmp/hdd/root_backup
# btrfs sub delete /tmp/hdd/home_backup

If you remove old root subvolume you also have to update grub, or you may be confused:

# grub2-mkconfig -o /boot/grub2/grub.cfg