Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disk Mirroring in Linux 3

Status
Not open for further replies.

samirm

Technical User
May 12, 2003
80
US
Hi,

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.

TIA

Sam
 
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.

OK?

D.E.R. Management - IT Project Management Consulting
 
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
 
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.
 
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. ==--
 
Brilliant. I didn't know you could create a degraded array.
 
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*?
Reboot?

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.

D.E.R. Management - IT Project Management Consulting
 
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.
 
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.
 
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]
 
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. ==--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top