Announcement

Collapse
No announcement yet.

Trying to implement RAID 1 [using mdadm] from an existing hard drive

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Trying to implement RAID 1 [using mdadm] from an existing hard drive

    I am trying to start using RAID 1 on my home computer in order to back my data up a little more effectively. Right now, the computer has a 1 TB hard drive [the current, working hard drive] in that has been partitioned and formatted ext. I recently picked up another hard drive, and I have it installed, but I haven't partitioned it yet. I know that to get RAID working, these mirrored partitions need to be the same size. I thought that I knew what my hard drive partition sizes were on the original drive, but when I set up the partitions on the new drive [using gparted] the partition sizes look different.

    I am wondering if there is a better way to make sure that my partitions are the same size? Once this is done, then I will move on to mdadm questions. Thanks.

    #2
    Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

    A little more info would be helpful: Start with your current partition setup and then detail what you want to do with your new drive space.

    If your drives are identical and you want an exact copy of partition tables you can simply copy one partition table to the other. If they are similar but not identical, you might want another approach.

    Please Read Me

    Comment


      #3
      Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

      Thanks.

      I have 2 x 1 TB hard drives. Right now /dev/sda is my primary drive and sdb is my secondary. The hard drives are identical in size and are actually the same manufacturer and model.

      Can you tell me more about copying the partition table?

      Comment


        #4
        Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

        OT, but I've gotta do my public service announcement for today

        RAID is not a backup solution. I've seen a server corrupt an entire RAID5 array by writing garbage to the array and in that case the data was not recoverable because more than one disk was corrupted and RAID5 won't tolerate a failure in more than one disk. The server admin came real close to becoming unemployed because he thought he could run a RAID array without backing the server up.

        Kudos to spaceballs for thinking about backing his data up, but IMO you'd probably be better off using rsync or tar to archive the data to an independent spindle.

        That said, we now return you to our regularly scheduled discussion already in progress.

        we see things not as they are, but as we are.
        -- anais nin

        Comment


          #5
          Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

          Lol, wiz - but maybe saying RAID5 is not a good substitute for a backup would have been a bit more on point. Of course, in the situation you mentioned, even RAID1 wouldn't have saved the day and a server doing automated backups could also write trash to the backup, so could drive controller failure, et. al. IMO: At some point you have to stop planning for failure or you'll never have time for anything else. Continuing the topic: RAID in general increases your chance of data lose due to the increased likelihood of a device failure, the actual odds increase depends on your setup.

          Point being: There's NO substitute for a good backup and always backup anything you can't afford to lose!

          Now back to the OP's topic:

          To duplicate exactly your partition table:

          Your Master Boot Record contains 512 bytes, the first 446 of which are boot record and the remaining are partition table (there's a couple of space holder bytes, but not really important for this exercise).

          To copy the entire mbr from one disk to another, open a terminal and type:

          dd if=/dev/sda of=/dev/sdb count=1 bs=512


          This will also duplicate your boot code but that won't hurt anything unless you've installed something to that drive already.

          If you want to copy just the partition table without the boot code:

          dd if=/dev/sda of=/dev/sdb bs=1 count=64 skip=446 seek=446


          Another variation would be to make a backup file of your MBR. To do this the command(s) are the same as above - substituting a file name for the device name where appropriate i.e.:

          dd if=/dev/sda of=/path/file.name count=1 bs=512


          to copy and

          dd if=/path/file.name of=/dev/sdb count=1 bs=512


          to restore.

          I've always done this with new drives. You'll want to reformat all the partitions on the new drive after you do the partition table copy.

          On to RAID1 as a backup (see how nicely these posts are tying together? ). I don't know how experienced you are at this, but you have a ton of drive space. Assuming 16gb for an install you could lay RAID1 on top of RAID0 for better performance or use RAID0 and have a backup (see previous post, lol) or several other setups.

          Post back with what you're goals are and if you like, I can make some suggestions.

          Please Read Me

          Comment


            #6
            Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

            My goal is to have everything backed up on a second hard drive. I am a computational scientist, and I work with some pretty large arrays - meaning, for me, 1 TB isn't all that large. But this is for my home computer, where 1 TB will be enough.

            I think that 1 TB mirrored will be ideal. I want something easy to implement and to maintain, and I think a straight RAID1 setup will do it. I did consider, at one point, getting three 500GB drives and running a RAID5 setup, but my tower isn't all that big and RAID1 seems to be more reliable.

            My data is also tarred and backed up about once a month onto another external drive, and all of my important projects are backed up onto a CVS repository somewhere offsite. I know a little bit about backup, but not all of the ins and outs...yet.

            When I copy, or backup, the MBR, should I include the boot information? After we sort this out, then I will start to ask the questions about the actual RAID setup. Like, what to do about swap, etc.

            Thanks for your help oshunluvr.





            Comment


              #7
              Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

              I have seen some other posts about using ddrescue to back up the drive. Should I do this before setting it up with mdadm? Or should I just set up mdadm?

              Comment


                #8
                Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                Originally posted by spaceballs
                ...
                When I copy, or backup, the MBR, should I include the boot information? ...
                Yes, and save the MBR and info on at least two USB memory sticks. You never know when one of them will fail as well.
                "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                – John F. Kennedy, February 26, 1962.

                Comment


                  #9
                  Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                  Originally posted by GreyGeek
                  Yes, and save the MBR and info on at least two USB memory sticks. You never know when one of them will fail as well.
                  Done. Can someone help me with the mdadm setup? Should I set up swap on both drives?

                  When it comes to swap, I think that I would rather have the swap partitions set up in a RAID0 configuration [for performance] and then have the rest of it mirrored. Is this possible?

                  Comment


                    #10
                    Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                    I can't help you because I've never set up raid on a storage device. Here is some help, though:

                    https://help.ubuntu.com/community/In...n/SoftwareRAID

                    and Ubuntu's Advanced Installation advice:
                    https://help.ubuntu.com/10.04/server...tallation.html

                    And what do you know, there is even a graphic mdadm utility:
                    http://www.bgevolution.com/blog/ubun...-raid-utility/
                    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                    – John F. Kennedy, February 26, 1962.

                    Comment


                      #11
                      Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                      Creating the arrays is real simple but you should read up on booting to a RAID1 array.

                      You could avoid booting into RAID1 (as I do) by using a dedicated boot partition since this area hardly ever changes outside the RAID1 array and use a cron job to back it up. This boot partition files are less than 100mb so it backs up quickly.
                      Also you can leave /tmp and swap outside the array since they do not need to be backed up at all.

                      Here's one way to do this (Adjust space as you see fit) :

                      part1 swap 1-2gb
                      part2 /boot 200mb
                      part3 /tmp 10gb
                      part4 - extended
                      part5 / 16gb
                      part6 /home all remaining space

                      Duplicate this partition table onto drive 2. Install as normal to your first drive. Boot into your new install. Create two RAID1 devices using part5 and part6 from both drives and one RAID0 device from part3's. No need to RAID your swap as linux will treat them this way anyway (give both swap partitions equal priority in fstab) Edit your /etc/fstab file to reflect the new RAID device UUID's and reboot. Copy the contents of /boot to your second drive. Done. I have to go to work but I'll post the steps to create the RAID devices if you want me to - it's really easy.

                      Please Read Me

                      Comment


                        #12
                        Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                        Originally posted by oshunluvr
                        but I'll post the steps to create the RAID devices if you want me to - it's really easy.
                        Thanks. I would really appreciate that.

                        Since I already have a working installation on one drive, I am worried that I will end up blanking out my working HD by somehow backing up my new, blank partition.

                        I think that I will set up a cron rsync job on the /boot directories.

                        Right now the disk is set up like:

                        2GB /dev/sda1 is /boot
                        30GB /dev/sda2 is swap
                        250GB /dev/sda3 is /
                        everything else on /dev/sda4 is /home

                        The partitions on the 2nd drive should be identical, but with sdb* in place of sda*. And I guess it looks like / and /home will be the only things I will be really be RAIDing. If you could help throw me in the right direction, I would really appreciate it.

                        Comment


                          #13
                          Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                          On partition sizes:
                          IMO: you have way too much space for / and /tmp can be smaller unless you're really doing a ton of large file processing. 20gb is more than enough for a linux install especially since you have /tmp and /home separate. Additionally, swap space is used when you overload RAM or to hibernate to disk (not usually done in the desktop environment) therefore the recommended amount is usually equal to your RAM size. Lastly, /boot will never exceed 200mb unless you go literally a dozen years without removing old kernels.

                          I suspect your partition sizes are guided by windows experience - which is a very common early linux users mistake. My totally loaded kubuntu install with thousands of packages is less than 10gb.

                          I suggest this; download and burn a Gparted bootable CD and resize and rearrange your partitions closer to what I suggested. If you leave sda1 as is and change it to swap, add a new sda2 for /boot of 400mb, resize sda3 to about 20gb for /, then expand /home to use the remaining space. At this time it might be a good idea to make your /home partition a logical partition (sda5) within sda4 (as an extended partition) in case you decided to add an additional partition later on. Then you can also create a 10gb partition for /tmp as /dev/sda6. In case you don't know it: hard drives can hold only 4 primary partitions, one of which may be an extended partition that can then hold up to 63 logical partitions. If you forge ahead without an extended partition, you're locked into a 4 partition limit.

                          However - all this (your partition sizes and such) is totally your decision and I'll respect whatever you choose. (If you haven't installed yet, download and use the Alternate install CD and it will offer the options to create the RAID devices for you during install)

                          The creation of raid devices uses mdadm so install that package and it's dependencies. To create a RAID1 device and not lose your current data you simply create the array with a missing device and then add the additional device later.

                          I'll assume the following:

                          You have partitioned drive "a" as you desire
                          You have installed kubuntu and have it set up and partitioned the way you wish all on drive "a"
                          You have duplicated your drive "a" partition table onto drive "b" but otherwise it is empty

                          You will now create two RAID1 devices and (optional) one RAID0 device. All commands in bold are issued in a terminal unless otherwise noted. You may use whatever device name you choose for your newly created RAID devices but I usually opt for one that reminds me of the devices used to create it - i.e. using /dev/sda5 and /dev/sdb5 as array members I would name the RAID device /dev/md5.

                          Assuming / is installed to /dev/sda3, /home is installed to /dev/sda5, and /tmp is installed to /dev/sda6:
                          sudo mdadm --create /dev/md3 --level=1 --raid-devices=2 /dev/sda3 missing
                          sudo mdadm --create /dev/md5 --level=1 --raid-devices=2 /dev/sda5 missing
                          sudo mdadm --create /dev/md6 --level=0 --raid-devices=2 /dev/sda6 /dev/sdb6


                          You now have two degraded RAID1 devices and one functioning RAID0 device. This command will show you the status of your new raid devices:

                          cat /proc/mdstat


                          The output will look something like:
                          Code:
                          Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
                          md3 : active raid1 sda3[0]
                             16771264 blocks [2/1] [U_]
                          
                          md5 : active raid1 sda5[0]
                             16771264 blocks [2/1] [U_]
                          
                          md6 : active raid0 sda10[0] sdd10[1]
                             16771328 blocks 64k chunks
                          Now add the missing devices in:
                          sudo mdadm /dev/md3 -a /dev/sdb3
                          sudo mdadm /dev/md5 -a /dev/sda5

                          and cat /proc/mdstat will show
                          Code:
                          md3 : active raid1 sda2[2] sdb2[1]
                               72192 blocks [2/1] [_U]
                               [====>................] recovery = 23.9% (18112/72192) finish=0.1min speed=6037K/sec
                            [...]
                          It may take quite awhile for the RAID1's to finish copying everything. Check back periodically with the above command until the "recovery" is complete before you continue.

                          Then create a config file:
                          sudo mdadm --detail --scan>>/etc/mdadm/mdadm.conf

                          Next step is to add the new devices to /etc/fstab so you can use them. You can see your new UUID's using the above command without the file re-direct:
                          sudo mdadm --detail --scan
                          and output looks like:
                          Code:
                          ARRAY /dev/md3 level=raid1 num-devices=2 metadata=00.90 UUID=4c4e228a:55102195:85a67013:1b2194de
                          ARRAY /dev/md5 level=raid1 num-devices=2 metadata=00.90 UUID=b97e3a56:f05815cc:85a67013:1b2194de
                          ARRAY /dev/md6 level=raid0 num-devices=2 metadata=00.90 UUID=608f504a:651f6154:577442e6:f4e07f49
                          Now edit your /etc/fstab and change the UUID's in there to match the new RAID devices.

                          Final steps are to add your second swap to /etc/fstab, set the swap priorities equal and format your second /boot partition to prepare it for the copying. Reboot and you should be good to go. I probably forgot something so keep a bootable liveCD handy so you can get back on line and get it fixed

                          Please Read Me

                          Comment


                            #14
                            Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                            Originally posted by oshunluvr
                            Assuming / is installed to /dev/sda3, /home is installed to /dev/sda5, and /tmp is installed to /dev/sda6:
                            sudo mdadm --create /dev/md3 --level=1 --raid-devices=2 /dev/sda3 missing
                            sudo mdadm --create /dev/md5 --level=1 --raid-devices=2 /dev/sda5 missing
                            I tried to run these, and I get an error that the device [/dev/sda3] is busy. Should I be able to do these steps with my drives presently mounted? Or should I boot onto a CD and then build these RAID arrays?

                            I see that some folks have this problem even with the drives NOT mounted.

                            Thank you for your time and incredibly detailed response.

                            Comment


                              #15
                              Re: Trying to implement RAID 1 [using mdadm] from an existing hard drive

                              Sorry - yeah you can't do it to a mounted partition. Either a liveCD or create a 8 gb partition and install there - then do your RAID creation.

                              Please Read Me

                              Comment

                              Working...
                              X