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.

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