A bash script that collects some useful commands to check Linux MD software arrays and component devices for some issues, e.g.
- RAID component device has a SMART warnings or errors.
- A RAID with HDD and SSD mixed doesn't have the HDD components set to write-mostly or the SSD is set to write-mostly.
It can also display info. Set env var SHOW_INFO='y'
or anything else, e.g. 'n'
(default) to just report issues.
Needs to run with root privileges.
Only errors:
sudo bash -c "SHOW_INFO='n' ./inspect_raid.sh"
Info and errors:
sudo bash -c "SHOW_INFO='y' ./inspect_raid.sh"
When mixing SSD and HDD in a RAID1 array, it's likely benificial for the SSD to perform the read operations while HDD devices are probably better left set in write-mostly mode and won't slow down reads.
A rarer exception would be a very large RAID1 (why?) that had a lot of HDD devices, only one SSD device, and a sequential IO worklaod. The assumptions are that:
- SSD is >= 2x faster at sequential read (500MB/s vs 200MB/s)
- SSD is >= 100x faster at random read (~20000 IOPs vs 200 IOPs for 4K random read)
Another exception might be a non-rotational device like a flash memory card or USB flash device on a slow interface where read speeds can be slow (e.g. 30MB/s sequential read and only 2000 4K random read IOPS). Again, the assumption is that mixing USB flash or micro SD with an HDD in RAID1 is a far out edge case.
A RAID1 device used for root was built with 1x SSD and 4x HDD with HDD set to writemostly
. Usually, if ROTA
(rotational), that should correlate to writemostly
if mixed with SSD.
INFO: # Inspecting virtual block raid device 'md127'
/dev/md127:
Version : 1.2
Creation Time : Tue Feb 21 18:01:21 2017
Raid Level : raid1
Array Size : 17809408 (16.98 GiB 18.24 GB)
Used Dev Size : 17809408 (16.98 GiB 18.24 GB)
Raid Devices : 5
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Mon Jan 7 10:33:53 2019
State : clean
Active Devices : 5
Working Devices : 5
Failed Devices : 0
Spare Devices : 0
Name : biscuit:os_raid1_hybrid (local to host biscuit)
UUID : 8602fd17:d885d3ac:c490e8da:8c56cbbf
Events : 553
Number Major Minor RaidDevice State
0 8 19 0 active sync /dev/sdb3
6 8 35 1 active sync writemostly /dev/sdc3
2 8 51 2 active sync writemostly /dev/sdd3
7 8 67 3 active sync writemostly /dev/sde3
5 8 83 4 active sync writemostly /dev/sdf3
INFO: ## Inspecting 5 members for raid device 'md127'
NAME TYPE ROTA SCHED RQ-SIZE TRAN SIZE VENDOR MODEL SERIAL
md127 raid1 1 128 17G
├─sdf3 part 1 cfq 128 17G
│ └─sdf disk 1 cfq 128 sata 3.7T ATA ST4000VN008-2 ZDH11XD0
├─sde3 part 1 cfq 128 17G
│ └─sde disk 1 cfq 128 sata 2.7T ATA ST3000DM001-1 W1F3LWTP
├─sdd3 part 1 cfq 128 17G
│ └─sdd disk 1 cfq 128 sata 2.7T ATA ST3000DM001-9 S1F0J0T2
├─sdc3 part 1 cfq 128 17G
│ └─sdc disk 1 cfq 128 sata 3.7T ATA ST4000VN008-2 ZGY03PCV
└─sdb3 part 0 cfq 128 17G
└─sdb disk 0 cfq 128 sata 238.5G ATA SAMSUNG SSD 8 S0XZNEAC602
INFO: raid member component composition: mixed
INFO: raid member HDD component count: 4/5 (/dev/sdc /dev/sdd /dev/sde /dev/sdf)
INFO: raid member SSD component count: 1/5 (/dev/sdb)
This script can provide examples of using bash arrays, functions, terminal colouring, and regular expressions.
The script demonstrates (ab)using bash arrays to enumerate raid device components and partitions to inspect which partitions lie on devices with SMART errors or rotational (HDD) properties and check various combinations.
Declare an array for rotational devices:
d_list_rotational=()
Append a device to the array:
d_list_rotational+=("/dev/$d")
Count the number of devices in the array:
d_list_n_rotational=${#d_list_rotational[@]}