summaryrefslogtreecommitdiff
path: root/articles/mdadm-raid.html
diff options
context:
space:
mode:
Diffstat (limited to 'articles/mdadm-raid.html')
-rw-r--r--articles/mdadm-raid.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/articles/mdadm-raid.html b/articles/mdadm-raid.html
new file mode 100644
index 0000000..dd2a014
--- /dev/null
+++ b/articles/mdadm-raid.html
@@ -0,0 +1,120 @@
1<!DOCTYPE html>
2<html lang=en>
3 <head>
4 <title></title>
5 <meta charset="utf-8"/>
6 <link rel="shortcut icon" href="favicon.ico"/>
7 <link rel='stylesheet' href='../style.css'/>
8 <meta name="viewport" content="width=device-width, initial-scale=1">
9 </head>
10<body>
11 <header><h1>Linux Software RAID</h1></header>
12 <main>
13 <p><strong>mdadm</strong> is a tool that allows for creation and
14 management of software RAID arrays on Linux. Creating an array
15 is a rather straightforward process.</p>
16
17 <h2>Install packages</h2>
18 <p>The only package needed is mdadm itself</p>
19 <pre><code>apt install mdadm</code></pre>
20
21 <h2>Partition disks</h2>
22 <p>We'll need to parition the disks to be used in the array before
23 creating it. This isn't anything complicated, we will just be
24 creating a single partition using all the space on each disk.</p>
25
26 <p>Use <strong>lsblk</strong> to get a list of disks attached to your system.</p>
27
28 <img src=../images/raid/lsblk.png alt="lsblk command">
29
30 <p>Then use <strong>fdisk</strong> to edit the partition table of the
31 first disk. In my case this would be <strong>/dev/sdb</strong>.
32 Be sure that you are selecting the correct disk as selecting the
33 wrong one can result in data being lost.</p>
34
35 <pre><code>fdisk /dev/sdb</code></pre>
36
37 <p>Use <strong>g</strong> to create a new GUID partition table.
38 Use <strong>n</strong> to create a new partition, and then just press
39 enter at all of the prompts to accept the defaults. Finally use
40 <strong>w</strong> to write the changes. You can use lsblk again
41 to verify the change and you should see that /dev/sdb now has a
42 partition <strong>/dev/sdb1</strong>.</p>
43
44 <img src=../images/raid/fdisk.png alt="fdisk command">
45
46 <p>Repeat this process for your other disks before continuing.</p>
47
48
49 <h2>Create the array</h2>
50 <p>Creating the array is done with a single command, but takes just a
51 bit of planning.</p>
52 <ul>
53 <li>Define an ID for the array, which is just a
54 number identifier. I use <em>0</em> in the command.</li>
55 <li>Determine the RAID level you want to use. I am going to
56 use RAID5 in this example. The argument to --level is the
57 number of the RAID level</li>
58 <li>Determine the devices that will be used in the array.
59 Somewhat contrary to the argument name, these devices
60 will actually be the partitions of the disks and not the
61 disks themselves. In the command, give the number of
62 partitions (<em>3</em>) and then a space-separated list of the
63 partitions that will be active in the array
64 (<em>/dev/sdb1 /dev/sdc1 /dev/sdd1</em>).</li>
65 <li>If you want to have any spare devices in the array you
66 will define them with the --spare-devices argument. These are
67 defined in the exact same way as the active RAID devices. In
68 the example I use <em>1</em> spare <em>/dev/sde1</em>. Spare
69 devices are hot-spares that will automatically be inserted into
70 the array if one of the disks fails.</li>
71 </ul>
72
73 <pre><code>mdadm --create /dev/md<em>0</em> --level=<em>5</em> --raid-devices=<em>3</em> <em>/dev/sdb1 /dev/sdc1 /dev/sdd1</em> --spare-devices=<em>1</em> <em>/dev/sde1</em></code></pre>
74
75 <p>After creating the array run the following command to get details
76 and the status of the array. It will take a bit to initialize the
77 array, you will know this is done when the state is clean. You do not
78 need to wait for the array to completely intialize to continue.</p>
79
80 <pre><code>mdadm --detail /dev/md<em>0</em></code></pre>
81
82 <p>Take note of the UUID and name values as we will need them in the
83 next step.</p>
84
85 <p>Before moving on we need to make a filesystem on the array. I'm
86 going to make a simple EXT4 filesystem here.</p>
87
88 <pre><code>mkfs.ext4 /dev/md<em>0</em></code></pre>
89
90
91 <h2>Configuration Files</h2>
92
93 <p>Open the mdadm configuration file at
94 <strong>/etc/mdadm/mdadm.conf</strong> and append this line. Replace
95 <em>uuid</em> and <em>name</em> with the values you got when running
96 mdadm --detail, replace <em>0</em> whatever ID you chose.</p>
97
98 <pre><code>ARRAY /dev/md<em>0</em> metadata=1.2 UUID=<em>uuid</em> name=<em>name</em></code></pre>
99
100 <p>Optionally, create an <strong>/etc/fstab</strong> entry for
101 automounting of the array. Replace /mnt/raid with the directory
102 where you want to mount the array. If you made a filesystem other than
103 ext4 make sure to change that value.</p>
104
105 <pre><code>/dev/md<em>0</em> /mnt/raid ext4 defaults 0 1</code></pre>
106
107<p>
108<hr>
109Consider <a href=../donate.html>donating</a> if this article was useful.
110<a class=qr href=../images/bitcoin.png>[BTC]</a>
111</p>
112 </main>
113 <footer>
114 <a href=../kb.html>Knowledge Base</a>
115 <br>
116 <a href=../index.html>www.chudnick.com</a>
117 </footer>
118</body>
119</html>
120