Difference between revisions of "Mdadm"

From braindump
Jump to navigation Jump to search
Line 33: Line 33:
Add disk
Add disk
# mdadm /dev/md5 --add /dev/loop6
# mdadm /dev/md5 --add /dev/loop6

== Destroy ==
# mdadm --stop /dev/md0
# mdadm --stop /dev/md1
# mdadm --stop /dev/md5
# mdadm --remove /dev/md0
# mdadm --remove /dev/md1
# mdadm --remove /dev/md5


== Config file ==
== Config file ==

Revision as of 15:26, 11 February 2011

Create

Create environment

DISK_DIR=/var/tmp/disks
mkdir -p ${DISK_DIR}
for i in $( seq 1 9 ); do 
    dd if=/dev/zero of=${DISK_DIR}/disk${i} bs=100M count=1
    [ ! -f /dev/loop${i} ] && mknod -m 660 /dev/loop${i} b 7 ${i} 
    losetup /dev/loop${i} ${DISK_DIR}/disk${i}
done

Create raid0 device

# mdadm --create /dev/md0 --level raid0 -n 2 /dev/loop[1-2]

Create raid1 with one spare

# mdadm --create /dev/md1 --level raid1 -n 2 -x 1 /dev/loop[3-5]

Create raid5 with one spare

# mdadm --create /dev/md5 --level raid5 -n 3 -x 1 /dev/loop[6-9]

Check the status

# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0] [raid1]
md5 : active raid5 loop8[2] loop9[3](S) loop7[1] loop6[0]
      204672 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

md0 : active raid0 loop2[1] loop1[0]
      204672 blocks 64k chunks

md1 : active raid1 loop5[2](S) loop4[1] loop3[0]
      102336 blocks [2/2] [UU]

unused devices: <none>

Manage

Fail and remove disk

# mdadm /dev/md5 --fail /dev/loop6 --remove /dev/loop6 

Add disk

# mdadm /dev/md5 --add /dev/loop6

Destroy

# mdadm --stop /dev/md0 
# mdadm --stop /dev/md1
# mdadm --stop /dev/md5
# mdadm --remove /dev/md0 
# mdadm --remove /dev/md1
# mdadm --remove /dev/md5

Config file

# mdadm --detail --scan >> /etc/mdadm.conf 
# cat /etc/mdadm.conf
ARRAY /dev/md1 metadata=0.90 spares=1 UUID=a79ea43f:46f4c907:b40a34a0:8cfeb653
ARRAY /dev/md0 metadata=0.90 UUID=c3d6c5a6:b0d1c032:b40a34a0:8cfeb653
ARRAY /dev/md5 metadata=0.90 spares=1 UUID=b6aeae37:58c17516:b40a34a0:8cfeb653

Sample config file

      DEVICE /dev/sd[bcdjkl]1
      DEVICE /dev/hda1 /dev/hdb1

      # /dev/md0 is known by its UUID.
      ARRAY /dev/md0 UUID=3aaa0122:29827cfa:5331ad66:ca767371
      # /dev/md1 contains all devices with a minor number of
      #   1 in the superblock.
      ARRAY /dev/md1 superminor=1
      # /dev/md2 is made from precisely these two devices
      ARRAY /dev/md2 devices=/dev/hda1,/dev/hdb1

      # /dev/md4 and /dev/md5 are a spare-group and spares
      #  can be moved between them
      ARRAY /dev/md4 uuid=b23f3c6d:aec43a9f:fd65db85:369432df
                 spare-group=group1
      ARRAY /dev/md5 uuid=19464854:03f71b1b:e0df2edd:246cc977
                 spare-group=group1
      # /dev/md/home is created if need to be a partitionable md array
      # any spare device number is allocated.
      ARRAY /dev/md/home UUID=9187a482:5dde19d9:eea3cc4a:d646ab8b
                 auto=part

      MAILADDR root@mydomain.tld
      PROGRAM /usr/sbin/handle-mdadm-events
      CREATE group=system mode=0640 auto=part-8
      HOMEHOST <system>
      AUTO +1.x -all