Skip to content

Instantly share code, notes, and snippets.

@seeekr
Last active April 24, 2022 21:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seeekr/1afa1e5ce3ad6e998367 to your computer and use it in GitHub Desktop.
Save seeekr/1afa1e5ce3ad6e998367 to your computer and use it in GitHub Desktop.
Using RAID with CoreOS (btrfs; RAID0, RAID1)
#!/bin/sh
# replace with whatever your additional device is called
# /dev/sda should be where your CoreOS install lives right now
newdevice="/dev/sdb"
# 0 or 1
raidtype="0"
# make sure to download the single-partition.layout file as well
# create single primary partition on $newdevice (you could also run fdisk interactively, choose p command and use defaults it suggests)
sudo sfdisk $newdevice < single-partition.layout
# mount current root; I suppose /dev/sda9 would work as well?
sudo mount /dev/disk/by-label/ROOT /mnt
# add btrfs device
sudo btrfs device add /dev/sdb1 /mnt
# convert to raid of given type; don't use -mconvert=raid0 but not sure if it's beneficial to add -mconvert=raid1 when making a RAID1 (I think it might be!)
sudo btrfs balance start -dconvert=raid$raidtype /mnt
# might take a bit, depending on how much data there is to copy over
# verify things have worked
sudo btrfs fi df /mnt
# should show something like...
#Data, RAID0: total=6.00GiB, used=303.25MiB
#System, DUP: total=8.00MiB, used=16.00KiB
#System, single: total=4.00MiB, used=0.00
#Metadata, DUP: total=108.06MiB, used=18.78MiB
#Metadata, single: total=8.00MiB, used=0.00
#unknown, single: total=16.00MiB, used=0.00
# clean up
sudo umount /mnt
# partition table of /dev/sdb
unit: sectors
/dev/sdb1 : start= 2048, size=937701040, Id=83
/dev/sdb2 : start= 0, size= 0, Id= 0
/dev/sdb3 : start= 0, size= 0, Id= 0
/dev/sdb4 : start= 0, size= 0, Id= 0

original pointers from @marineam at coreos/docs#222 (comment)

btrfs adding devices and rebalancing: https://btrfs.wiki.kernel.org/index.php/Using_Btrfs_with_Multiple_Devices#Adding_new_devices

btrfs rebalance command: http://askubuntu.com/a/412307 essence of that: don't use -mconvert=raid0 since that would mean "use raid0 for metadata also" which is not advisable

running fdisk in non-interactive mode: http://xmodulo.com/how-to-run-fdisk-in-non-interactive-batch-mode.html

additional docs by coreos that already point in the right direction and that are probably a candidate for introducing explicit information about getting up and running with RAID: https://coreos.com/docs/cluster-management/debugging/btrfs-troubleshooting/

@seeekr
Copy link
Author

seeekr commented Dec 11, 2014

Here's another piece of documentation I hadn't seen: https://coreos.com/docs/cluster-management/debugging/btrfs-troubleshooting/#adding-a-new-physical-disk
Maybe it's even easier and the "create partition" step isn't even required. That hadn't worked for me when trying to add the disk to btrfs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment