image

– In this example we create RAID 5
– Create 3 partition with equal size

fdisk /dev/sdb
Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 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-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): +1000M

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         123      987966   83  Linux

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

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

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         123      987966   83  Linux
/dev/sdb2             124         246      987997+  83  Linux
/dev/sdb3             247         369      987997+  83  Linux

Command (m for help): t
Partition number (1-4):
1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4):
2
Hex code (type L to list codes):
fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4):
3
Hex code (type L to list codes):
fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         123      987966   fd  Linux raid autodetect
/dev/sdb2             124         246      987997+  fd  Linux raid autodetect
/dev/sdb3             247         369      987997+  fd  Linux raid autodetect

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

Calling ioctl() to re-read partition table.
Syncing disks.
– Create RAID Level
[root@localhost ~]# mdadm –create –verbose /dev/md0 –level=raid5 –raid-device=3 /devsdb1/sdb1 /dev/sdb2 /dev/sdb3
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 64K
mdadm: /dev/sdb1 appears to contain an ext2fs file system
    size=987964K  mtime=Wed Dec 31 16:00:00 1969
mdadm: /dev/sdb2 appears to contain an ext2fs file system
    size=987996K  mtime=Wed Dec 31 16:00:00 1969
mdadm: /dev/sdb3 appears to contain an ext2fs file system
    size=987996K  mtime=Wed Dec 31 16:00:00 1969
mdadm: size set to 987840K
Continue creating array? y
mdadm: array /dev/md0 started.
– Check the process
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb3[3] sdb2[1] sdb1[0]
      1975680 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
      [===========>………]  recovery = 56.4% (558592/987840) finish=0.0min speed=139648K/sec
unused devices: <none>

[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb3[2] sdb2[1] sdb1[0]
      1975680 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
Finally RAID created
– Make FileSystem
[root@localhost ~]# mkfs.ext3 /dev/nmd0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
247296 inodes, 493920 blocks
24696 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=507510784
16 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables:  0/16 1/16 2/16 3/16 4/16 5/16 6/16 7/16 8/16 9/1610/1611/1612/1613/1614/1615/16done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/md0 /data/
[root@localhost ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             3.8G  3.1G  569M  85% /
sysfs                 3.8G  3.8G     0 100% /sys
/dev/sda5             4.0G  139M  3.6G   4% /home
/dev/sda1              46M   11M   33M  25% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /sys
.host:/               196G   31G  165G  16% /mnt/hgfs
/dev/md0              1.9G   35M  1.8G   2% /data
[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         515     4088542+  83  Linux
/dev/sda3             516         776     2096482+  82  Linux swap / Solaris
/dev/sda4             777        1305     4249192+   5  Extended
/dev/sda5             777        1305     4249161   83  Linux

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         123      987966   fd  Linux raid autodetect
/dev/sdb2             124         246      987997+  fd  Linux raid autodetect
/dev/sdb3             247         369      987997+  fd  Linux raid autodetect

Disk /dev/md0: 2023 MB, 2023096320 bytes
2 heads, 4 sectors/track, 493920 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md0 doesn’t contain a valid partition table
– Show details about RAID
[root@localhost data]# mdadm –detail /dev/md0
/dev/md0:
        Version : 0.90
  Creation Time : Thu Feb 12 07:35:24 2015
     Raid Level : raid5
     Array Size : 1975680 (1929.70 MiB 2023.10 MB)
  Used Dev Size : 987840 (964.85 MiB 1011.55 MB)
   Raid Devices : 3
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Thu Feb 12 07:52:32 2015
          State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : d109af5b:41917fcf:3fcace8c:68aead3c
         Events : 0.2

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2
       2       8       19        2      active sync   /dev/sdb3
– Make one faulty Disk
[root@localhost data]# mdadm /dev/md0 -f /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md0
– Show the faulty disk informatiom
[root@localhost data]# mdadm –detail /dev/md0
/dev/md0:
        Version : 0.90
  Creation Time : Thu Feb 12 07:35:24 2015
     Raid Level : raid5
     Array Size : 1975680 (1929.70 MiB 2023.10 MB)
  Used Dev Size : 987840 (964.85 MiB 1011.55 MB)
   Raid Devices : 3
  Total Devices : 3
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Thu Feb 12 08:05:35 2015
          State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : d109af5b:41917fcf:3fcace8c:68aead3c
         Events : 0.10

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       18        1      active sync   /dev/sdb2
       2       8       19        2      active sync   /dev/sdb3

       3       8       17        –      faulty spare   /dev/sdb1
– Hot removed disk
[root@localhost data]# mdadm /dev/md0 -r /dev/sdb1
mdadm: hot removed /dev/sdb1
[root@localhost data]# mdadm –detail /dev/md0
/dev/md0:
        Version : 0.90
  Creation Time : Thu Feb 12 07:35:24 2015
     Raid Level : raid5
     Array Size : 1975680 (1929.70 MiB 2023.10 MB)
  Used Dev Size : 987840 (964.85 MiB 1011.55 MB)
   Raid Devices : 3
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Thu Feb 12 08:05:47 2015
          State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : d109af5b:41917fcf:3fcace8c:68aead3c
         Events : 0.12

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       18        1      active sync   /dev/sdb2
       2       8       19        2      active sync   /dev/sdb3
– Re-added new disk
[root@localhost data]# mdadm /dev/md0 -a /dev/sdb1
mdadm: re-added /dev/sdb1
– Show recovery process
[root@localhost data]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb1[0] sdb3[2] sdb2[1]
      1975680 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]
      [============>……..]  recovery = 61.8% (612224/987840) finish=0.0min speed=153056K/sec
unused devices: <none>
– Show recovery process
[root@localhost data]# cat /proc/mdstat

Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb1[0] sdb3[2] sdb2[1]
      1975680 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]
      [=================>…]  recovery = 87.4% (864256/987840) finish=0.0min speed=172851K/sec
unused devices: <none>
– Show recovery process
[root@localhost data]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb1[0] sdb3[2] sdb2[1]
      1975680 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
– Recovery process done and RAID again live
– To remove RAID volume

[root@localhost ~]# mdadm –stop /dev/md0
mdadm: stopped /dev/md0

Leave a Reply