LINUX Mirror

X4Nt3R1UM

Member
Apr 25, 2003
58
0
0
hi,

how do i make a mirror (software mirror) for my harddisk in my linux PC?, if I will be using another hard disk with the same capacity, what utilities do I need?

any advice will be gladly appeciated.

thanks :)

x4nt3r1um
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Your talking like RAID, right? For reliability....

You can use Linux Software RAID, which is very fast. Supports all sorts of different RAID styles including RAID 5 and even hotswappables and standby drives.

Most of the time you use that in conjunction with LVM for a extra layer of abstraction of your harddrive.

This is so you can have many easily managed partitions or one huge partition. LVM will allow you to spread partitions across disks and even resize partitions on the fly without taking the machine down. Of course you don't ever want to have multiple disk spanning volumes (more poper term for these partitions) without something like RAID 5 supporting it incase one of the disks go out.

Also you don't want to run disks that are RAID'd as master slaves, always master for good performance (buy a extra cheapy IDE to PCI adapter if you need more then 2 PATA drives, they are cheap and you don't need any special features for software RAID)

However on just RAID disk mirroring LVM may not be needed or wanted, but it's nice to be able to resize volumes.... (just a FYI)

However if you just want to mirror a drive for backup purposes and NOT do RAID you can use dd command. The second drive has to be the same size or bigger for that to work. If it's bigger the lost space can be reclaimed by resizing the partitions with something like partition magic or parted.
dd if=/dev/hda of=/dev/hdc

or if you just want the data copied you can go:
mount /dev/hd## /mnt/harddrive1
mount /dev/hd## /mnt/harddrive2
cp --archive /mnt/harddrive1/* /mnt/harddrive2

(hda = primary master, hdb =primary slave, hdc =secondary master, hdd=secondary slave. For the partitions you add the number of the partition to the name of the harddrive. So like the 3rd partition on the secondary master would be: /dev/hdc3)


You don't want to do that while the machine is running off of the harddrive, of course, just while your boot up with a rescue floppy or rescue/live cdrom. Then to finish off replacing the one harddrive with the other you just have to setup the bootloader manually like you do with Gentoo during it's install.

http://www.tldp.org/HOWTO/Software-RAID-HOWTO.html
description of lvm + software raid:
http://www.aplawrence.com/Linux/lvm.html

Quick howto:
http://www.siliconvalleyccie.com/linux-adv/raid.htm
 

X4Nt3R1UM

Member
Apr 25, 2003
58
0
0
thank U, very much...just got what I need :D

and thanks also for the additional info about RAID

x4nt3r1um :)
 

uOpt

Golden Member
Oct 19, 2004
1,628
0
0
Just a few warnings:

Do not copy a filesystem with dd or cstream or something on the plain device unless the filesystem is unmounted or readonly mounted. Never do that on a read/write mounted filesystem.

I use rsync to perform that `cp --archive ...` step above.

There are two ways to set up RAID in Linux: mdadm (one commandline tool for everything) and raidtools (has several tools like startraid, stopraid etc.). The latter turned out to be very bad for me as they didn't properly recover a RAID-5 array automatically. I had to use mdadm to hook a new disk in. People insist that raidstart sucks. Of course, in the case of mdadm, the documentation sucks and the usage is very counterintuitive, so there you go :)

Other than that, software RAID works very well for me on Linux. I stripe over different controller and max out the PCI bus easily in striping. And I can mix striping and RAID-5 on the same set of disks.
 

groovin

Senior member
Jul 24, 2001
857
0
0
anyone know the performance difference between mirroring and raid5? i know raid5 is slower, but for my own home server that just myself and my roomates use, i think i can stand losing a bit of speed for the extra disk space recovered from raid5.
 

uOpt

Golden Member
Oct 19, 2004
1,628
0
0
No, RAID-5 is actually a little faster than just mirroring. There is a small amount of striping involved which leads to both a throughput and seek increase in normal circumstances.

However, RAID-5 takes up more CPU, so you only see better performance in RAID-5 than RAID-1 as long as your have decent CPU power and it isn't taken up by other programs.

My P4 2.8C yawns about the CPU requirements for RAID-5 on three SATA disks, which gives about 60 MB/sec out of the filesystem, but if you put an encryption layer above RAID-5 and then compress and decrompress lots of data within that partition things get a little ugly.

I find no reason not to recommend software RAID-5 on Linux as long as you are aware of that recovery problem with startraid, requiring mdadm that I mentioned above.
 

groovin

Senior member
Jul 24, 2001
857
0
0
thanks for the info. yeah im gonna try it out since i really dont feel like dropping $300 for a 4 port 3ware card. ill give it lots of testing to make sure I know how to do a recovery.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
It'll probably be faster then the 4 port 3ware card, too. Possibly by a long shot.
 

uOpt

Golden Member
Oct 19, 2004
1,628
0
0
I think Linux is actually deprecating hardware RAID controller in the newer kernels.

There was too much bitching around the drivers, it is a problem of the controller telling the OS properly when to exchange a harddrive, with software raid you can always spawn over controllers, buses or even machines, and CPU speed is high enough by now in relation to the snorky PCI bus.

Plus if you use a hardware RAID controller and it breaks, you can usualy only read your data by getting a controller or the same kind. And if your OS drops the driver for the controller...