Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Disk Mirroring in Linux

Disk Mirroring in Linux

Disk Mirroring in Linux


I am new to Linux environment. I have a Linux server which is acting as a sendmail server of the Company. I want to make my disk mirrored. I don't have any idea how to do that. If someone can share the steps to be followed for the mirroring would be wonderful.



RE: Disk Mirroring in Linux

Disk mirroring is more appropriately called RAID 1

RAID itself can be implemented using hardware- or software-based solutions.  Hardware would require the installation of a specific, compatible disk controller card.  Software would require specific support available in the kernel and managed during the install of the server.

In either case you'll require at least two disks of same type and similar geometry (i.e. two SATA, >100GB).

Generally the RedHat/Centos/Fedora install process has a disk partitioning "druid/agent/wizard" as part of the install process to support combining to physical disks into a suitable software based RAID 1 virtual disk.

Generally any hardware based solution has a BIOS boot-up keystroke that you would toggle to enter the setup screen(s) for that card's RAID configuration support.


D.E.R. Management - IT Project Management Consulting

RE: Disk Mirroring in Linux

A couple more points:

Any software RAID/mirroring solution utilizes the processor(s) on the computer itself to perform the "math" and overhead that supports the mirroring function.  Depending upon the hardware, utilization, etc. this can have little to a significant effect on perceived performance of the machine.

Conversely, MOST hardware based RAID1 solutions use processing power on the dedicated card to reduce/eliminate any impact upon the main CPUs to support RAID.

Finally, it is possible to add either hw or sw raid to an existing server.  I do not believe, however, that it's particularly easy to convert an existing single disk system into a software RAID system - but someone can correct me there.

D.E.R. Management - IT Project Management Consulting

RE: Disk Mirroring in Linux

I've set up software raid on one of my computers, and the partition type is different. Normal linux partitions are type 83, and raid partitions are type fd. You can't really change the partition type on an existing table without losing data on your disk (to my knowledge.)

You'd need to get 2 identical drives, partition them accordingly, and compile in the relevant pieces in the kernel. After this is done and it is formatted and mounted, then you can copy everything onto the drive.

RE: Disk Mirroring in Linux

I've added a RAID1 to my system before without loosing data. Create a RAID1 device with a missing disk.

mdadm -C /dev/md0 --force --level=1 --raid-devices=2 /dev/xxx missing

Where xxx is your new drive. This will create a degraded raid1 device that can be mounted and data from an existing drive copied to it. Partition your old drive and add it into your raid1 array. The array should start to rebuild after a few minutes.

Do remember to rename the device in your /etc/fstab.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--

RE: Disk Mirroring in Linux

I stand corrected.

RE: Disk Mirroring in Linux

Brilliant. I didn't know you could create a degraded array.

RE: Disk Mirroring in Linux

zeland can you provide a stepwise plan for reboots and changes to the fstab?

As in:
After you create the phantom RAID1 (degraded),
Then you modify fstab by
- removing/renaming the partitions to be md* from hd*?

I've never seen this done either, so I'm trying to soak it in...  I assume a reboot is required under circumstances where the primary drive is being mirrored.

Finally, is it permissible to work on/use the new RAID1 when it comes back immediately from reboot?  Or will the first reboot require some time to sync the mirrors before the user is permitted use of the console?

Thanks!  Cool!

D.E.R. Management - IT Project Management Consulting

RE: Disk Mirroring in Linux

I recall when I set mine up, mdadm actually creates a degraded array to force it to rebuild itself. However, I wasn't aware that it could be possible to copy files to it (I was using raid5, however, so building it took forever.)

I would still like to have a backup of my data before trying it, though.

RE: Disk Mirroring in Linux

Gah, sorry for the double post.

I just thought that after creating the array with a missing drive, you could mount /dev/md0, and copy files to it. Then repartition the old drive to type fd, and use mdadm to add the new device to it so it rebuilds.

Not sure if that's exactly how it would work though.

I do recall that my raid5 was available while it was building.

RE: Disk Mirroring in Linux

To be able to boot from the md device you would need to rebuild your kernel with the raid1 modules built-in, not as (un)loadable modules.  When the kernel (or dm_mod and raid1 modules) is loaded it will detect the md array and assemble it for use.  Assembling the array at boot can only be accomplished without initrd support in the kernel.

You might be able to accomplish similar using a third disk to house your /etc, /boot and /lib (there might be others...) so your kernel can load the modules to assemble the array at boot and continue with the init process.  The kernel can't find the modules to load if the md device is not available.

And don't forget to install grub on each disk (if using raid 1).

If you don't need to boot from the md device then you can disregard this.

Have Fun afro2

RE: Disk Mirroring in Linux

Lets make a point-form tutorial that others may use.

A: If you are trying to mirror a data drive. Assumption, existing data drive is /dev/sdb and new drive is /dev/sdc.
1. Make sure your kernel had RAID support and both md_mod & raid1 modules are loadable.
2. With fdisk, create a new partition of type fd on your new drive.
3. Initialize a degraded RAID1 array: mdadm -C /dev/md0 --force --level=1 --raid-devices=2 /dev/sdc1 missing.
4. Create a filesystem on /dev/md0: mkfs -t ext3 /dev/md0.
5. At this point, /dev/md0 is fully usable. Mount /dev/md0 and copy the contents of /dev/sdb to /dev/md0.
6. Unmount /dev/sdb and mount /dev/md0 in /dev/sdb mount point.
7. With fdisk, repartition /dev/sdb with a partition of type fd.
8. Add /dev/sdb1 to your existing RAID1 array: mdadm /dev/md0 --add /dev/sdb1. *I encountered a problem with adding the old drive to the array this morning if I didn't create a filesystem on it first. I don't recall doing this the last time.
9. Array will now start to rebuild. Use mdadm -D /dev/md0 to check its rebuild status.
10. Edit your /etc/fstab file and edit all references of /dev/sdb to /dev/md0.
* No reboot is required.
** It may be possible "upgrade" to a RAID5 in future by breaking your RAID1 and pairing the "broken" (/dev/sdd?) drive to another new drive (/dev/sde?) to form a degraded RAID5 and copying the data from /dev/md0. Finally adding /dev/sdc back into your new RAID5 array to rebuild.

B: If you are trying to mirror an OS drive. Assumption, OS drive is /dev/sda and new drive is /dev/sdb
1. Repeat steps A1 to A5.
2. Repeat step A10.
3. Install grub on /dev/sdb to make it bootable. Run: grub-install /dev/sdb. (I may be wrong here!)
5. Shutdown your system and swap your drives.
6. Power up your system and repeat step A8.
* This method was my first attempt to create a RAID1 array on an existing system with data with only 2 drives! It was trial and error trying really hard to loose any data. My memory is a bit vague about that attempt. Method A was a second attempt which proved successful.

--== Anything can go wrong. It's just a matter of how far wrong it will go till people think its right. ==--

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close