Tuesday, March 24, 2009

How to set up Raid5 in Ubuntu

How to set up raid5:

Setting up raid5 with 4 drives, 500gb each. Using a SIL hardware sata drive controller, and setting up software raid.

1. update and install package mdadm
apt-get update
apt-get install mdadm

2. Use the 4 devices to create md0
mdadm --create /dev/md0 --level=raid5 --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1

2b. If the array is already started, stop it.
mdadm --stop /dev/md0

3. Assemble the array
root@gamma:~# mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm: /dev/md0 has been started with 3 drives (out of 4) and 1 spare.

Live watch of the array building:
watch cat /proc/mdstat

Wait many hours...

I believe the wait here was about 6 hours.


4. Create the file system:

root@gamma:~# mkfs.ext3 /dev/md0
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
183156736 inodes, 366287952 blocks
18314397 blocks (5.00%) reserved for the super user
First data block=0
11179 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Writing inode tables: 158/11179
...

This command hangs for me, waiting at 158 forever. I even tried doing a kill -9 on the process, with no luck. Even a shutdown -now didn't work, so I had to do a hard boot. Then, I tried the following command:


4b. Try, try again, use mke2fs instead of mkfs.ext3

root@gamma:~# mke2fs /dev/md0
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
183156736 inodes, 366289872 blocks
18314493 blocks (5.00%) reserved for the super user
First data block=0
11179 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848

Writing inode tables: 427/11179
...
and that updated slowly, without hanging.
...

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@gamma:~#

5. use fdisk to create one partition for the whole md0
root@gamma:~# fdisk /dev/md0

Command (m for help): p

Disk /dev/md0: 1500.3 GB, 1500323315712 bytes
2 heads, 4 sectors/track, 366289872 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-366289872, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-366289872, default 366289872):
Using default value 366289872

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
root@gamma:~#


6. Restart the system:
shutdown -r now

7. Create a directory in /mnt
mkdir /mnt/r5

8. Mount the md0 device:
mount /dev/md0 /mnt/r5/

9. Check how much space is available on the drive:

root@gamma:/mnt/r5# df -h /mnt/r5
Filesystem Size Used Avail Use% Mounted on
/dev/md0 1.4T 20K 1.3T 1% /mnt/r5
root@gamma:/mnt/r5#

... and we have 1.4 Terrabytes. All ok.

No comments:

Post a Comment