{"title":"BTRFS RAID1 and how to fix it","url":"https://seanbehan.ca/posts/btrfs","description":"Setting up a two-disk BTRFS RAID1 for a Steam library, and repairing it when a drive starts throwing errors.","author":"Sean Behan","published":"2023-05-23T14:39:58.000Z","updated":null,"draft":false,"tags":["backup","linux","raid"],"readingMinutes":2,"image":null,"sections":[{"id":"btrfs-raid1-setup","text":"BTRFS RAID1 Setup","level":2},{"id":"formatting-drives","text":"Formatting Drives","level":2},{"id":"creating-the-raid1-array","text":"Creating the RAID1 Array","level":2},{"id":"managing-the-array","text":"Managing the Array","level":2}],"content_format":"text/markdown","content_url":"https://seanbehan.ca/posts/btrfs.md","content":"### BTRFS RAID1 Setup\n\nI mentioned in my previous post that I use an external drive to keep my Steam\n\ngames on. In an attempt to not have to re-download hundreds of gigabytes of\n\ngames I keep them on a RAID1 with 2x5TB drives that I use BTRFS to manage. In\n\nthis post I'm going to outline how I set it all up, and how I manage it when\n\nissues arise.\n\n### Formatting Drives\n\nFirst of all I had to format the drives, so I made sure they were empty and\n\neverything was backed up. Don't do this unless you know for sure that all the\n\ndata on all your drives is backed up somewhere else, or you want to delete it\n\npermanently.\n\nOkay so the commands are easy, you just have to make sure you're using the\n\nright ones as not to lose your data. Don't run these commands without\n\nunderstanding what they do. Replace \\_ with your drive letter. A lot of these\n\ncommands need to be run with root, make sure to either elevate to root (`sudo -s`)\n\nor prepend the commands with `sudo`.\n\n```sh\nlsblk\n```\n\n```sh\nmkfs.btrfs /dev/sd_1\nmkfs.btrfs /dev/sd_1\n```\n\n### Creating the RAID1 Array\n\nNow you can mount the newly formatted drives to a single RAID1.\n\n```sh\nmount /dev/sd_1 /mnt\nbtrfs device add /dev/sd_1 /mnt\nbtrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt\n```\n\nThe last command might take a little bit of time, but once it's finished your\n\ndrives will be all ready to be used.\n\n### Managing the Array\n\nNow if you need to swap out a drive, add another, or you unplug one when it's\n\nwriting you can simply balance again and btrfs should be able to balance back\n\nonto the drive.\n\n```sh\nbtrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt\n```\n\nYou can view the status of the balance using:\n\n```sh\nbtrfs balance status\n```\n\nYou can remove a drive or add another using:\n\n```sh\nbtrfs device remove /dev/sd_1\nbtrfs device add /dev/sd_1\n```\n\nJust make sure you balance right afterwards (which will take a VERY long time\n\nif you have lots of data, beware)\n\n```sh\nbtrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt\n```\n"}