
Setting up your RAID-1 devices.
(C) 1997 Ingo Molnar, Gadi Oxman, Miguel de Icaza.

Send comments and suggestions to:

	linux-raid@vger.rutgers.edu

First of all, make sure you read the INSTALL file for details on how 
to install the userland utilties for managing the Linux/RAID code.

1a. Setting up a 2 way mirrored RAID-1 array:
    (you may setup an n-way mirrored array by just adding more devices
    to the MD device).

a)  Get two partitions of equal size, say /dev/hda1 and /dev/hdb1.

    If they have different sizes, the RAID-1 code won't be able to use
    the difference, but besides wasting that space, there is nothing
    bad with this.  If you have two disks with different sizes, you
    may probably want to partition the bigger one to have one
    partition with the same size as the small disk and use the other
    partition to put other information.

b)  Copy the configuration from raid1.conf.sample into
    /etc/raid1.conf.  Edit the file according to your system.
    
c)  run:

	$ mkraid /etc/raid1.conf

    This creates the RAID-1 superblocks and *ERASES* both paritions.
    Might take a long time for big arrays.

    Be careful, this will *wipe* all the information on your composing
    devices. 

1b. Setting up a software RAID-4/RAID-5:

a)  Get n-partitions of equal size, say /dev/sda1, /dev/sdb1,
    /dev/sdc1, /dev/sdd1.

    If the partitions are of different size, the driver will not be
    able to use the difference in disk space.

b)  Copy the configuration from raid4.conf.sample or raid5.conf.sample
    into /etc/raid4.conf or /etc/raid5.conf.  Edit the file according
    to your setup.

    The configurable things you want to change in this file:

	nr-raid-disks: 	the number of disks in your disk array
                       	(this includes the parity disk).
	
	the device/raid-disk pairs.

2. Creating your MD device:

    run: 

	# mdadd /dev/md0 /dev/hda1 /dev/hdb1

    Those two devices should be the same devices that are specified in
    your raidX.conf file.

3. Activating your MD device:

   Activate your disk array, choose one according to the setup you selected:

	For RAID-1 setups:

	# mdrun -p1 /dev/md0

	For RAID-4 setups:

    	# mdrun -p4 /dev/md0

	For RAID-5 setups:
	
	# mdrun -p5 /dev/md0

    With this instruction you tell the kernel that you want to use the
    /dev/md0 device as a specific RAID personality.

4. Using your MD device:

    Now you can mount /dev/md0 as if it was a normal disk
    partition. You can do:

	# mke2fs /dev/md0
	# mount /dev/md0 /mnt

	[ work, work, work ]

	# umount /mnt

5. Shutting down:

    Before shutdown (but after umount) you should run:

	# mdstop /dev/md0

6. Checking the disk array:

    If mdrun reports that the array couldn't be activated because the
    mirrors were out of sync, you should run:

	For a RAID-1 setup:

	# ckraid /etc/raid1.conf

	For a RAID-4 setup:

	# ckraid /etc/raid4.conf

	For a RAID-5 setup:

	# ckraid /etc/raid5.conf

    This checks your disk array and marks it 'clean'.  It might take
    longer time for big arrays as it has to check every block on the
    mirrors.

7. Mirroring over stripping:

    You might desire to run the mirroring personality on top of the
    stripping personality or the linear personality for various
    reasons: 

    a) too improve the performance of your disk array.  The idea here
       is that you want to have a mirror, but have the speed benefits of the
       stripping personality, or

    b) you want to concatenate some smaller devices as one side of the
       mirror.

       For example: you have two 100meg disks, and one 200meg disk, so
       you concatenate the two 100meg disks with the linear
       personality and then you create a mirror from this new composed
       device and the 200meg disk.

Sample setup mirror over stripping setup:

	(/dev/sda + /dev/sdb) mirrored with (/dev/sdc + /dev/sdd).
  	the '$' is the shell prompt, comments are indented.

$ mdadd /dev/md0 /dev/sda /dev/sdb
	This adds devices /dev/sda and /dev/sdb to /dev/md0

$ mdadd /dev/md1 /dev/sdc /dev/sdd
	This adds devices /dev/sdc and /dev/sdd to /dev/md1

$ mdrun -p0 /dev/md0
	This tells the kernel that you want to use /dev/md0 in
	stripping mode (RAID-0).

$ mdrun -p0 /dev/md1
	This tells the kernel that you want to use /dev/md1 in
	stripping mode (RAID-0).

	Now, create the configuration file for this setup, very
	simple, we just changed the devices to be the md0 and md1
	devices:

$ cat > stripped-raid1.conf << EOF
# Sample raid-1 on top of linear/stripped devices configuration
raiddev                 /dev/md2
raid-level              1
nr-raid-disks           2
nr-spare-disks          0
device                  /dev/md0
raid-disk               0
device                  /dev/md1
raid-disk               1
EOF
$ mkraid stripped-raid1.conf 
	This creates the superblocks on /dev/md0 and /dev/md1 and
	*wipes* the contents of it.  It might take a long time to run.

$ mdadd /dev/md2 /dev/md0 /dev/md1	
	This adds the stripped devices to the mirroring device

$ mdrun -p1 /dev/md2
	Now we actuall tell the kernel to use /dev/md2 as a mirroring
	device.  Note that you can't use stripping over stripping.

Ready!  Now you have a mirror over stripping device in /dev/md2

At shutdown time, don't forget to mdstop your devices:

$ mdstop /dev/md2
	This stops the mirroring personality

$ mdstop /dev/md0
	This stops the first stripping component

$ mdstop /dev/md1
	This stops the second stripping component

