-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguring-a-raid1-with-mdadm-on-debian-squeeze.html
160 lines (140 loc) · 11 KB
/
configuring-a-raid1-with-mdadm-on-debian-squeeze.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Configuring a RAID1 with mdadm on Debian Squeeze - kb.haeringer.org</title>
<link href="http://fonts.googleapis.com/css?family=Arimo:400,700|Inika" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/theme/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/theme/pastie.css" />
<link href="/" type="application/atom+xml" rel="alternate" title="kb.haeringer.org Atom Feed" />
</head>
<body>
<div class="container">
<div class="row">
<div class="span10">
<div id="content">
<div class="header">
<h1>Configuring a RAID1 with mdadm on Debian Squeeze</h1>
</br>
</div>
<p class="meta"><small><span><a href="/author/ben/">ben</a> - </span><span>Di 20 September 2011</span> - <span class="tags"><a href="/tag/Debian/">Debian</a>, <a href="/tag/RAID/">RAID</a></span></small></p>
<div class="entry-content">
<p>Generally I have always thought software raids to be insecure, difficult
to handle and more a risk than a safety measure. But a RAID1 with the
Linux software <strong>mdadm</strong> is a safe mirror of your harddisk - in case of
a HD failure, you can put the remaining disk into any computer and boot
from it. And it's easy to handle. One way to configure it on Debian is
with the Debian installer during the OS installation, which will be
described here.</p>
<p>First, a brief explanation of how software raids work - this is needed
to understand the installation process. In a hardware raid, devices
exist as hard disks. In a software raid, those devices are partitions
that are marked as “Physical volumes for RAID”. Those partitions are
then combined into a software RAID array. This array contains normal
partitions as they are present on every normal non-raid hard disk.<br />
<!--more--><br />
I wrote this because I think that the setup process is not
self-explanatory and can be a bit confusing.</p>
<p>1. During the Debian installation, choose manual partitioning</p>
<p>2. Select the first harddisk (sda) and create a new partition table</p>
<p>3. Choose the newly created free space and create new partitions
(primary), selecting "Use as: physical volume for RAID" for each one.
This is where you define your own filesystem structure, so the below is
only an example:<br />
- First RAID partition of 2-4 GB for the root file system /<br />
- Second RAID partition for swap, 2 times RAM<br />
- Third RAID partition for data, rest of HD space</p>
<p>4. Select the second hard disk (sdb) and repeat all steps above</p>
<p>5. When finished, select "Configure software RAID" and follow the
on-screen instructions:<br />
- Create MD device<br />
- RAID1<br />
- Number of active devices = 2<br />
- Spare devices = 0<br />
- Repeat for active devices = sda1 + sdb1, sda2 + sdb2, sda3 + sdb3<br />
- Finish</p>
<p>6. Back in the partitions overview, select the partition of the first
RAID device</p>
<p>7. Choose "Use as: do not use" from the menu and change it to ext4 (or
whatever you need) file system, mount point /, done</p>
<p>8. For the second RAID partition, change "Use as" to swap area</p>
<p>9. For the third one, change to ext4, mount point "Enter manually" and
name it e.g. /data</p>
<p>10. Finish partitioning</p>
<p>11. After rebooting, when the installation has finished, verify your
RAID configuration with cat /proc/mdstat</p>
<p>Grub2 only gets installed on the first HD, sda, by default. Install
Grub2 also on the second HD to make it bootable in case HD1 fails:</p>
<div class="highlight"><pre><span class="n">grub</span><span class="o">-</span><span class="n">install</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb</span>
</pre></div>
<p>Done. </p>
<p><strong>Harddisk Failure</strong></p>
<p>If you test your RAID1 by removing one HD and installing it back again;
your RAID may not come up correct again automatically. Check with
<code>cat /proc/mdstat</code>. In case of a partially degraded array, fully degrade
it first:</p>
<div class="highlight"><pre><span class="n">mdadm</span> <span class="o">--</span><span class="n">manage</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md0</span> <span class="o">--</span><span class="n">fail</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb1</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">manage</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md1</span> <span class="o">--</span><span class="n">fail</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb2</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">manage</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md2</span> <span class="o">--</span><span class="n">fail</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb3</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">manage</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md0</span> <span class="o">--</span><span class="n">remove</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb1</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">manage</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md1</span> <span class="o">--</span><span class="n">remove</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb2</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">manage</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md2</span> <span class="o">--</span><span class="n">remove</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb3</span>
</pre></div>
<p>At this point, your system is like having installed a new second HD
(sdb) after a real failure. If that's the case (i.e. the disk is empty),
copy the partition table of /dev/sda to /dev/sdb:</p>
<div class="highlight"><pre><span class="n">sfdisk</span> <span class="o">-</span><span class="n">d</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sda</span> <span class="o">|</span> <span class="n">sfdisk</span> <span class="o">--</span><span class="n">force</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb</span>
</pre></div>
<p>Afterwards, remove any remains of a previous RAID array from /dev/sdb:</p>
<div class="highlight"><pre><span class="n">mdadm</span> <span class="o">--</span><span class="n">zero</span><span class="o">-</span><span class="n">superblock</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb1</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">zero</span><span class="o">-</span><span class="n">superblock</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb2</span>
<span class="n">mdadm</span> <span class="o">--</span><span class="n">zero</span><span class="o">-</span><span class="n">superblock</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb3</span>
</pre></div>
<p>...and add /dev/sdb back to the array:</p>
<div class="highlight"><pre><span class="n">mdadm</span> <span class="o">-</span><span class="n">a</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md0</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb1</span>
<span class="n">mdadm</span> <span class="o">-</span><span class="n">a</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md1</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb2</span>
<span class="n">mdadm</span> <span class="o">-</span><span class="n">a</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md2</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdb3</span>
</pre></div>
<p>If there are error messages and you have problems rebuilding the array,
check the config file /etc/mdadm/mdadm.conf - your array should be
listed there. If it's not, issue the following command to add it to the
config file:</p>
<div class="highlight"><pre><span class="n">mdadm</span> <span class="o">--</span><span class="n">examine</span> <span class="o">--</span><span class="n">scan</span> <span class="o">--</span><span class="n">config</span><span class="o">=</span><span class="n">mdadm</span><span class="p">.</span><span class="n">conf</span> <span class="o">>></span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">mdadm</span><span class="o">/</span><span class="n">mdadm</span><span class="p">.</span><span class="n">conf</span>
</pre></div>
<p>Check the array status with <code>cat /proc/mdstat</code>. After the
synchronisation has finished, you should have a fully working RAID1
again.</p>
<p>One last tip: In case the md1 device of your RAID array is shown as
"resync=PENDING" and doesn't leave that state anymore (can happen after
a hard reboot, e.g. because of a power outage), this can easily fixed
with</p>
<div class="highlight"><pre><span class="n">mdadm</span> <span class="o">--</span><span class="n">readwrite</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">md1</span>
</pre></div>
</div><!-- /.entry-content -->
</div>
</div>
<div class="span2">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Blog</li>
<!-- <li ><a href="">Home</a></li> -->
<li ><a href="index.html">Home</a></li>
<li ><a href="/tags/">Tags</a></li>
<li ><a href="/archives/">Archive</a></li>
<li class="nav-header">Pages</li>
<li><a href="/pages/about.html">About</a></li>
</ul>
</div><!-- /#menu -->
</div>
</div>
<hr />
<div class="row">
<div class="span12">
<div id="about">
<p>Proudly powered by <a href="http://twitter.github.com/bootstrap/">bootstrap</a>, <a href="http://docs.notmyidea.org/alexis/pelican/">pelican</a>, <a href="http://python.org">python</a> and <a href="http://www.julo.ch/about/">Alex</a></p>
</div><!-- /#about -->
</div><!-- /#contentinfo -->
</div>
</div>
</body>
</html>