How to re-create RAID1 really properly

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












System:

Laptop with Linux Mint 17.3, 1x SSD for system and 2x HDD intended for RAID1 using mdadm.



Situation:

Without knowing how to create RAID1 properly, I created it badly.



  • GParted showed a warning that a primary gpt partition table is not there, and that it is using the backup one, I think it showed this twice


  • GParted showed the partition on both HDDs contained ext4 filesystem, instead of linux-raid filesystem


  • GParted did not show the raid flag on neither HDDs


  • Reboot caused the array not to work, I mean not only it did not mount automatically, it could not be mounted without stopping the array and re-assembling it


  • There were probably other things I did not notice like I don't know if the array, I mean the mirroring, even worked properly










share|improve this question



























    up vote
    0
    down vote

    favorite












    System:

    Laptop with Linux Mint 17.3, 1x SSD for system and 2x HDD intended for RAID1 using mdadm.



    Situation:

    Without knowing how to create RAID1 properly, I created it badly.



    • GParted showed a warning that a primary gpt partition table is not there, and that it is using the backup one, I think it showed this twice


    • GParted showed the partition on both HDDs contained ext4 filesystem, instead of linux-raid filesystem


    • GParted did not show the raid flag on neither HDDs


    • Reboot caused the array not to work, I mean not only it did not mount automatically, it could not be mounted without stopping the array and re-assembling it


    • There were probably other things I did not notice like I don't know if the array, I mean the mirroring, even worked properly










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      System:

      Laptop with Linux Mint 17.3, 1x SSD for system and 2x HDD intended for RAID1 using mdadm.



      Situation:

      Without knowing how to create RAID1 properly, I created it badly.



      • GParted showed a warning that a primary gpt partition table is not there, and that it is using the backup one, I think it showed this twice


      • GParted showed the partition on both HDDs contained ext4 filesystem, instead of linux-raid filesystem


      • GParted did not show the raid flag on neither HDDs


      • Reboot caused the array not to work, I mean not only it did not mount automatically, it could not be mounted without stopping the array and re-assembling it


      • There were probably other things I did not notice like I don't know if the array, I mean the mirroring, even worked properly










      share|improve this question















      System:

      Laptop with Linux Mint 17.3, 1x SSD for system and 2x HDD intended for RAID1 using mdadm.



      Situation:

      Without knowing how to create RAID1 properly, I created it badly.



      • GParted showed a warning that a primary gpt partition table is not there, and that it is using the backup one, I think it showed this twice


      • GParted showed the partition on both HDDs contained ext4 filesystem, instead of linux-raid filesystem


      • GParted did not show the raid flag on neither HDDs


      • Reboot caused the array not to work, I mean not only it did not mount automatically, it could not be mounted without stopping the array and re-assembling it


      • There were probably other things I did not notice like I don't know if the array, I mean the mirroring, even worked properly







      linux-mint partition mdadm software-raid gpt






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 30 at 8:40

























      asked Jun 10 '16 at 11:57









      Vlastimil

      7,2021153129




      7,2021153129




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          In this answer, let it be clear that all of your data will be destroyed on both of the array members (drives), so back it up first!




          Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):



          sudo -i



          Check what number (mdX) the array has:



          cat /proc/mdstat


          Suppose it is md0 and it is mounted on /mnt/raid1, first we have to unmount and stop the array:



          umount /mnt/raid1
          mdadm --stop /dev/md0


          We need to erase the super-block on both drives, suppose sda and sdb:



          mdadm --zero-superblock /dev/sda1
          mdadm --zero-superblock /dev/sdb1



          Let's get to work; we should erase the drives, if there were any data and filesystems before, that is. Suppose we have 2 members: sda, sdb:



          pv < /dev/zero > /dev/sda
          pv < /dev/zero > /dev/sdb


          If you were to skip the previous step for your reasons, you need to wipe all filesystems on both of the drives. Then check if there is nothing left behind, you may peek with GParted on both of the drives, and if there is any filesystem other than unknown, wipe it.



          First, we wipe all existing partitions, suppose sda contains 3 partitions, then:



          wipefs --all /dev/sda3
          wipefs --all /dev/sda2
          wipefs --all /dev/sda1


          Use this on both of the drives and do all partitions there are.



          Then, we wipe the partition scheme with:



          wipefs --all /dev/sda
          wipefs --all /dev/sdb



          Then, we initialize both drives with GUID partition table (GPT):



          gdisk /dev/sda
          gdisk /dev/sdb


          In both cases use the following:



          o Enter for new empty GUID partition table (GPT)
          y Enter to confirm your decision
          w Enter to write changes
          y Enter to confirm your decision



          Now, we need to partition both of the drives, but don't do this with GParted, because it would create a filesystem in the process, which we don't want, use gdisk again:



          gdisk /dev/sda
          gdisk /dev/sdb


          In both cases use the following:
          n Enter for new partition
          Enter for first partition
          Enter for default of the first sector
          Enter for default of the last sector
          fd00 Enter for Linux RAID type
          w Enter to write changes
          y Enter to confirm your decision




          To triple-check if there is nothing left behind, you may peek with GParted on both of the newly created partitions, and if they contain any filesystem other than unknown, wipe it:



          wipefs --all /dev/sda1
          wipefs --all /dev/sdb1



          You can examine the drives now:



          mdadm --examine /dev/sda /dev/sdb


          It should say:




          (type ee)



          If it does, we now examine the partitions:



          mdadm --examine /dev/sda1 /dev/sdb1


          It should say:




          No md superblock detected




          If it does, we can create the RAID1 array:



          mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1


          We shall wait until the array is fully created, this process we may watch with:



          watch -n 1 cat /proc/mdstat


          After creation of the array, we should look at its detail:



          mdadm --detail /dev/md0


          It should say:




           State : clean
          Active Devices : 2
          Working Devices : 2
          Failed Devices : 0
          Spare Devices : 0




          Now we create filesystem on the array, if you use ext4, this is better to be avoided, because of ext4lazyinit would take noticeable amount of time, hence the name, "lazyinit", therefore I recommend you to avoid this one:




          mkfs.ext4 /dev/md0




          Instead, you should force a full instant initialization with:



          mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/md0


          By specifying these options, the inodes and the journal will be initialized immediately during creation, useful for larger arrays.



          If you chose to take a shortcut and created the ext4 filesystem with the "better avoided command", note that ext4lazyinit will take noticeable amount of time to initialize all of the inodes, you may watch it until it is done, e.g. with:



          iotop


          Either way you choose to make the file system initialization, you should mount it after it has finished its initialization.




          We now create some directory for this RAID1 array:



          mkdir --parents /mnt/raid1


          And simply mount it:



          mount /dev/md0 /mnt/raid1


          Since we are essentially done, we may use GParted again to quickly check if it shows linux-raid filesystem, together with the raid flag on both of the drives.



          If it does, we properly created the RAID1 array with GPT partitions and can now copy files on it.




          See what UUID the md0 filesystem has:



          blkid /dev/md0


          Copy the UUID to clipboard.



          Now we need to edit fstab, with your favorite text editor:



          nano /etc/fstab


          And add add an entry to it:



          UUID=<the UUID you have in the clipboard> /mnt/raid1 ext4 defaults 0 0


          You may check if it is correct, after you save the changes:



          mount --all --verbose | grep raid1


          It should say:




          already mounted




          If it does, we save the array configuration; in case you don't have any md device yet created, you can simply do:



          mdadm --detail --scan >> /etc/mdadm/mdadm.conf


          In case there are arrays already existent, just run the previous command without redirection to the conf file:



          mdadm --detail --scan


          and add the new array to the mdadm.conf file manually.




          In the end, don't forget to update your initramfs:



          update-initramfs -u


          Check if you did everything according to plan, and if so, you may restart:



          reboot --reboot





          share|improve this answer





























            up vote
            0
            down vote













            Perfect and exactly what I needed!



            Thanks!






            share|improve this answer








            New contributor




            Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

















            • Thank you for feedback.
              – Vlastimil
              1 hour ago










            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f288947%2fhow-to-re-create-raid1-really-properly%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            In this answer, let it be clear that all of your data will be destroyed on both of the array members (drives), so back it up first!




            Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):



            sudo -i



            Check what number (mdX) the array has:



            cat /proc/mdstat


            Suppose it is md0 and it is mounted on /mnt/raid1, first we have to unmount and stop the array:



            umount /mnt/raid1
            mdadm --stop /dev/md0


            We need to erase the super-block on both drives, suppose sda and sdb:



            mdadm --zero-superblock /dev/sda1
            mdadm --zero-superblock /dev/sdb1



            Let's get to work; we should erase the drives, if there were any data and filesystems before, that is. Suppose we have 2 members: sda, sdb:



            pv < /dev/zero > /dev/sda
            pv < /dev/zero > /dev/sdb


            If you were to skip the previous step for your reasons, you need to wipe all filesystems on both of the drives. Then check if there is nothing left behind, you may peek with GParted on both of the drives, and if there is any filesystem other than unknown, wipe it.



            First, we wipe all existing partitions, suppose sda contains 3 partitions, then:



            wipefs --all /dev/sda3
            wipefs --all /dev/sda2
            wipefs --all /dev/sda1


            Use this on both of the drives and do all partitions there are.



            Then, we wipe the partition scheme with:



            wipefs --all /dev/sda
            wipefs --all /dev/sdb



            Then, we initialize both drives with GUID partition table (GPT):



            gdisk /dev/sda
            gdisk /dev/sdb


            In both cases use the following:



            o Enter for new empty GUID partition table (GPT)
            y Enter to confirm your decision
            w Enter to write changes
            y Enter to confirm your decision



            Now, we need to partition both of the drives, but don't do this with GParted, because it would create a filesystem in the process, which we don't want, use gdisk again:



            gdisk /dev/sda
            gdisk /dev/sdb


            In both cases use the following:
            n Enter for new partition
            Enter for first partition
            Enter for default of the first sector
            Enter for default of the last sector
            fd00 Enter for Linux RAID type
            w Enter to write changes
            y Enter to confirm your decision




            To triple-check if there is nothing left behind, you may peek with GParted on both of the newly created partitions, and if they contain any filesystem other than unknown, wipe it:



            wipefs --all /dev/sda1
            wipefs --all /dev/sdb1



            You can examine the drives now:



            mdadm --examine /dev/sda /dev/sdb


            It should say:




            (type ee)



            If it does, we now examine the partitions:



            mdadm --examine /dev/sda1 /dev/sdb1


            It should say:




            No md superblock detected




            If it does, we can create the RAID1 array:



            mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1


            We shall wait until the array is fully created, this process we may watch with:



            watch -n 1 cat /proc/mdstat


            After creation of the array, we should look at its detail:



            mdadm --detail /dev/md0


            It should say:




             State : clean
            Active Devices : 2
            Working Devices : 2
            Failed Devices : 0
            Spare Devices : 0




            Now we create filesystem on the array, if you use ext4, this is better to be avoided, because of ext4lazyinit would take noticeable amount of time, hence the name, "lazyinit", therefore I recommend you to avoid this one:




            mkfs.ext4 /dev/md0




            Instead, you should force a full instant initialization with:



            mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/md0


            By specifying these options, the inodes and the journal will be initialized immediately during creation, useful for larger arrays.



            If you chose to take a shortcut and created the ext4 filesystem with the "better avoided command", note that ext4lazyinit will take noticeable amount of time to initialize all of the inodes, you may watch it until it is done, e.g. with:



            iotop


            Either way you choose to make the file system initialization, you should mount it after it has finished its initialization.




            We now create some directory for this RAID1 array:



            mkdir --parents /mnt/raid1


            And simply mount it:



            mount /dev/md0 /mnt/raid1


            Since we are essentially done, we may use GParted again to quickly check if it shows linux-raid filesystem, together with the raid flag on both of the drives.



            If it does, we properly created the RAID1 array with GPT partitions and can now copy files on it.




            See what UUID the md0 filesystem has:



            blkid /dev/md0


            Copy the UUID to clipboard.



            Now we need to edit fstab, with your favorite text editor:



            nano /etc/fstab


            And add add an entry to it:



            UUID=<the UUID you have in the clipboard> /mnt/raid1 ext4 defaults 0 0


            You may check if it is correct, after you save the changes:



            mount --all --verbose | grep raid1


            It should say:




            already mounted




            If it does, we save the array configuration; in case you don't have any md device yet created, you can simply do:



            mdadm --detail --scan >> /etc/mdadm/mdadm.conf


            In case there are arrays already existent, just run the previous command without redirection to the conf file:



            mdadm --detail --scan


            and add the new array to the mdadm.conf file manually.




            In the end, don't forget to update your initramfs:



            update-initramfs -u


            Check if you did everything according to plan, and if so, you may restart:



            reboot --reboot





            share|improve this answer


























              up vote
              2
              down vote



              accepted










              In this answer, let it be clear that all of your data will be destroyed on both of the array members (drives), so back it up first!




              Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):



              sudo -i



              Check what number (mdX) the array has:



              cat /proc/mdstat


              Suppose it is md0 and it is mounted on /mnt/raid1, first we have to unmount and stop the array:



              umount /mnt/raid1
              mdadm --stop /dev/md0


              We need to erase the super-block on both drives, suppose sda and sdb:



              mdadm --zero-superblock /dev/sda1
              mdadm --zero-superblock /dev/sdb1



              Let's get to work; we should erase the drives, if there were any data and filesystems before, that is. Suppose we have 2 members: sda, sdb:



              pv < /dev/zero > /dev/sda
              pv < /dev/zero > /dev/sdb


              If you were to skip the previous step for your reasons, you need to wipe all filesystems on both of the drives. Then check if there is nothing left behind, you may peek with GParted on both of the drives, and if there is any filesystem other than unknown, wipe it.



              First, we wipe all existing partitions, suppose sda contains 3 partitions, then:



              wipefs --all /dev/sda3
              wipefs --all /dev/sda2
              wipefs --all /dev/sda1


              Use this on both of the drives and do all partitions there are.



              Then, we wipe the partition scheme with:



              wipefs --all /dev/sda
              wipefs --all /dev/sdb



              Then, we initialize both drives with GUID partition table (GPT):



              gdisk /dev/sda
              gdisk /dev/sdb


              In both cases use the following:



              o Enter for new empty GUID partition table (GPT)
              y Enter to confirm your decision
              w Enter to write changes
              y Enter to confirm your decision



              Now, we need to partition both of the drives, but don't do this with GParted, because it would create a filesystem in the process, which we don't want, use gdisk again:



              gdisk /dev/sda
              gdisk /dev/sdb


              In both cases use the following:
              n Enter for new partition
              Enter for first partition
              Enter for default of the first sector
              Enter for default of the last sector
              fd00 Enter for Linux RAID type
              w Enter to write changes
              y Enter to confirm your decision




              To triple-check if there is nothing left behind, you may peek with GParted on both of the newly created partitions, and if they contain any filesystem other than unknown, wipe it:



              wipefs --all /dev/sda1
              wipefs --all /dev/sdb1



              You can examine the drives now:



              mdadm --examine /dev/sda /dev/sdb


              It should say:




              (type ee)



              If it does, we now examine the partitions:



              mdadm --examine /dev/sda1 /dev/sdb1


              It should say:




              No md superblock detected




              If it does, we can create the RAID1 array:



              mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1


              We shall wait until the array is fully created, this process we may watch with:



              watch -n 1 cat /proc/mdstat


              After creation of the array, we should look at its detail:



              mdadm --detail /dev/md0


              It should say:




               State : clean
              Active Devices : 2
              Working Devices : 2
              Failed Devices : 0
              Spare Devices : 0




              Now we create filesystem on the array, if you use ext4, this is better to be avoided, because of ext4lazyinit would take noticeable amount of time, hence the name, "lazyinit", therefore I recommend you to avoid this one:




              mkfs.ext4 /dev/md0




              Instead, you should force a full instant initialization with:



              mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/md0


              By specifying these options, the inodes and the journal will be initialized immediately during creation, useful for larger arrays.



              If you chose to take a shortcut and created the ext4 filesystem with the "better avoided command", note that ext4lazyinit will take noticeable amount of time to initialize all of the inodes, you may watch it until it is done, e.g. with:



              iotop


              Either way you choose to make the file system initialization, you should mount it after it has finished its initialization.




              We now create some directory for this RAID1 array:



              mkdir --parents /mnt/raid1


              And simply mount it:



              mount /dev/md0 /mnt/raid1


              Since we are essentially done, we may use GParted again to quickly check if it shows linux-raid filesystem, together with the raid flag on both of the drives.



              If it does, we properly created the RAID1 array with GPT partitions and can now copy files on it.




              See what UUID the md0 filesystem has:



              blkid /dev/md0


              Copy the UUID to clipboard.



              Now we need to edit fstab, with your favorite text editor:



              nano /etc/fstab


              And add add an entry to it:



              UUID=<the UUID you have in the clipboard> /mnt/raid1 ext4 defaults 0 0


              You may check if it is correct, after you save the changes:



              mount --all --verbose | grep raid1


              It should say:




              already mounted




              If it does, we save the array configuration; in case you don't have any md device yet created, you can simply do:



              mdadm --detail --scan >> /etc/mdadm/mdadm.conf


              In case there are arrays already existent, just run the previous command without redirection to the conf file:



              mdadm --detail --scan


              and add the new array to the mdadm.conf file manually.




              In the end, don't forget to update your initramfs:



              update-initramfs -u


              Check if you did everything according to plan, and if so, you may restart:



              reboot --reboot





              share|improve this answer
























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                In this answer, let it be clear that all of your data will be destroyed on both of the array members (drives), so back it up first!




                Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):



                sudo -i



                Check what number (mdX) the array has:



                cat /proc/mdstat


                Suppose it is md0 and it is mounted on /mnt/raid1, first we have to unmount and stop the array:



                umount /mnt/raid1
                mdadm --stop /dev/md0


                We need to erase the super-block on both drives, suppose sda and sdb:



                mdadm --zero-superblock /dev/sda1
                mdadm --zero-superblock /dev/sdb1



                Let's get to work; we should erase the drives, if there were any data and filesystems before, that is. Suppose we have 2 members: sda, sdb:



                pv < /dev/zero > /dev/sda
                pv < /dev/zero > /dev/sdb


                If you were to skip the previous step for your reasons, you need to wipe all filesystems on both of the drives. Then check if there is nothing left behind, you may peek with GParted on both of the drives, and if there is any filesystem other than unknown, wipe it.



                First, we wipe all existing partitions, suppose sda contains 3 partitions, then:



                wipefs --all /dev/sda3
                wipefs --all /dev/sda2
                wipefs --all /dev/sda1


                Use this on both of the drives and do all partitions there are.



                Then, we wipe the partition scheme with:



                wipefs --all /dev/sda
                wipefs --all /dev/sdb



                Then, we initialize both drives with GUID partition table (GPT):



                gdisk /dev/sda
                gdisk /dev/sdb


                In both cases use the following:



                o Enter for new empty GUID partition table (GPT)
                y Enter to confirm your decision
                w Enter to write changes
                y Enter to confirm your decision



                Now, we need to partition both of the drives, but don't do this with GParted, because it would create a filesystem in the process, which we don't want, use gdisk again:



                gdisk /dev/sda
                gdisk /dev/sdb


                In both cases use the following:
                n Enter for new partition
                Enter for first partition
                Enter for default of the first sector
                Enter for default of the last sector
                fd00 Enter for Linux RAID type
                w Enter to write changes
                y Enter to confirm your decision




                To triple-check if there is nothing left behind, you may peek with GParted on both of the newly created partitions, and if they contain any filesystem other than unknown, wipe it:



                wipefs --all /dev/sda1
                wipefs --all /dev/sdb1



                You can examine the drives now:



                mdadm --examine /dev/sda /dev/sdb


                It should say:




                (type ee)



                If it does, we now examine the partitions:



                mdadm --examine /dev/sda1 /dev/sdb1


                It should say:




                No md superblock detected




                If it does, we can create the RAID1 array:



                mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1


                We shall wait until the array is fully created, this process we may watch with:



                watch -n 1 cat /proc/mdstat


                After creation of the array, we should look at its detail:



                mdadm --detail /dev/md0


                It should say:




                 State : clean
                Active Devices : 2
                Working Devices : 2
                Failed Devices : 0
                Spare Devices : 0




                Now we create filesystem on the array, if you use ext4, this is better to be avoided, because of ext4lazyinit would take noticeable amount of time, hence the name, "lazyinit", therefore I recommend you to avoid this one:




                mkfs.ext4 /dev/md0




                Instead, you should force a full instant initialization with:



                mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/md0


                By specifying these options, the inodes and the journal will be initialized immediately during creation, useful for larger arrays.



                If you chose to take a shortcut and created the ext4 filesystem with the "better avoided command", note that ext4lazyinit will take noticeable amount of time to initialize all of the inodes, you may watch it until it is done, e.g. with:



                iotop


                Either way you choose to make the file system initialization, you should mount it after it has finished its initialization.




                We now create some directory for this RAID1 array:



                mkdir --parents /mnt/raid1


                And simply mount it:



                mount /dev/md0 /mnt/raid1


                Since we are essentially done, we may use GParted again to quickly check if it shows linux-raid filesystem, together with the raid flag on both of the drives.



                If it does, we properly created the RAID1 array with GPT partitions and can now copy files on it.




                See what UUID the md0 filesystem has:



                blkid /dev/md0


                Copy the UUID to clipboard.



                Now we need to edit fstab, with your favorite text editor:



                nano /etc/fstab


                And add add an entry to it:



                UUID=<the UUID you have in the clipboard> /mnt/raid1 ext4 defaults 0 0


                You may check if it is correct, after you save the changes:



                mount --all --verbose | grep raid1


                It should say:




                already mounted




                If it does, we save the array configuration; in case you don't have any md device yet created, you can simply do:



                mdadm --detail --scan >> /etc/mdadm/mdadm.conf


                In case there are arrays already existent, just run the previous command without redirection to the conf file:



                mdadm --detail --scan


                and add the new array to the mdadm.conf file manually.




                In the end, don't forget to update your initramfs:



                update-initramfs -u


                Check if you did everything according to plan, and if so, you may restart:



                reboot --reboot





                share|improve this answer














                In this answer, let it be clear that all of your data will be destroyed on both of the array members (drives), so back it up first!




                Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options):



                sudo -i



                Check what number (mdX) the array has:



                cat /proc/mdstat


                Suppose it is md0 and it is mounted on /mnt/raid1, first we have to unmount and stop the array:



                umount /mnt/raid1
                mdadm --stop /dev/md0


                We need to erase the super-block on both drives, suppose sda and sdb:



                mdadm --zero-superblock /dev/sda1
                mdadm --zero-superblock /dev/sdb1



                Let's get to work; we should erase the drives, if there were any data and filesystems before, that is. Suppose we have 2 members: sda, sdb:



                pv < /dev/zero > /dev/sda
                pv < /dev/zero > /dev/sdb


                If you were to skip the previous step for your reasons, you need to wipe all filesystems on both of the drives. Then check if there is nothing left behind, you may peek with GParted on both of the drives, and if there is any filesystem other than unknown, wipe it.



                First, we wipe all existing partitions, suppose sda contains 3 partitions, then:



                wipefs --all /dev/sda3
                wipefs --all /dev/sda2
                wipefs --all /dev/sda1


                Use this on both of the drives and do all partitions there are.



                Then, we wipe the partition scheme with:



                wipefs --all /dev/sda
                wipefs --all /dev/sdb



                Then, we initialize both drives with GUID partition table (GPT):



                gdisk /dev/sda
                gdisk /dev/sdb


                In both cases use the following:



                o Enter for new empty GUID partition table (GPT)
                y Enter to confirm your decision
                w Enter to write changes
                y Enter to confirm your decision



                Now, we need to partition both of the drives, but don't do this with GParted, because it would create a filesystem in the process, which we don't want, use gdisk again:



                gdisk /dev/sda
                gdisk /dev/sdb


                In both cases use the following:
                n Enter for new partition
                Enter for first partition
                Enter for default of the first sector
                Enter for default of the last sector
                fd00 Enter for Linux RAID type
                w Enter to write changes
                y Enter to confirm your decision




                To triple-check if there is nothing left behind, you may peek with GParted on both of the newly created partitions, and if they contain any filesystem other than unknown, wipe it:



                wipefs --all /dev/sda1
                wipefs --all /dev/sdb1



                You can examine the drives now:



                mdadm --examine /dev/sda /dev/sdb


                It should say:




                (type ee)



                If it does, we now examine the partitions:



                mdadm --examine /dev/sda1 /dev/sdb1


                It should say:




                No md superblock detected




                If it does, we can create the RAID1 array:



                mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1


                We shall wait until the array is fully created, this process we may watch with:



                watch -n 1 cat /proc/mdstat


                After creation of the array, we should look at its detail:



                mdadm --detail /dev/md0


                It should say:




                 State : clean
                Active Devices : 2
                Working Devices : 2
                Failed Devices : 0
                Spare Devices : 0




                Now we create filesystem on the array, if you use ext4, this is better to be avoided, because of ext4lazyinit would take noticeable amount of time, hence the name, "lazyinit", therefore I recommend you to avoid this one:




                mkfs.ext4 /dev/md0




                Instead, you should force a full instant initialization with:



                mkfs.ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/md0


                By specifying these options, the inodes and the journal will be initialized immediately during creation, useful for larger arrays.



                If you chose to take a shortcut and created the ext4 filesystem with the "better avoided command", note that ext4lazyinit will take noticeable amount of time to initialize all of the inodes, you may watch it until it is done, e.g. with:



                iotop


                Either way you choose to make the file system initialization, you should mount it after it has finished its initialization.




                We now create some directory for this RAID1 array:



                mkdir --parents /mnt/raid1


                And simply mount it:



                mount /dev/md0 /mnt/raid1


                Since we are essentially done, we may use GParted again to quickly check if it shows linux-raid filesystem, together with the raid flag on both of the drives.



                If it does, we properly created the RAID1 array with GPT partitions and can now copy files on it.




                See what UUID the md0 filesystem has:



                blkid /dev/md0


                Copy the UUID to clipboard.



                Now we need to edit fstab, with your favorite text editor:



                nano /etc/fstab


                And add add an entry to it:



                UUID=<the UUID you have in the clipboard> /mnt/raid1 ext4 defaults 0 0


                You may check if it is correct, after you save the changes:



                mount --all --verbose | grep raid1


                It should say:




                already mounted




                If it does, we save the array configuration; in case you don't have any md device yet created, you can simply do:



                mdadm --detail --scan >> /etc/mdadm/mdadm.conf


                In case there are arrays already existent, just run the previous command without redirection to the conf file:



                mdadm --detail --scan


                and add the new array to the mdadm.conf file manually.




                In the end, don't forget to update your initramfs:



                update-initramfs -u


                Check if you did everything according to plan, and if so, you may restart:



                reboot --reboot






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 30 at 9:51

























                answered Jun 10 '16 at 11:57









                Vlastimil

                7,2021153129




                7,2021153129






















                    up vote
                    0
                    down vote













                    Perfect and exactly what I needed!



                    Thanks!






                    share|improve this answer








                    New contributor




                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.

















                    • Thank you for feedback.
                      – Vlastimil
                      1 hour ago














                    up vote
                    0
                    down vote













                    Perfect and exactly what I needed!



                    Thanks!






                    share|improve this answer








                    New contributor




                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.

















                    • Thank you for feedback.
                      – Vlastimil
                      1 hour ago












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Perfect and exactly what I needed!



                    Thanks!






                    share|improve this answer








                    New contributor




                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    Perfect and exactly what I needed!



                    Thanks!







                    share|improve this answer








                    New contributor




                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer






                    New contributor




                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 1 hour ago









                    Hardliner

                    11




                    11




                    New contributor




                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    Hardliner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.











                    • Thank you for feedback.
                      – Vlastimil
                      1 hour ago
















                    • Thank you for feedback.
                      – Vlastimil
                      1 hour ago















                    Thank you for feedback.
                    – Vlastimil
                    1 hour ago




                    Thank you for feedback.
                    – Vlastimil
                    1 hour ago

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f288947%2fhow-to-re-create-raid1-really-properly%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?