osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Replacing a Btrfs drive - best practices?


As a follow-up, here is the method I used that worked fairly well. This allowed me to move my Btrfs /home partition from a stand-alone disk to a new Btrfs raid1 array.


1. Make a Raid1 Btrfs filesystem

# mkfs.btrfs -m raid1 -d raid1 /dev/sdc /dev/sdd
where sdc and sdd are my new drives, sda is my existing / partition and sdb is my existing /home


2. Mount the Raid1 array

# mkdir /media/homebackup
# mount /dev/sdc /media/homebackup


3. Make a snapshot of my existing /home

# mount /dev/sdb1 /mnt
# btrfs subvolume snapshot /mnt/@home /mnt/@home_backup

Ubuntu Btrfs documentation recommends mounting Btrfs volumes to /mnt for ease of working with. See:
https://help.ubuntu.com/community/btrfs

Might as well make a backup of / (root) too. Just in case something gets mucked up in fstab later. 
# mount /dev/sda1 /mnt
# btrfs subvolume snapshot /mnt/@ /mnt/@_backup

4. Send the snapshot to the new drive 

# btrfs send /mnt/@home_backup | pv -b -a | btrfs receive /media/homebackup

This part can take several hours, depending on the amount of data that needs to be sent.


5. Make new snapshot, wdevid    2 size 1.82TiB used 1.21TiB path /dev/sdd

Label: none  uuid: 56b012cf-a870-4105-88e7-6f5806738e8d
	Total devices 1 FS bytes used 1.21TiB
	devid    1 size 1.82TiB used 1.58TiB path /dev/sdb1

hich resets to writable

# btrfs subvolume snapshot /media/homebackup/@home_backup /media/homebackup/@home


6. Edit /etc/fstab

The simple way is to change the UUID to point to the new drive(s), and have the old drive point to a new location. Something like:

UUID=XXX /media/homebackup btrfs defaults,subvol=@home,noauto 0 2
UUID=XXX /home btrfs noatime,nodiratime,autodefrag,subvol=@home 0 3


7. Reboot and verify

If all goes according to plan, the new raid array will mount as /home upon boot, and the old drive will not be mounted. In my case:

matthew at matt-linux-desktop:~$ df -k
Filesystem              1K-blocks       Used Available Use% Mounted on
/dev/sda1               470807552    8777432 460347848   2% /
/dev/sdc               1953514584 1302434304 650683152  67% /home
/dev/sdc               1953514584 1302434304 650683152  67% /mnt

matthew at matt-linux-desktop:~$ sudo lsblk -f
NAME           FSTYPE   LABEL UUID                                 MOUNTPOINT
sda                                                                
â??â??sda1         btrfs          dde09d67-fe28-4a79-ac1d-3dec0ef486ca /
â??â??sda2                                                             
â??â??sda5         swap           21c78577-95f6-49fb-be38-862013ec9252 
  â??â??cryptswap1 swap           e3c2d3de-e2d0-4fba-9fda-d929aea3167b [SWAP]
sdb                                                                
â??â??sdb1         btrfs          56b012cf-a870-4105-88e7-6f5806738e8d 
sdc            btrfs          d3c8cb5d-5394-477b-bb1f-5cc78316800e /mnt
sdd            btrfs          d3c8cb5d-5394-477b-bb1f-5cc78316800e 

sdb1 is currently not mounted, while sdc is mounted at /home and /mnt. Due to a quirk with Btrfs raid arrays, sdd will appear to be unmounted. However you can verify that the raid array is working:

matthew at matt-linux-desktop:~$ sudo btrfs filesystem show
Label: none  uuid: d3c8cb5d-5394-477b-bb1f-5cc78316800e
	Total devices 2 FS bytes used 1.21TiB
	devid    1 size 1.82TiB used 1.21TiB path /dev/sdc
	devid    2 size 1.82TiB used 1.21TiB path /dev/sdd




Hope this helps anyone else out there!