linux raid device

(create raid (raid1))
# mdadm --create md127 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

(add hotspare to raiddevice)
# mdadm /dev/md127 -a /dev/sdd1

(check raiddevice)
# cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdd1[2](S) sdc1[1] sdb1[0]
1044181 blocks super 1.2 [2/2] [UU]

(create physical volume)
# pvcreate /dev/md/md127

(create volume group)
# vgcreate petervg /dev/md127

(create logical volume)
# lvcreate -L 200m -n plv petervg

(create filesystem)
# mkfs -t ext4 /dev/petervg/plv

(mount)
# mkdir /mnt/plv
mount /dev/petervg/plv /mnt/plv

(put some files in volume)
# cp /boot/init* /mnt/plv

(create snapshot and mount)
# lvcreate -L 200m -s -n plv-snap petervg/plv
#mkdir /mnt/snapplv
# mount -t ext4 /dev/petervg/plv-snap

---

replace failed device.
(create raiddevice (raid1))
# mdadm --create md127 --level=1 --raid-devices 2 /dev/sdb1 /dev/sdc1
(add hotspare)
# mdadm /dev/md127 -a /dev/sdd1
# (view device)
cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdd1[2](S) sdc1[1] sdb1[0]
1044181 blocks super 1.2 [2/2] [UU]

# mdadm --manage /dev/md127 --fail /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md127

# cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdd1[2] sdc1[1] sdb1[0](F)
1044181 blocks super 1.2 [2/2] [UU]

(fail second device)
# mdadm --manage /dev/md127 --fail /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md127

# cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdd1[2] sdc1[1](F) sdb1[0](F)
1044181 blocks super 1.2 [2/1] [U_]

(remove first broken disk and add it back)
# mdadm --manage /dev/md127 --remove /dev/sdb1
mdadm: hot removed /dev/sdb1 from /dev/md127

# mdadm /dev/md127 -a /dev/sdb1
cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdb1[3] sdd1[2] sdc1[1](F)
1044181 blocks super 1.2 [2/1] [U_]
[==============>......] recovery = 70.9% (741824/1044181) finish=0.0min speed=123637K/sec

(remove second failed device)
# mdadm --manage /dev/md127 --remove /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md127

# cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdb1[3] sdd1[2]
1044181 blocks super 1.2 [2/2] [UU]

(add the device again)
# mdadm /dev/md127 -a /dev/sdc1
mdadm: added /dev/sdc1

# cat /proc/mdstat
Personalities : [raid1]
md127 : active raid1 sdc1[4](S) sdb1[3] sdd1[2]
1044181 blocks super 1.2 [2/2] [UU]

-----
(get rid of it all)
# mdadm -S /dev/md127
mdadm: stopped /dev/md127

# mdadm --zero-superblock /dev/sdb1
# mdadm --zero-superblock /dev/sdc1
# mdadm --zero-superblock /dev/sdd1

This entry was posted in linux. Bookmark the permalink.

Comments are closed.