17 lines
No EOL
14 KiB
HTML
17 lines
No EOL
14 KiB
HTML
<!doctype html><html lang=en><head><meta charset=utf-8><meta content="width=device-width,initial-scale=1.0" name=viewport><meta content="light dark" name=color-scheme><title>RAID with btrfs</title><link href=/img/favicon-32x32.png rel=icon sizes=32x32 type=image/png><link href=/img/favicon-16x16.png rel=icon sizes=16x16 type=image/png><link href=/img/apple-touch-icon.png rel=apple-touch-icon sizes=180x180><link href=https://fonts.googleapis.com rel=preconnect><link crossorigin href=https://fonts.gstatic.com rel=preconnect><link href="https://fonts.googleapis.com/css2?family=Signika&display=swap" rel=stylesheet><script data-website-id=422360e8-6821-4e32-82b2-05b380bc8cad defer src=https://cloud.umami.is/script.js></script></head><style>*{font-family:monospace!important}body{--primary-color:#8070c6;--primary-pale-color:#8070c61c;--text-color:#151517;--text-pale-color:#454449;--bg-color:#f4f0f3;--highlight-mark-color:#5f75b045;--callout-note-color:#e887bb;--callout-important-color:#a292e8;--callout-warning-color:#d9d564;--callout-alert-color:#f06969;--callout-question-color:#78b9c4;--callout-tip-color:#91d65c;font-size:1.1em}body.dark{--primary-color:#a292e8;--primary-pale-color:#a292e81c;--text-color:#ece5ea;--text-pale-color:#5c5c61;--bg-color:#151517;--highlight-mark-color:#5f75b045;--callout-note-color:#e887bb;--callout-important-color:#a292e8;--callout-warning-color:#d9d564;--callout-alert-color:#f06969;--callout-question-color:#78b9c4;--callout-tip-color:#91d65c}body{--main-font:"Signika",ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--code-font:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--homepage-max-width:750px;--main-max-width:750px;--avatar-size:70px;--avatar-radius:0;--paragraph-font-size:18px;--paragraph-line-height:1.75;--aside-font-size:16px;--img-border-radius:0px;--inline-code-border-radius:2px}</style><link href=/main.css rel=stylesheet><body class=post><script>if(localStorage.getItem(`theme`)==`dark`){document.body.classList.add(`dark`);const a=document.querySelector(`link#hl`);if(a)a.href=`/hl-dark.css`}</script><header class=blur><div id=header-wrapper><nav><a href=/>devraza</a><button aria-label="toggle expand" class=separator id=toggler>::</button><span class="wrap left fold">{</span><a href=/blog>blog</a><span class="wrap-separator fold">,</span><a class=fold href=/projects>projects</a><span class="wrap right fold">} ;</span></nav><div id=btns><button aria-label="theme switch" data-moon-icon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M10 7C10 10.866 13.134 14 17 14C18.9584 14 20.729 13.1957 21.9995 11.8995C22 11.933 22 11.9665 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C12.0335 2 12.067 2 12.1005 2.00049C10.8043 3.27098 10 5.04157 10 7ZM4 12C4 16.4183 7.58172 20 12 20C15.0583 20 17.7158 18.2839 19.062 15.7621C18.3945 15.9187 17.7035 16 17 16C12.0294 16 8 11.9706 8 7C8 6.29648 8.08133 5.60547 8.2379 4.938C5.71611 6.28423 4 8.9417 4 12Z" fill="currentColor"></path></svg>' data-sun-icon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M12 18C8.68629 18 6 15.3137 6 12C6 8.68629 8.68629 6 12 6C15.3137 6 18 8.68629 18 12C18 15.3137 15.3137 18 12 18ZM12 16C14.2091 16 16 14.2091 16 12C16 9.79086 14.2091 8 12 8C9.79086 8 8 9.79086 8 12C8 14.2091 9.79086 16 12 16ZM11 1H13V4H11V1ZM11 20H13V23H11V20ZM3.51472 4.92893L4.92893 3.51472L7.05025 5.63604L5.63604 7.05025L3.51472 4.92893ZM16.9497 18.364L18.364 16.9497L20.4853 19.0711L19.0711 20.4853L16.9497 18.364ZM19.0711 3.51472L20.4853 4.92893L18.364 7.05025L16.9497 5.63604L19.0711 3.51472ZM5.63604 16.9497L7.05025 18.364L4.92893 20.4853L3.51472 19.0711L5.63604 16.9497ZM23 11V13H20V11H23ZM4 11V13H1V11H4Z" fill="currentColor"></path></svg>' id=theme-toggle><svg viewbox="0 0 24 24" height=24 width=24 xmlns=http://www.w3.org/2000/svg><path d="M10 7C10 10.866 13.134 14 17 14C18.9584 14 20.729 13.1957 21.9995 11.8995C22 11.933 22 11.9665 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C12.0335 2 12.067 2 12.1005 2.00049C10.8043 3.27098 10 5.04157 10 7ZM4 12C4 16.4183 7.58172 20 12 20C15.0583 20 17.7158 18.2839 19.062 15.7621C18.3945 15.9187 17.7035 16 17 16C12.0294 16 8 11.9706 8 7C8 6.29648 8.08133 5.60547 8.2379 4.938C5.71611 6.28423 4 8.9417 4 12Z" fill=currentColor></path></svg></button><button aria-label="table of content" id=toc-toggle><svg viewbox="0 0 24 24" height=24 width=24 xmlns=http://www.w3.org/2000/svg><path d="M3 4H21V6H3V4ZM3 11H15V13H3V11ZM3 18H21V20H3V18Z" fill=currentColor></path></svg></button></div></div></header><div id=wrapper><div id=blank></div><aside class=blur><nav><ul><li><a class=h2 href=#introduction>Introduction</a> <ul><li><a class=h3 href=#what-is-raid>What is RAID?</a><li><a class=h3 href=#why-use-it>Why use it?</a></ul><li><a class=h2 href=#that-s-great-but-how-do-i-use-it>That's great, but how do I use it?</a> <ul><li><a class=h3 href=#raid1>RAID1</a><li><a class=h3 href=#raid0>RAID0</a><li><a class=h3 href=#nested-raid-levels>Nested RAID levels</a></ul><li><a class=h2 href=#useful-resources>Useful resources</a></ul></nav><button aria-label="back to top" id=back-to-top><svg viewbox="0 0 24 24" height=24 width=24 xmlns=http://www.w3.org/2000/svg><path d="M11.9997 10.8284L7.04996 15.7782L5.63574 14.364L11.9997 8L18.3637 14.364L16.9495 15.7782L11.9997 10.8284Z" fill=currentColor></path></svg></button></aside><main><div><div data-check-icon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M10.0007 15.1709L19.1931 5.97852L20.6073 7.39273L10.0007 17.9993L3.63672 11.6354L5.05093 10.2212L10.0007 15.1709Z" fill="currentColor"></path></svg>' data-copy-icon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M6.9998 6V3C6.9998 2.44772 7.44752 2 7.9998 2H19.9998C20.5521 2 20.9998 2.44772 20.9998 3V17C20.9998 17.5523 20.5521 18 19.9998 18H16.9998V20.9991C16.9998 21.5519 16.5499 22 15.993 22H4.00666C3.45059 22 3 21.5554 3 20.9991L3.0026 7.00087C3.0027 6.44811 3.45264 6 4.00942 6H6.9998ZM5.00242 8L5.00019 20H14.9998V8H5.00242ZM8.9998 6H16.9998V16H18.9998V4H8.9998V6Z" fill="currentColor"></path></svg>' id=copy-cfg style=display:none></div><article data-backlink-icon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20"><path d="M9.41421 8L18.0208 16.6066L16.6066 18.0208L8 9.41421V17H6V6H17V8H9.41421Z" fill="currentColor"></path></svg>' class=prose><h1>RAID with btrfs</h1><div id=post-info><div id=date><span id=publish>2024-12-30</span></div><div id=tags><a href=https://devraza.giize.com/tags/btrfs><span>#</span>btrfs</a><a href=https://devraza.giize.com/tags/nas><span>#</span>NAS</a><a href=https://devraza.giize.com/tags/raid><span>#</span>RAID</a><a href=https://devraza.giize.com/tags/raid10><span>#</span>RAID10</a><a href=https://devraza.giize.com/tags/raid1><span>#</span>RAID1</a><a href=https://devraza.giize.com/tags/raid0><span>#</span>RAID0</a></div></div><h1 id=introduction>Introduction<a aria-label="Anchor link for: introduction" class=zola-anchor href=#introduction>#</a></h1><h2 id=what-is-raid>What is RAID?<a aria-label="Anchor link for: what-is-raid" class=zola-anchor href=#what-is-raid>#</a></h2><p>Shamelessly copying from the <a rel="nofollow noreferrer" href=https://en.wikipedia.org/wiki/RAID>relevant Wikipedia page</a>:<blockquote><p>RAID (/reɪd/; redundant array of inexpensive disks or redundant array of independent disks) is a data storage virtualization technology that combines multiple physical data storage components into one or more logical units for the purposes of data redundancy, performance improvement, or both.</blockquote><p>That definition works well enough in case you don't already know what RAID is, which I doubt is the case for anyone reading this post.<h2 id=why-use-it>Why use it?<a aria-label="Anchor link for: why-use-it" class=zola-anchor href=#why-use-it>#</a></h2><p>Ever had a hard drive containing important data - without any backups - fail? Or, a little less likely, had a mission-critical file server break for a few hours because a drive failed? These are the two biggest problems that RAID solves.<h1 id=that-s-great-but-how-do-i-use-it>That's great, but how do I use it?<a aria-label="Anchor link for: that-s-great-but-how-do-i-use-it" class=zola-anchor href=#that-s-great-but-how-do-i-use-it>#</a></h1><p>And finally, we have the main body of this blog post! While frustatingly looking up how to do <em>slightly</em> weird things with RAID using <code>btrfs</code>, I found the lack of documentation annoying - so, I thought I'd make this blog post to aggregate a bunch of commands.<p>And so, the list:<h2 id=raid1>RAID1<a aria-label="Anchor link for: raid1" class=zola-anchor href=#raid1>#</a></h2><ul><li>Setting up RAID1 with two disks:<pre class=language-bash data-lang=bash style=color:#e8e8d3;background-color:#151515><code class=language-bash data-lang=bash><span style=color:#ffb964>mkdir</span><span> /mnt/raid1 </span><span style=color:#888># make the RAID1 pool
|
||
</span><span style=color:#ffb964>btrfs</span><span> device add /dev/sdA1 /mnt/raid1 </span><span style=color:#888># add the first device
|
||
</span><span style=color:#ffb964>btrfs</span><span> device add /dev/sdB1 /mnt/raid1 </span><span style=color:#888># add the second device
|
||
</span></code></pre><li>Setting up RAID1 when you already have a disk with some data on it and want to add another:<pre class=language-bash data-lang=bash style=color:#e8e8d3;background-color:#151515><code class=language-bash data-lang=bash><span style=color:#ffb964>btrfs</span><span> device add /dev/sdB1 /mnt/raid1 </span><span style=color:#888># add the second device
|
||
</span><span style=color:#ffb964>btrfs</span><span> balance start</span><span style=color:#ffb964> -dconvert</span><span>=raid1</span><span style=color:#ffb964> -mconvert</span><span>=raid1 /mnt/raid1 </span><span style=color:#888># distribute data to get the array set up
|
||
</span></code></pre></ul><h2 id=raid0>RAID0<a aria-label="Anchor link for: raid0" class=zola-anchor href=#raid0>#</a></h2><ul><li>Setting up RAID0 with two disks - exactly the same as with RAID1:<pre class=language-bash data-lang=bash style=color:#e8e8d3;background-color:#151515><code class=language-bash data-lang=bash><span style=color:#ffb964>mkdir</span><span> /mnt/raid1 </span><span style=color:#888># make the RAID1 pool
|
||
</span><span style=color:#ffb964>btrfs</span><span> device add /dev/sdA1 /mnt/raid0 </span><span style=color:#888># add the first device
|
||
</span><span style=color:#ffb964>btrfs</span><span> device add /dev/sdB1 /mnt/raid0 </span><span style=color:#888># add the second device
|
||
</span></code></pre> You can also continue to add more devices. The total storage available at the end of the process is the sum of the storage available on each drive:<pre class=language-bash data-lang=bash style=color:#e8e8d3;background-color:#151515><code class=language-bash data-lang=bash><span style=color:#ffb964>btrfs</span><span> device add /dev/sdC1 /mnt/raid0 </span><span style=color:#888># add the third device
|
||
</span><span style=color:#ffb964>btrfs</span><span> device add /dev/sdD1 /mnt/raid0 </span><span style=color:#888># add the fourth device
|
||
</span><span style=color:#888># and so on...
|
||
</span></code></pre><li>Setting up RAID0 when you already have a disk with some data on it and want to add another:<pre class=language-bash data-lang=bash style=color:#e8e8d3;background-color:#151515><code class=language-bash data-lang=bash><span style=color:#ffb964>btrfs</span><span> device add /dev/sdA1 /mnt/raid0 </span><span style=color:#888># add the second device
|
||
</span><span style=color:#ffb964>btrfs</span><span> balance start</span><span style=color:#ffb964> -dconvert</span><span>=raid0 /mnt/raid0 </span><span style=color:#888># distribute data to get the array set up
|
||
</span></code></pre></ul><h2 id=nested-raid-levels>Nested RAID levels<a aria-label="Anchor link for: nested-raid-levels" class=zola-anchor href=#nested-raid-levels>#</a></h2><p>Btrfs also supports RAID10 (or RAID1+0) which is a combination of RAID1 and RAID0 as demonstrated by the following image: <img alt="Image demonstrating how RAID10 looks" src=https://devraza.giize.com/img/raid10.png><p>However, as you can see, RAID10 requires <em>n</em> disks where <em>n</em> is an even number greater than or equal to 4. Furthermore, if you tried using devices of varying sizes, space would likely be wasted. So what would you do if you had 3 devices, with, for example, sizes of 1TB, 500GB, and 500GB?<p>A possible solution here would be to split the 1TB drive into two equal partitions of 500GB, and pass them to btrfs as independant drives.<p>Theoretically, you could also combine the two 500GB drives into a RAID0 partition and combine them through RAID1 with the 1TB drive (creating a nested RAID01/RAID0+1 array), but this seems to be unsupported by btrfs.<p>In general, setting up a RAID10 array with btrfs looks like this:<pre class=language-bash data-lang=bash style=color:#e8e8d3;background-color:#151515><code class=language-bash data-lang=bash><span style=color:#ffb964>mkdir</span><span> /mnt/raid10 </span><span style=color:#888># make the RAID10 pool
|
||
</span><span style=color:#ffb964>btrfs</span><span> device add /dev/sdA1 /dev/sdB1 /dev/sdC1 /dev/sdD1 /mnt/raid10 </span><span style=color:#888># add the drives
|
||
</span><span style=color:#ffb964>btrfs</span><span> balance start</span><span style=color:#ffb964> -dconvert</span><span>=raid10</span><span style=color:#ffb964> -mconvert</span><span>=raid10 /mnt/raid10 </span><span style=color:#888># distribute data to get the array set up
|
||
</span></code></pre><h1 id=useful-resources>Useful resources<a aria-label="Anchor link for: useful-resources" class=zola-anchor href=#useful-resources>#</a></h1><ul><li><a rel="nofollow noreferrer" href=https://carfax.org.uk/btrfs-usage/>btrfs disk usage calculator</a> - I found this somewhat useful, but it won't tell you how to get whatever configuration you set up to work<li><a rel="nofollow noreferrer" href=https://en.wikipedia.org/wiki/Nested_RAID_levels>The Wikipedia page on nested RAID levels</a></ul></article><div class=giscus></div></div><footer><div class=copyright><p>© 2023-2025 Muhammad Nauman Raza</div><div class=credits>powered by <a rel="noreferrer noopener" href=https://www.getzola.org target=_blank>zola</a> and <a rel="noreferrer noopener" href=https://github.com/isunjn/serene target=_blank>serene</a></div></footer></main></div><script src=/js/lightense.min.js></script><script src=/js/main.js></script> |