Raid5 on Debian 實作全記錄
收入從建立 Raid device
及日後增加硬碟讓空間更大等實作技巧
首先安裝 raidtools2
[root]# apt-get install raidtools2
[root]# fdisk -l /dev/hdeDisk /dev/hde: 16 heads, 63 sectors, 238216 cylinders
Units = cylinders of 1008 * 512 bytesDevice Boot Start End Blocks Id System
/dev/hde1 1 238216 120060832+ fd Linux raid autodetect
[root]# cp /usr/share/doc/raidtools2/examples/raid5.conf.sample /etc/raidtab
# Sample raid-5 configuration
raiddev /dev/md0
raid-level 5
nr-raid-disks 4
chunk-size 256# Parity placement algorithm
#parity-algorithm left-asymmetric
#
# the best one for maximum performance:
#
parity-algorithm left-symmetric#parity-algorithm right-asymmetric
#parity-algorithm right-symmetric# Spare disks for hot reconstruction
#nr-spare-disks 0device /dev/hde1
raid-disk 0device /dev/hdf1
raid-disk 1device /dev/hdg1
raid-disk 2
[root]# mkraid /dev/md0
[root]# cfdisk /dev/md0
[root]# mke2fs -j -b 4096 -R stride=64 -m 1 /dev/md0
[root]# cat /proc/mdstat
Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 hdg1[2] hdf1[1] hde1[0]
720364995 blocks level 5, 256k chunk, algorithm 2 [4/4] [UUUU]
[>....................] resync = 0.1% (148532/120060736) finish=134.8min speed=11425K/sec
unused devices:
[root]# mount /dev/md0 /mnt
[root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 13G 347M 12G 3% /
/dev/md0 225G 33M 213G 1% /mnt
[root]# cp /etc/raidtab /etc/oldraidtab
[root]# cp /etc/oldraidtab /etc/newraidtab
[root]# /etc/init.d/raid2 stop
Stopping RAID devices: /dev/md0 done.
[root]# vi newraidtab
[root]# raidreconf -o oldraidtab -n newraidtab -m /dev/md0
Working with device /dev/md0
Parsing oldraidtab
Parsing newraidtab
Size of old array: 720364995 blocks, Size of new array: 960486660 blocks
Old raid-disk 0 has 468987 chunks, 120060736 blocks
Old raid-disk 1 has 468987 chunks, 120060736 blocks
Old raid-disk 2 has 468987 chunks, 120060736 blocks
New raid-disk 0 has 468987 chunks, 120060736 blocks
New raid-disk 1 has 468987 chunks, 120060736 blocks
New raid-disk 2 has 468987 chunks, 120060736 blocks
New raid-disk 3 has 468987 chunks, 120060736 blocks
Using 256 Kbyte blocks to move from 256 Kbyte chunks to 256 Kbyte chunks.
Detected 126412 KB of physical memory in system
A maximum of 144 outstanding requests is allowed
---------------------------------------------------
I will grow your old device /dev/md0 of 937974 blocks
to a new device /dev/md0 of 1406961 blocks
using a block-size of 256 KB
Is this what you want? (yes/no): yes
Converting 937974 block device to 1406961 block device
Allocated free block map for 3 disks
4 unique disks detected.
Working (-) [00937974/00937974] [############################################]
Source drained, flushing sink.
Reconfiguration succeeded, will update superblocks...
Updating superblocks...
handling MD device /dev/md0
analyzing super-block
disk 0: /dev/hde1, 120060832kB, raid superblock at 120060736kB
disk 1: /dev/hdf1, 120060832kB, raid superblock at 120060736kB
disk 2: /dev/hdg1, 120060832kB, raid superblock at 120060736kB
disk 3: /dev/hdh1, 120060832kB, raid superblock at 120060736kB
Array is updated with kernel.
Disks re-inserted in array... Hold on while starting the array...
Maximum friend-freeing depth: 4
Total wishes hooked: 937974
Maximum wishes hooked: 144
Total gifts hooked: 937974
Maximum gifts hooked: 107
Congratulations, your array has been reconfigured,
and no errors seem to have occured.
[root]# mount /dev/md0 /backup/
[root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 13G 309M 12G 3% /
/dev/md0 225G 33M 213G 1% /backup
[root]# umount /backup/
[root]# resize2fs /dev/md0
resize2fs 1.27 (8-Mar-2002)
Please run 'e2fsck -f /dev/md0' first.
[root]# e2fsck -f /dev/md0
e2fsck 1.27 (8-Mar-2002)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/md0: 11/30015488 files (9.1% non-contiguous), 950095/60030336 blocks
[root]# resize2fs /dev/md0
resize2fs 1.27 (8-Mar-2002)
The filesystem on /dev/md0 is now 90045504 blocks long.
[root]# mount /dev/md0 /backup/
[root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 13G 309M 12G 3% /
/dev/md0 338G 35M 324G 1% /backup
[root]# cat /proc/mdstat
Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 hdh1[3] hdg1[2] hdf1[1] hde1[0]
360182016 blocks level 5, 256k chunk, algorithm 2 [4/4] [UUUU]
unused devices: