{"id":327,"date":"2019-04-17T18:44:52","date_gmt":"2019-04-17T18:44:52","guid":{"rendered":"https:\/\/unsrewiki.1sys1.com\/?p=327"},"modified":"2022-05-20T16:46:57","modified_gmt":"2022-05-20T16:46:57","slug":"rebuild-software-raid-linux","status":"publish","type":"post","link":"https:\/\/server-help.org\/index.php\/2019\/04\/17\/rebuild-software-raid-linux\/","title":{"rendered":"Rebuild Software RAID (Linux)"},"content":{"rendered":"\n<p>This guide will walk you though how to Rebuild a Software RAID  after replacing the defective hard disk. <\/p>\n\n\n\n<p>After replacing the defective hard disk, you need to check the RAID status<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># cat \/proc\/mdstat\nPersonalities : &#91;linear] &#91;raid0] &#91;raid1] &#91;raid10] &#91;raid6] &#91;raid5] &#91;raid4] &#91;faulty]\nmd1 : active raid1 sdb1&#91;1]\n      4194240 blocks &#91;2\/1] &#91;_U]\n\nmd3 : active raid1 sdb3&#91;1]\n      970470016 blocks &#91;2\/1] &#91;_U]\n\nunused devices: &lt;none&gt;<\/code><\/pre>\n\n\n\n<p>The above output shows that the First Drive (sda) is not exists. By checking fdisk -l, we will notice that SDA has no partition table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># fdisk -l\nDisk \/dev\/ram0: 896 MiB, 939524096 bytes, 1835008 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 4096 bytes\nI\/O size (minimum\/optimal): 4096 bytes \/ 4096 bytes\n\n\nDisk \/dev\/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: dos\nDisk identifier: 0x76a7d556\n\n\nDisk \/dev\/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: dos\nDisk identifier: 0x76a7d556\n\nDevice     Boot    Start        End    Sectors   Size Id Type\n\/dev\/sdb1           2048    8390655    8388608     4G fd Linux raid autodetect\n\/dev\/sdb2        8390656   12584959    4194304     2G 82 Linux swap \/ Solaris\n\/dev\/sdb3       12584960 1953525167 1940940208 925.5G fd Linux raid autodetect\n\n\nDisk \/dev\/md3: 925.5 GiB, 993761296384 bytes, 1940940032 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/md1: 4 GiB, 4294901760 bytes, 8388480 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/mapper\/vg00-usr: 5 GiB, 5368709120 bytes, 10485760 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/mapper\/vg00-var: 5 GiB, 5368709120 bytes, 10485760 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/mapper\/vg00-home: 5 GiB, 5368709120 bytes, 10485760 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/code><\/pre>\n\n\n\n<p> In the first step, copy the partition tables manually from the second to the first hard disk. This is done with this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># sfdisk -d \/dev\/sdb | sfdisk \/dev\/sda<\/code><\/pre>\n\n\n\n<p>After running sfdisk check to make sure that your exact partition layout has been duplicated on the new disk.<\/p>\n\n\n\n<p>If it hasn&#8217;t, this means that the original drive is using GPT and therefore sfdisk will not work.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@host ~]# fdisk -l\nWARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.\n\nDisk \/dev\/sdb: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk label type: gpt\nDisk identifier: 74D5FA4C-6B00-4A51-B72B-A017907EBABE\n\n\n#         Start          End    Size  Type            Name\n 1         2048         6143      2M  BIOS boot       primary\n 2         6144      3905535    1.9G  Linux RAID      primary\n 3      3905536     11718655    3.7G  Linux swap      primary\n 4     11718656   3907026943    1.8T  Linux RAID      primary<\/code><\/pre>\n\n\n\n<p>You will now need to delete the new broken partition you made before proceeding:<\/p>\n\n\n\n<p>Then we will instead use sgdisk.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sgdisk \/dev\/sdb -R \/dev\/sda\nsgdisk -G \/dev\/sda<\/code><\/pre>\n\n\n\n<p>If the sgdisk command isn&#8217;t available you will first need to install gdisk.<\/p>\n\n\n\n<p>After that you can check with <strong>fdisk -l<\/strong> if the first hard disk is now as divided as the second one. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># fdisk -l\nDisk \/dev\/ram0: 896 MiB, 939524096 bytes, 1835008 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 4096 bytes\nI\/O size (minimum\/optimal): 4096 bytes \/ 4096 bytes\n\n\nDisk \/dev\/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: dos\nDisk identifier: 0x76a7d556\n\nDevice     Boot    Start        End    Sectors   Size Id Type\n\/dev\/sda1           2048    8390655    8388608     4G fd Linux raid autodetect\n\/dev\/sda2        8390656   12584959    4194304     2G 82 Linux swap \/ Solaris\n\/dev\/sda3       12584960 1953525167 1940940208 925.5G fd Linux raid autodetect\n\n\nDisk \/dev\/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisklabel type: dos\nDisk identifier: 0x76a7d556\n\nDevice     Boot    Start        End    Sectors   Size Id Type\n\/dev\/sdb1           2048    8390655    8388608     4G fd Linux raid autodetect\n\/dev\/sdb2        8390656   12584959    4194304     2G 82 Linux swap \/ Solaris\n\/dev\/sdb3       12584960 1953525167 1940940208 925.5G fd Linux raid autodetect\n\n\nDisk \/dev\/md3: 925.5 GiB, 993761296384 bytes, 1940940032 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/md1: 4 GiB, 4294901760 bytes, 8388480 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/mapper\/vg00-usr: 5 GiB, 5368709120 bytes, 10485760 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/mapper\/vg00-var: 5 GiB, 5368709120 bytes, 10485760 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\n\n\nDisk \/dev\/mapper\/vg00-home: 5 GiB, 5368709120 bytes, 10485760 sectors\nUnits: sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes<\/code><\/pre>\n\n\n\n<p>After restoring the partitioning,  activate the swap partition using the following commands: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># mkswap \/dev\/sda2\n# swapon -p 1 \/dev\/sda2<\/code><\/pre>\n\n\n\n<p>*Note* <\/p>\n\n\n\n<p>If your disk was using GPT your swap partition is likely \/dev\/sda3 instead.<\/p>\n\n\n\n<p>Please reference fdisk -l output to confirm.<\/p>\n\n\n\n<p>Now, we can start building the RAID:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># mdadm --manage \/dev\/md1 --add \/dev\/sda1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># mdadm --manage \/dev\/md3 --add \/dev\/sda3<\/code><\/pre>\n\n\n\n<p>If your partition layout was GPT, then you will be rebuilding md2 and md4 instead<\/p>\n\n\n\n<p>We can now use <strong>cat \/proc\/mdstat<\/strong> to track the rebuild of the RAID.  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/proc\/mdstat\nPersonalities : &#91;linear] &#91;raid0] &#91;raid1] &#91;raid10] &#91;raid6] &#91;raid5] &#91;raid4] &#91;faulty]\nmd1 : active raid1 sda1&#91;0] sdb1&#91;1]\n      4194240 blocks &#91;2\/2] &#91;UU]\n\nmd3 : active raid1 sda3&#91;2] sdb3&#91;1]\n      970470016 blocks &#91;2\/1] &#91;_U]\n      &#91;========&gt;............]  recovery = 40.2% (390393152\/970470016) finish=67.9min speed=142233K\/sec\n\nunused devices: &lt;none&gt;\n<\/code><\/pre>\n\n\n\n<p>GPT Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@host ~]# cat \/proc\/mdstat \nPersonalities : &#91;raid1] \nmd2 : active raid1 sda2&#91;2] sdb2&#91;0] \u00a0 \u00a0 \u00a0 \n1949632 blocks super 1.0 &#91;2\/2] &#91;UU] \n\n\nmd4 : active raid1 sda4&#91;2] sdb4&#91;0] \u00a0 \u00a0 \u00a0 \n1947653952 blocks super 1.0 &#91;2\/1] &#91;U_] \u00a0 \u00a0 \u00a0 \n&#91;>....................] \u00a0recovery = \u00a00.3% (7050752\/1947653952) finish=658.0min speed=49147K\/sec\nunused devices: &lt;none><\/code><\/pre>\n\n\n\n<p>Now, after the RAID has been rebuilt, we need to build grub. First we need to mount everything:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># mount \/dev\/md1 \/mnt\n# mount \/dev\/mapper\/vg00-var \/mnt\/var\n# mount \/dev\/mapper\/vg00-usr \/mnt\/usr\n# mount \/dev\/mapper\/vg00-home \/mnt\/home\n# mount --bind \/dev \/mnt\/dev\n# mount --bind \/dev\/pts \/mnt\/dev\/pts\n# mount --bind \/proc \/mnt\/proc\n# mount --bind \/sys \/mnt\/sys <\/code><\/pre>\n\n\n\n<p>Then chroot \/mnt director<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># chroot \/mnt<\/code><\/pre>\n\n\n\n<p>Building grub:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># grub-install \/dev\/sda\n# grub-install \/dev\/sdb<\/code><\/pre>\n\n\n\n<p>Or, Building grub2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># grub2-mkconfig\n# grub2-install \/dev\/sda\n# grub2-install \/dev\/sdb\n# grubby --update-kernel=ALL --args=rd.auto=1<\/code><\/pre>\n\n\n\n<p>Exit Chroot with <strong>Exit<\/strong> and unmount all disks: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># exit\n# umount -a<\/code><\/pre>\n\n\n\n<p>Finally, the RAID has been rebuilt<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide will walk you though how to Rebuild a Software RAID after replacing the defective hard disk. After replacing the defective hard disk, you need to check the RAID status The above output shows that the First Drive (sda) is not exists. By checking fdisk -l, we will notice that SDA has no partition&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[],"_links":{"self":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/327"}],"collection":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":6,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":862,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/posts\/327\/revisions\/862"}],"wp:attachment":[{"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server-help.org\/index.php\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}