Articles I've written for customers on IT issues.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.0 KiB

5 years ago
  1. \documentclass[11pt]{article}
  2. %Gummi|065|=)
  3. \title{\textbf{RAID on GnuLinux - Mdadm Reference}}
  4. \usepackage{graphicx}
  5. \usepackage{caption }
  6. \author{Steak Electronics}
  7. \date{07/31/19}
  8. \begin{document}
  9. %\maketitle
  10. \textbf{RAID on GnuLinux - Mdadm Reference}
  11. %\textbf{Todo}
  12. \section{Overview}
  13. There are a few options for software RAID on Gnu Linux. Among them is BtrFS and ZFS, however today I will focus on using mdadm. This is historically the oldest software raid, therefore should be better vetted, although its performance may be less of that of the first two mentioned - for simple servers, mdadm might be the most stable choice.
  14. \section{Details}
  15. I've worked with this in setting up some Core 2 Duo PCs, with 2 to 4 Sata HDDs. This will be a reference. Let's begin.
  16. \\
  17. \\
  18. \subsection{Creation of RAID:}
  19. Will not be covered here (yet). You must create the partition tables. Create the raid with mdadm. mkfs.ext4 on the raid partition. Add mdadm to grub config. Reinstall grub. Details may be provided later.
  20. \subsection{Details of RAID:}
  21. \begin{verbatim}
  22. root@advacoONE:/dev# sudo mdadm -D /dev/md127
  23. /dev/md127:
  24. Version : 1.2
  25. Creation Time : Fri Feb 1 01:00:25 2019
  26. Raid Level : raid1
  27. Array Size : 57638912 (54.97 GiB 59.02 GB)
  28. Used Dev Size : 57638912 (54.97 GiB 59.02 GB)
  29. Raid Devices : 3
  30. Total Devices : 2
  31. Persistence : Superblock is persistent
  32. Update Time : Fri Feb 1 02:40:44 2019
  33. State : clean, degraded
  34. Active Devices : 2
  35. Working Devices : 2
  36. Failed Devices : 0
  37. Spare Devices : 0
  38. Name : devuan:root
  39. UUID : 83a8dc03:802a4129:26322116:c2cfe1d4
  40. Events : 82
  41. Number Major Minor RaidDevice State
  42. - 0 0 0 removed
  43. 1 8 17 1 active sync /dev/sdb1
  44. 2 8 33 2 active sync /dev/sdc1
  45. root@advacoONE:/dev#--
  46. \end{verbatim}
  47. so you can see, one was removed (it auto removes, when unplugged)
  48. \\
  49. \\
  50. \subsection{Add Drive to RAID:}
  51. sudo mdadm --add /dev/md127 /dev/sda1
  52. \\
  53. \\
  54. NOTE2: If you setup 2 hdds, in a raid, and want to add a third, if you just --add, it will show up as a spare...
  55. if you do mdadm --grow /dev/md127 -raid-devices=3 then the third might be active sync (what we want)
  56. note that the --grow, seems to allow for parameter changes after you have already created the raid. you can also specify
  57. the exact same command, raid-devices=3 in the setup of the raid (see install doc). Note that if you lose a drive, you can simply add it.
  58. \\
  59. \\
  60. NOTE: don't worry about mkfs.ext4 on the raid members, after initial setup. The RAID will manage that.
  61. \\
  62. \\
  63. NOTE: if you have a new drive and need to copy the hdd partition tables:
  64. https://unix.stackexchange.com/questions/12986/how-to-copy-the-partition-layout-of-a-whole-disk-using-standard-tools
  65. or aka
  66. \begin{verbatim}
  67. (FOR MBR ONLY)
  68. Save:
  69. sfdisk -d /dev/sda > part_table
  70. Restore:
  71. sfdisk /dev/NEWHDD < part_table
  72. (FOR GPT:)
  73. # Save MBR disks
  74. sgdisk --backup=/partitions-backup-$(basename $source).sgdisk $source
  75. sgdisk --backup=/partitions-backup-$(basename $dest).sgdisk $dest
  76. # Copy $source layout to $dest and regenerate GUIDs
  77. sgdisk --replicate=$dest $source
  78. sgdisk -G $dest
  79. \end{verbatim}
  80. \begin{verbatim}
  81. root@advacoONE:/dev# mdadm --add /dev/md127 /dev/sda1
  82. mdadm: added /dev/sda1
  83. root@advacoONE:/dev# sudo mdadm -D /dev/md127
  84. /dev/md127:
  85. Version : 1.2
  86. Creation Time : Fri Feb 1 01:00:25 2019
  87. Raid Level : raid1
  88. Array Size : 57638912 (54.97 GiB 59.02 GB)
  89. Used Dev Size : 57638912 (54.97 GiB 59.02 GB)
  90. Raid Devices : 3
  91. Total Devices : 3
  92. Persistence : Superblock is persistent
  93. Update Time : Fri Feb 1 02:41:43 2019
  94. State : clean, degraded, recovering
  95. Active Devices : 2
  96. Working Devices : 3
  97. Failed Devices : 0
  98. Spare Devices : 1
  99. Rebuild Status : 0% complete
  100. Name : devuan:root
  101. UUID : 83a8dc03:802a4129:26322116:c2cfe1d4
  102. Events : 92
  103. Number Major Minor RaidDevice State
  104. 3 8 1 0 spare rebuilding /dev/sda1
  105. 1 8 17 1 active sync /dev/sdb1
  106. 2 8 33 2 active sync /dev/sdc1
  107. root@advacoONE:/dev#
  108. \end{verbatim}
  109. Looks good.
  110. \begin{verbatim}
  111. Rebuild Status : 6% complete
  112. Name : devuan:root
  113. UUID : 83a8dc03:802a4129:26322116:c2cfe1d4
  114. Events : 103
  115. Number Major Minor RaidDevice State
  116. 3 8 1 0 spare rebuilding /dev/sda1
  117. 1 8 17 1 active sync /dev/sdb1
  118. 2 8 33 2 active sync /dev/sdc1
  119. \end{verbatim}
  120. as it progresses, you see the RAID rebuilding.
  121. \begin{verbatim}
  122. watch -n1 cat /proc/mdstat
  123. Every 1.0s: cat /proc/mdstat
  124. advacoONE: Fri Feb 1 02:43:24 2019
  125. Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]
  126. md127 : active raid1 sda1[3] sdb1[1] sdc1[2]
  127. 57638912 blocks super 1.2 [3/2] [_UU]
  128. [==>..................] recovery = 11.2% (6471936/57638912) finish=13.2min speed=64324K/sec
  129. unused devices: <none>
  130. \end{verbatim}
  131. \textbf{WARNING:} Reinstall grub on the new drive again as well afterwards.
  132. \subsection{Email Notifications on mdadm}
  133. Test emails on mdadm.. first configure email however you prefer (i currently use ssmtp, see this link:
  134. https://wiki.zoneminder.com/How\_to\_get\_ssmtp\_working\_with\_Zoneminder
  135. --
  136. then edit /etc/mdadm/mdadm.conf to have your email in mailaddr
  137. then
  138. \begin{verbatim}
  139. sudo mdadm --monitor --scan --test --oneshot
  140. \end{verbatim}
  141. should send an email
  142. https://ubuntuforums.org/showthread.php?t=1185134
  143. for more details on email sending
  144. \section{References}
  145. \begin{verbatim}
  146. The section about degraded disks
  147. https://help.ubuntu.com/lts/serverguide/advanced-installation.html.en
  148. General partition tips.
  149. https://github.com/zfsonlinux/zfs/wiki/Debian-Stretch-Root-on-ZFS
  150. SSMTP email setup:
  151. https://wiki.zoneminder.com/How_to_get_ssmtp_working_with_Zoneminder
  152. wiki.zoneminder.com/SMS_Notifications
  153. \end{verbatim}
  154. \end{document}