{"id":283,"date":"2008-12-27T19:38:26","date_gmt":"2008-12-27T18:38:26","guid":{"rendered":"http:\/\/sickel.net\/blogg\/?p=283"},"modified":"2009-01-08T15:16:12","modified_gmt":"2009-01-08T14:16:12","slug":"rebuilding-a-raid5","status":"publish","type":"post","link":"https:\/\/sickel.net\/blogg\/?p=283","title":{"rendered":"Rebuilding a raid5"},"content":{"rendered":"<p>In theory, it should be simple. One of the disks, the \/dev\/hdd, in my raid5-array on a linux machine (an old dell poweredge server) had failed. As far as I understood, it should just be to turn of the machine (since i don&#8217;t have hot-swap-able hardware) get out the old disk. insert a new of the same size or bigger and reboot&#8230; But then disaster struck&#8230; According to SMART, one of the disk had a real good ol&#8217; hardware error, but then the other disk on the same controller was marked as defective, or by some other way taken out of the array, so then my nice three-disk RAID5 was reduced to one unusable disk.<\/p>\n<p>Looking into the s.m.a.r.t. info on each of the failed disks, it seemed that one of them had failed, but the other had at least no smart-errors, but then, how to get a failed disk back in the array? I have found quite a few lessions telling you to &#8220;fail a disk&#8221; and then take it out of the array, but not how to get that disk back again&#8230; <\/p>\n<p>That turned out to be as easy as to rebuild the array:<br \/>\n<code># \/sbin\/mdadm --create --verbose \/dev\/md0 --level=5 --raid-devices=3 \/dev\/hdb1 \/dev\/hda1 \/dev\/hdf1<br \/>\n<\/code><\/p>\n<p>For a while I was reluctant to do that, as I was afraid it would erase the array and I had some info on the array that was not backed up, but no danger. In fact I did that after I had removed the failed disk and put in a new one. What I probably should have done, was just a<br \/>\n<code><br \/>\n# mdadm -a \/dev\/hdc1<br \/>\n<\/code><br \/>\nBut the rebuild also did the trick to get back the \/dev\/hdc1 which had not failed, but anyhow was thrown out. But now a <code>mdadm --detail \/dev\/md0<\/code> showed that \/dev\/hdb1 and \/dev\/hdc1 was working well in the array, but disk Number 2 was  missing and my brand new \/dev\/hdd1 was still just a spare, no attempt being done to get it into the array. A lot of googling did not turn up any way to get a spare to be used as an active disk in the array. Probably the array discovers after a while that a disk is missing and a spare is waiting, but to me it seemed as if the example command in the man page on doing several commands in one mdadm might do what I needed, so I did:<br \/>\n<code>mdadm \/dev\/md0 -f \/dev\/hdd1 -r \/dev\/hdd1 -a \/dev\/hdd1<\/code> and got an error message connected to the last -a, after a mdadm \/dev\/md0 -a \/dev\/hdd1 everything looked fine and the array started to sync \/dev\/hdd1 with the rest. <\/p>\n<p>Then the next problem was to find the file system again. After googling and looking around a lot, restarting the md system and lvm system nothing turned up, so I gave in and restarted the machine. \ud83d\ude41 Then, for the first time since the crash, it found all volumes and came up without a hitch.<\/p>\n<p>Looking back, the next time a drive fails, I will do as follows (given \/dev\/hdc1 fails)<br \/>\n<code><br \/>\n# if any \/dev\/hdd1 is taken offline without reason<br \/>\nmdadm \/dev\/md0 -a \/dev\/hdd1<br \/>\nmdadm \/dev\/md0 -r \/dev\/hdc1<\/p>\n<p># Halt machine, remove failed disk set up new disk<br \/>\nmdadm \/dev\/md0 -a \/dev\/hdc1<br \/>\n<\/code><br \/>\nand then, hopefully, the filesystem is still there, else I have to look a bit more in howto resurrect a lvm file system or just reboot the system.<\/p>\n<p>Disclaimer: This worked great for me, no guarantee that it works for anyone else. If the other disk really had been out, I would have lost all data since my last backup&#8230;.<\/p>\n<p>My main sources of information for this was <a href=\"http:\/\/www.gagme.com\/greg\/linux\/raid-lvm.php\">Managing RAID and LVM with Linux (v0.5)<\/a> and the mdadm man page. I was using mdadm &#8211; v2.6.7.1 &#8211; 15th October 2008 and debian&#8217;s kernel  2.6.26-1-686.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It should be simple, but anyhow I was messing around for a while not knowing what to do, but in the end, it was all logical, although not very explicitely documented. <a href=\"https:\/\/sickel.net\/blogg\/?p=283\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[17],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-data","tag-englishposts"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnVtD-4z","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283"}],"version-history":[{"count":11,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":325,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions\/325"}],"wp:attachment":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}