{"id":913,"date":"2009-12-04T06:36:12","date_gmt":"2009-12-04T11:36:12","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=913"},"modified":"2009-12-04T06:36:12","modified_gmt":"2009-12-04T11:36:12","slug":"mdadm-cheat-sheet","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/","title":{"rendered":"Mdadm Cheat Sheet"},"content":{"rendered":"<p>Mdadm Cheat Sheet<\/p>\n<p>Mdadm is the modern tool most Linux distributions use these days to manage software RAID arrays; in the past raidtools was the tool we have used for this. This cheat sheet will show the most common usages of mdadm to manage software raid arrays; it assumes you have a good understanding of software RAID and Linux in general, and it will just explain the commands line usage of mdadm. The examples bellow use RAID1, but they can be adapted for any RAID level the Linux kernel driver supports.<br \/>\n1. Create a new RAID array<\/p>\n<p>Create (mdadm \u2013create) is used to create a new array:<br \/>\nmdadm &#8211;create &#8211;verbose \/dev\/md0 &#8211;level=1 \/dev\/sda1 \/dev\/sdb2<br \/>\nor using the compact notation:<br \/>\nmdadm -Cv \/dev\/md0 -l1 -n2 \/dev\/sd[ab]1<br \/>\n2. \/etc\/mdadm.conf<\/p>\n<p>\/etc\/mdadm.conf or \/etc\/mdadm\/mdadm.conf (on debian) is the main configuration file for mdadm. After we create our RAID arrays we add them to this file using:<br \/>\nmdadm &#8211;detail &#8211;scan >> \/etc\/mdadm.conf<br \/>\nor on debian<br \/>\nmdadm &#8211;detail &#8211;scan >> \/etc\/mdadm\/mdadm.conf<br \/>\n3. Remove a disk from an array<\/p>\n<p>We can\u2019t remove a disk directly from the array, unless it is failed, so we first have to fail it (if the drive it is failed this is normally already in failed state and this step is not needed):<br \/>\nmdadm &#8211;fail \/dev\/md0 \/dev\/sda1<br \/>\nand now we can remove it:<br \/>\nmdadm &#8211;remove \/dev\/md0 \/dev\/sda1<\/p>\n<p>This can be done in a single step using:<br \/>\nmdadm \/dev\/md0 &#8211;fail \/dev\/sda1 &#8211;remove \/dev\/sda1<br \/>\n4. Add a disk to an existing array<\/p>\n<p>We can add a new disk to an array (replacing a failed one probably):<br \/>\nmdadm &#8211;add \/dev\/md0 \/dev\/sdb1<br \/>\n5. Verifying the status of the RAID arrays<\/p>\n<p>We can check the status of the arrays on the system with:<br \/>\ncat \/proc\/mdstat<br \/>\nor<br \/>\nmdadm &#8211;detail \/dev\/md0<\/p>\n<p>The output of this command will look like:<\/p>\n<p>cat \/proc\/mdstat<br \/>\nPersonalities : [raid1]<br \/>\nmd0 : active raid1 sdb1[1] sda1[0]<br \/>\n104320 blocks [2\/2] [UU]<\/p>\n<p>md1 : active raid1 sdb3[1] sda3[0]<br \/>\n19542976 blocks [2\/2] [UU]<\/p>\n<p>md2 : active raid1 sdb4[1] sda4[0]<br \/>\n223504192 blocks [2\/2] [UU]<\/p>\n<p>here we can see both drives are used and working fine \u2013 U. A failed drive will show as F, while a degraded array will miss the second disk &#8211;<\/p>\n<p>Note: while monitoring the status of a RAID rebuild operation using watch can be useful:<br \/>\nwatch cat \/proc\/mdstat<br \/>\n6. Stop and delete a RAID array<\/p>\n<p>If we want to completely remove a raid array we have to stop if first and then remove it:<br \/>\nmdadm &#8211;stop \/dev\/md0<br \/>\nmdadm &#8211;remove \/dev\/md0<br \/>\nand finally we can even delete the superblock from the individual drives:<br \/>\nmdadm &#8211;zero-superblock \/dev\/sda<\/p>\n<p>Finally in using RAID1 arrays, where we create identical partitions on both drives this can be useful to copy the partitions from sda to sdb:<br \/>\nsfdisk -d \/dev\/sda | sfdisk \/dev\/sdb<\/p>\n<p>(this will dump the partition table of sda, removing completely the existing partitions on sdb, so be sure you want this before running this command, as it will not warn you at all).<\/p>\n<p>There are many other usages of mdadm particular for each type of RAID level, and I would recommend to use the manual page (man mdadm) or the help (mdadm \u2013help) if you need more details on its usage. Hopefully these quick examples will put you on the fast track with how mdadm works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mdadm Cheat Sheet Mdadm is the modern tool most Linux distributions use these days to manage software RAID arrays; in the past raidtools was the tool we have used for this. This cheat sheet will show the most common usages of mdadm to manage software raid arrays; it assumes you have a good understanding of&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-913","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Mdadm Cheat Sheet - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mdadm Cheat Sheet - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"Mdadm Cheat Sheet Mdadm is the modern tool most Linux distributions use these days to manage software RAID arrays; in the past raidtools was the tool we have used for this. This cheat sheet will show the most common usages of mdadm to manage software raid arrays; it assumes you have a good understanding of... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2009-12-04T11:36:12+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Mdadm Cheat Sheet\",\"datePublished\":\"2009-12-04T11:36:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/\"},\"wordCount\":567,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/\",\"name\":\"Mdadm Cheat Sheet - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2009-12-04T11:36:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/mdadm-cheat-sheet\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mdadm Cheat Sheet\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mdadm Cheat Sheet - Linux Shtuff","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/","og_locale":"en_US","og_type":"article","og_title":"Mdadm Cheat Sheet - Linux Shtuff","og_description":"Mdadm Cheat Sheet Mdadm is the modern tool most Linux distributions use these days to manage software RAID arrays; in the past raidtools was the tool we have used for this. This cheat sheet will show the most common usages of mdadm to manage software raid arrays; it assumes you have a good understanding of... Read More","og_url":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2009-12-04T11:36:12+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Mdadm Cheat Sheet","datePublished":"2009-12-04T11:36:12+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/"},"wordCount":567,"commentCount":0,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/","url":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/","name":"Mdadm Cheat Sheet - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2009-12-04T11:36:12+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/mdadm-cheat-sheet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Mdadm Cheat Sheet"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=913"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/913\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}