Linux Labs

Storage / Stage 5 of 12

RAID 1: a disk has failed

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 8 · theory · 6 min

Recording the array

Here: which records mdadm assembles arrays from, and why an array is written into /etc/mdadm/mdadm.conf.

At the start of every disk in an array sits the md superblock, a service record with the array's UUID, its name and the disk's number. super 1.2 in /proc/mdstat is the format of that record, and sudo mdadm --examine /dev/loop0 prints it. From the superblocks mdadm finds the disks of one array and assembles them again: on a server, at boot as the disks appear, or on the command sudo mdadm --assemble --scan.

The file /etc/mdadm/mdadm.conf is the machine's list of arrays (in the Wiki): one ARRAY line with the device name and the array's UUID. While there are no lines, mdadm --assemble --scan assembles every array it finds: an array of this machine by the name in its superblock (ubuntu:0 → /dev/md0), and an array with another host's name, for instance from the disks of another server, as /dev/md127. Once lines are there, only the listed arrays are assembled, under the listed names.

mdadm prints the line itself, and you append it to the file with sudo tee -a:

bash
sudo mdadm --detail --scan            # lines for all assembled arrays
sudo mdadm --detail --brief /dev/md0  # the line for one array
sudo mdadm --detail --brief /dev/md0 | sudo tee -a /etc/mdadm/mdadm.conf

One line per array: with two lines for the same array, mdadm --assemble --scan answers Duplicate MD device names in conf file were found. Arrays needed for booting are also assembled by the server in initramfs from its own copy of the file, so after editing mdadm.conf the copy is refreshed: sudo update-initramfs -u.

Check yourself 1 question

The server's mdadm.conf lists only the md0 array. Two disks holding a mirror from an old server have been attached. What will sudo mdadm --assemble --scan do?

  • mdadm does not hand out numbers in order: it takes the name from an ARRAY line or from the superblock. The moved array is not in the file, so mdadm will not assemble it.

  • --assemble --scan does not touch a running array: md0 stays in /proc/mdstat. And the moved array is not in the file.

  • That would happen if the file had no ARRAY lines at all. The md0 line is there, and mdadm assembles only the arrays it lists.

When mdadm.conf has ARRAY lines, --assemble --scan assembles only the arrays they list. The moved array is assembled once its line, with the UUID from sudo mdadm --examine of any of its disks, is added to the file.

Key points

  • The superblock on every disk keeps the array's UUID: mdadm uses it to find the disks of one array.
  • An ARRAY line in mdadm.conf pins a name to the array; once there are lines, mdadm assembles only the listed arrays.
  • One line per array, and on a server the initramfs is refreshed after editing the file.
Ubuntu 24.04
Loading…