User Tools

Site Tools

This documentation is no longer maintained by the Turris team (although it can be used by the community to share content). The current official documentation is at docs.turris.cz.

Table of Contents

Summary

These instructions assume that the steps to assemble the hardware components of the RAID has been completed.

Instructions

The steps are to be performed via ssh.

  1. Identify the block (two 3.7TB drives in this example):
    root@turris:~# lsblk
    
    NAME         MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
    sda            8:0    0  3.7T  0 disk              <-- device 1
    sdb            8:16   0  3.7T  0 disk              <-- device 2
    mtdblock0     31:0    0    1M  0 disk  
    mtdblock1     31:1    0    7M  0 disk  
    mmcblk0      179:0    0  7.3G  0 disk  
    `-mmcblk0p1  179:1    0  7.3G  0 part  /
    mmcblk0boot0 179:8    0    4M  1 disk  
    mmcblk0boot1 179:16   0    4M  1 disk  
    mmcblk0rpmb  179:24   0    4M  0 disk  
  2. Disable NCQ:
    root@turris:~# echo 1 > /sys/block/[device 1]/device/queue_depth
    root@turris:~# echo 1 > /sys/block/[device 2]/device/queue_depth 
  3. Create array ([device 1] → sda; [device 2] → sdb):
    root@turris:~# mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sda /dev/sdb
  4. Monitor status:
    root@turris:~# cat /proc/mdstat
  5. Create file system (btrfs in this example):
    root@turris:~# mkfs.btrfs /dev/md0
  6. Find UUID for /dev/md0:
    root@turris:~# lsblk -o NAME,SIZE,MOUNTPOINT,STATE,FSTYPE,MODEL,UUID
    
    NAME          SIZE MOUNTPOINT STATE   FSTYPE            MODEL            UUID
    sda           3.7T            running linux_raid_member ST4000DM005-2DP1 f4b01a9e-7349-057d-f5f2-61ccbd78b1ea
    `-md0         3.7T                    btrfs                              6282e17f-2797-49dc-b4f9-e9452c35b922  <-- UUID
    sdb           3.7T            running linux_raid_member ST4000DM005-2DP1 f4b01a9e-7349-057d-f5f2-61ccbd78b1ea
    `-md0         3.7T                    btrfs                              6282e17f-2797-49dc-b4f9-e9452c35b922  <-- UUID
    mtdblock0       1M                                                       
    mtdblock1       7M                                                       
    mmcblk0       7.3G                                                       
    `-mmcblk0p1   7.3G /                  btrfs                              1ecd23ea-3018-4a83-9072-d337b0d00c5c
    mmcblk0boot0    4M                                                       
    mmcblk0boot1    4M                                                       
    mmcblk0rpmb     4M                                                       
  7. Mount drive by adding a section (choose one of the two options) to /etc/config/fstab:
    # cat /etc/config/fstab
    
    # mount using UUID
    config mount
    	option enabled '1'
    	option uuid '[UUID]'
    	option target '/mnt/raid'
    
    # mount using device 
    config mount
    	option enabled '1'
    	option device '/dev/md0'
    	option target '/mnt/raid'
    
  8. Create the settings file (/etc/mdadm/mdadm.conf) with the following contents:
    # mdadm.conf
    #
    # Please refer to mdadm.conf(5) for information about this file.
    #
    
    DEVICE partitions
    
    # auto-create devices with Debian standard permissions
    CREATE owner=root group=disk mode=0660 auto=yes
    
    # automatically tag new arrays as belonging to the local system
    HOMEHOST <system>
    
    # instruct the monitoring daemon where to send mail alerts
    MAILADDR root
    
    # definitions of existing MD arrays
  9. Append the details of the RAID to the settings file:
    # mdadm --examine --scan >> /etc/mdadm/mdadm.conf
  10. The file should resemble:
    # mdadm.conf
    #
    # Please refer to mdadm.conf(5) for information about this file.
    #
    
    DEVICE partitions
    
    # auto-create devices with Debian standard permissions
    CREATE owner=root group=disk mode=0660 auto=yes
    
    # automatically tag new arrays as belonging to the local system
    HOMEHOST <system>
    
    # instruct the monitoring daemon where to send mail alerts
    MAILADDR root
    
    # definitions of existing MD arrays
    ARRAY /dev/md/0 metadata=1.2 name=turris:0 UUID=69c415bb::########::########:########
  11. Test the settings file:
    # mdadm --monitor --scan --test --oneshot
  12. An email should be received:
    This is an automatically generated mail message from mdadm running on turris 
     
    A DegradedArray event had been detected on md device /dev/md/0. 
     
    Faithfully yours, etc. 
     
    P.S. The /proc/mdstat file currently contains the following: 
     
    Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath] 
    md0 : active raid1 sda[2] sdb[1] 
        1953383360 blocks super 1.2 [2/1] [_U] 
        [===>.................] recovery = 17.9% 
    (351595072/1953383360) finish=242.1min speed=110263K/sec 
     
    unused devices: <none> 
  13. Adjust /etc/rc.local to enable RAID on boot:
    # disable NCQ
    echo 1 > /sys/block/sda/device/queue_depth
    echo 1 > /sys/block/sdb/device/queue_depth
    
    # start RAID array
    mdadm --assemble --scan
    
    # start RAID monitoring
    # --scan        -s   : find mail-address/program in config file (/etc/mdadm/mdadm.conf)
    # --test        -t   : Generate a TestMessage event against each array at startup
    # --daemonise   -f   : Fork and continue in child, parent exits
    mdadm --monitor --scan --test --daemonize
    
    # existing code
    exit 0

Reference