Did you know  45Drives offers free  public and private  webinars ? Click here to learn more  & register! Build & Price

KB450304 – Assembling RBD mdadm Raids on Boot

You are here:

Scope/Description

  • This article will show how to ensure mdadm raids built on rbd will mount on boot.
  • Due to the order of the linux boot process, mdadm devices built with rbd’s will not be assembled on boot time. This article provided the solution using a systemd service.

Prerequisites

  • RBD images mapped and configured for auto mapping on boot.
  • mdadm array created.

Steps

Creating mdadm configuruation file

  • Create mdadm config directory if not already created
[root@client ~]$ mkdir /etc/mdadm
  • Create mdadm.conf file if not alreay created
    • Careful not to make duplicated entries !
[root@client ~]$ mdadm --examine --scan >> /etc/mdadm/mdadm.conf
  • Create md-rbd.conf file
    • Change the varibles accordingly to fit your environment
[root@client ~]$ cat > /etc/mdadm/md-rbd.conf <<EOF
# MDADM device name
MD_DEVICE=/dev/md0
# Mount point of RBD mdadm raid
MOUNT_POINT=/mnt/data
EOF

Creating systemd service file

  • Create systemd service file, “md-rbd-assemble.service”
[root@client ~]$ cat > /usr/lib/systemd/system/md-rbd-assemble.service <<EOF
[Unit]
Description=mdadm assemble rbd devices
ConditionPathExists=/etc/mdadm/mdadm.conf
ConditionPathExists=/etc/mdadm/md-rbd.conf
After=rbdmap.service

[Service]
EnvironmentFile=-/etc/mdadm/md-rbd.conf
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/md-rbd-assemble $MD_DEVICE $MOUNT_POINT

[Install]
WantedBy=multi-user.target
EOF
  • Create assemble-rbd-md script and past the below into the file
[root@client ~]$ touch /usr/bin/md-rbd-assemble
#!/bin/bash
MD_DEVICE=$1
MOUNT_POINT=$2
mdadm --assemble $MD_DEVICE
mount -t xfs $MOUNT_POINT
  • Mark it executable
[root@client ~]$ chmod +x /usr/bin/md-rbd-assemble
  • Add entry to fstab for md mount
    • Make sure md device and mountpoint are correct for your environment
[root@client ~]$ echo "/dev/md0 /mnt/data xfs defaults,noatime,nofail 0 0" >> /etc/fstab
  • Enable md-rbd-assemble.service
[root@client ~]$ systemctl enable md-rbd-assemble
  • Reboot and verify that mdadm is started and mounted

Verification

Troubleshooting

Was this article helpful?
Dislike 0
Views: 404
Unboxing Racking Storage Drives Cable Setup Power UPS Sizing Remote Access