http://en.wikipedia.org/wiki/Mdadm

mdadm

From Wikipedia, the free encyclopedia
 
 
mdadm
Original author(s) Neil Brown
Developer(s) Neil Brown
Initial release 2001
Stable release 3.3[1] / September 3, 2013; 3 months ago
Development status Active
Written in C
Operating system Linux
Available in English
Type Disk utility
License GNU General Public License
Website http://neil.brown.name/blog/mdadm

 

mdadm is a Linux utility used to manage software RAID devices.

The name is derived from the md (multiple device) device nodes it administers or manages, and it replaced a previous utility mdctl. The original name was "Mirror Disk", but was changed as the functionality increased.

It is free software licensed under version 2 or later of the GNU General Public License - maintained and copyrighted to Neil Brown of SUSE.

 

Functionality[edit]

Types of physical device[edit]

mdadm can handle anything which presents to the kernel as a block device. This can encompass whole disks (/dev/sda) and partitions (/dev/sda1).

RAID Configurations[edit]

Main article: Standard RAID levels
  • RAID 0 — Block level striping. MD can handle devices of different lengths, the extra space on the larger device is then not striped.
  • RAID 1 — Mirror.
  • RAID 4 — Like RAID 0, but with an extra device for the parity.
  • RAID 5 — Like RAID 4, but with the parity distributed across all devices.
  • RAID 6 — Like RAID 5, but with two parity segments per stripe.
  • RAID 10 — Take a number of RAID 1 mirrorsets and stripe across them RAID 0 style.

Note that "RAID 10" is distinct from RAID "0+1", which consists of a top-level RAID-1 mirror composed of high-performance RAID-0 stripes directly across the physical hard disks. A single-drive failure in a RAID 10 configuration results in one of the lower-level mirrors entering degraded mode, but the top-level stripe performing normally (except for the performance hit). A single-drive failure in a RAID 0+1 configuration results in one of the lower-level stripescompletely failing, and the top-level mirror entering degraded mode. Which of the two setups is preferable depends on the details of the application in question, such as whether or not spare disks are available, and how they should be spun up.

Non-RAID configurations[edit]

  • Linear — concatenates a number of devices into a single large MD device.
  • Multipath — provides multiple paths with failover to a single device.
  • Faulty — a single device which emulates a number of disk-fault scenarios for testing and development.
  • Container — a group of devices managed as a single device, in which one can build RAID systems.

Types of MD device[edit]

The original (standard) form was /dev/md<n> where <n> is a number between 0 and 99. More recent kernels have supported the use of names such as /dev/md/Home. Under kernel 2.4 and earlier these two were the only options. Both of them are non-partitionable.

From kernel 2.6 a new type of MD device was introduced, a partitionable array. The device names were modified by changing md to md_d. The partitions were identified by adding p<m>; thus /dev/md/md_d2p3 for example.

From kernel 2.6.28 non-partitionable arrays can be partitioned, the partitions being referred to in the same way as for partitionable arrays — /dev/md/md1p2, for example.

Booting[edit]

Since support for MD is found in the kernel, there is an issue with using it before the kernel is running. Specifically it will not be present if the boot loader is either (e)LiLo or GRUB legacy. It may not be present for GRUB 2. In order to circumvent this problem a /boot filesystem must be used either without md support, or else with RAID1. In the latter case the system will boot by treating the RAID1 device as a normal filesystem, and once the system is running it can be remounted as md and the second disk added to it. This will result in a catch-up, but /boot filesystems are usually small.

With more recent bootloaders it is possible to load the MD support as a kernel module through the initramfs mechanism, this approach allows you to let the /boot filesystem be inside any RAID system without the need of a complex manual configuration.

Quick reference[edit]

Creating an array[edit]

mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sda1 /dev/sdb1

Create a RAID 1 (mirror) array from two partitions. If the partitions differ in size, the array is the size of the smaller partition. You can create a RAID 1 array with more than two devices. This gives you multiple copies. Whilst there is little extra safety in this, it makes sense when you are creating a RAID 5 array for most of your disk space and using RAID 1 only for a small /boot partition. Using the same partitioning for all member drives keeps things simple.

mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sda2 /dev/sdb2 /dev/sdc2

Create a RAID 5 volume from three partitions. If the partitions used in your RAID array are not the same size, mdadm will use the size of the smallest from each partition. If you receive an error, such as: "mdadm: RUN_ARRAY failed: Invalid argument", make sure your kernel supports (either via a module or by being directly compiled in) the raid mode you are trying to use. (Most modern kernels do.)

It is possible to create a degraded mirror, with one half missing by replacing a drive name with "missing":

mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb1 missing

The other half mirror is added to the set thus:

mdadm --manage /dev/md1 --add /dev/sda1

This is useful when you are adding a disk to a computer which currently isn't mirrored. The new drive is...

  • partitioned to match the first (unless you are also repartitioning too)
  • turned into a set of "half-mirrors"
  • formatted with appropriate file system
  • mounted
  • the data is copied over,
  • made bootable
  • its grub config and fstab mounts changed

The computer is then booted off the secondary drive (or a rescue disk), the now idle original disk can be repartitioned if required (no need to format), and then the primary drive submirrors are added.

Note that the partition types should be changed to 0xFD with fdisk to indicate that they are mirrored devices.

Recording the array[edit]

mdadm --detail /dev/md0

View the status of the multi disk array md0.

mdadm -Es | grep md >> /etc/mdadm/mdadm.conf

This adds md0 to the configuration file so that it is recognised next time you boot.

You may wish to keep a copy of /proc/mdstat on another machine or as a paper copy. The information will allow you to restart the array manually if mdadm fails to do so.

Growing an array by adding devices[edit]

mdadm --add /dev/md1 /dev/sdd1
mdadm --grow /dev/md1 --raid-devices=4

This adds the new device to the array then grows the array to use its space.

In some configurations you may not be able to grow the array until you have removed the internal bitmap. You can add the bitmap back again after the array has been grown.

mdadm --grow /dev/md1 -b none
mdadm --grow /dev/md1 -b internal

Growing an array by upgrading devices[edit]

An array may be upgraded by replacing the devices one by one, either as a planned upgrade or ad hoc as a result of replacing failed devices.

mdadm /dev/md1 --fail /dev/sda1
# replace the first drive with the new, larger one then partition it
mdadm --add /dev/md1 /dev/sda1

Allow the new drive to resync. If replacing all the devices repeat the above for each device, allowing the array to resync between repetitions. Finally, grow the array to use the maximum space available and then grow the filesystem(s) on the RAID array to use the new space.

mdadm --grow /dev/md1 --size=max

Deleting an array[edit]

mdadm --stop /dev/md0  # to halt the array
mdadm --remove /dev/md0 # to remove the array
mdadm --zero-superblock /dev/sd[abc]1 # delete the superblock from all drives in the array
# edit /etc/mdadm/mdadm.conf to delete any rows related to deleted array

Convert an existing partition to RAID 5[edit]

Assume that the existing data is on /dev/sda1:

mdadm --create /dev/md1 --level=5 --raid-devices=3 missing /dev/sdb2 /dev/sdc2
mdadm -Es >>/etc/mdadm/mdadm.conf
update-initramfs -u
dd if=/dev/sda1 of=/dev/md1
# replace /dev/sdaX with /dev/md1pX in your boot loader's menu
# reboot into /dev/md1
# format /dev/sdaY by marking the partition as autoraid
mdadm --add /dev/md1 /dev/sda1
# update your boot loader

Notes:

  • A partition can be specified as missing, to act as a placeholder so that it can be added later.
  • The /boot directory should be elsewhere, possibly on /dev/md0 or on its own partition.
  • If the reboot fails, do not add /dev/sda1 into the array until the issue is resolved.

Mdmpd[edit]

Mdmpd is a computer program for the GNU/Linux Operating System. It is part of the mdadm package written and copyrighted by Red Hat.[2] The program is used to monitor multi-path (RAID) devices, and is usually started at boot time as a service, and afterwards running as a daemon.

mdmpd – daemon to monitor MD multipath devices

Enterprise storage requirements often include the desire to have more than one way to talk to a single disk drive so that in the event of some failure to talk to a disk drive via one controller, the system can automatically switch to another controller and keep going. This is called multipath disk access. The linux kernel implements multipath disk access via the software RAID stack known as the md (Multiple Devices) driver. The kernel portion of the md multipath driver only handles routing I/O requests to the proper device and handling failures on the active path. It does not try to find out if a path that has previously failed might be working again. That's what this daemon does. Upon startup, the daemon will fork and place itself in the background. Then it reads the current state of the md raid arrays, saves that state, and then waits for the kernel to tell it something interesting has happened. It then wakes up, checks to see if any paths on a multipath device have failed, and if they have then it starts to poll the failed path once every 15 seconds until it starts working again. Once it starts working again, the daemon will then add the path back into the multipath md device it was originally part of as a new spare path.

If one is using the /proc filesystem, /proc/mdstat lists all active md devices with information about them. Mdmpd requires this to find arrays to monitor paths on and to get notification of interesting events.

Known problems[edit]

A common error when creating RAID devices is that the dmraid driver has taken control of all the devices that are to be used in the new RAID device. Error messages like this will occur:

mdadm: Cannot open /dev/sdb1: Device or resource busy

Typically, the solution to this problem involves adding the "nodmraid" kernel parameter to the boot loader config. Another way this error can present itself is if the device mapper has its way with the drives. Issue "dmsetup table" to see if the drive in question is listed. Issuing "dmsetup remove <drive id>" will remove the drive from device mapper and the error message from above will go away as well.

RAID already running[edit]

First check that the device is not already used in another array:

cat /proc/mdstat

Probably you will have to stop the array with:

mdadm --stop /dev/md<xxx>

Check the /etc/mdadm/mdadm.conf file (and restart the system if possible):

vi /etc/mdadm/mdadm.conf

Then you should be able to delete the superblock of this device:

mdadm --zero-superblock /dev/sd<x>N

Now the device should be no longer marked as busy.

Sometimes dmraid "owns" the devices and will not let them go. There is a solution.[3]

Tweaking the kernel[edit]

To solve this problem, you need to build a new initrd without the dmraid driver. The following command does this on a system running the 2.6.18-8.1.6.el5 kernel:

mkinitrd --omit-dmraid /boot/NO_DMRAID_initrd-2.6.18-8.1.6.el5.img 2.6.18-8.1.6.el5

After this, the system has to be rebooted with the new initrd. Edit your /boot/grub/grub.conf to achieve this.

Alternatively if you have a self customized and compiled kernel from a Linux distribution like Gentoo (the default option in Gentoo) which does not use initrd then check kernel .config file in /usr/src/linux for the line

# CONFIG_BLK_DEV_DM is not configured

If the above line is set as follows:

CONFIG_BLK_DEV_DM=y

then you might have to disable that option, recompile the kernel, put it in /boot and finally edit grub config file in /boot/grub. PLEASE be careful NOT to disable

CONFIG_BLK_DEV_MD=y

(Note the MD instead of DM) which is essential for raid to work at all!

If both methods have not helped you then booting from live CD probably will (the below example is for starting a degraded RAID-1 mirror array and adding a spare HDD to it and syncing. Creating a new one should not be more difficult because the underlying problem was a "Device or resource busy" error):

modprobe raid1
mknod /dev/md1 b 9 1
mknod /dev/md3 b 9 3
mdadm --assemble /dev/md1 /dev/hda1
mdadm --assemble /dev/md3 /dev/hda3
mdadm --add /dev/md1 /dev/hdb1
mdadm --add /dev/md3 /dev/hdb3

It might be easier to try and automatically assemble the devices:

mdadm --assemble --scan

Remember to change the corresponding md* and hd* values with the corresponding ones from your system. You can monitor the sync progress using:

cat /proc/mdstat

When the sync is done you can reboot the computer as usual.

Zeroing the superblock[edit]

Another way to prevent the kernel autostarting the raid is to remove all the previous raid-related information from the disks before proceeding with the creation, for example:

mdadm --stop /dev/md0
mdadm --zero-superblock /dev/sd[abcd]1

And now the usual create, for example:

mdadm --create /dev/md0 --level=5 --raid-devices=4 --spare-devices=0 /dev/sd[abcd]1

Recovering from a loss of RAID superblock[edit]

There are superblocks on the drives themselves and on the RAID (apparently). If you are unable to recover a RAID set damaged due to power outage or hardware failure, try the following procedure in order to re-create the superblocks and make your data accessible again.

Get a list of the devices in the raid in question:

mdadm --detail /dev/md<x>

Output of the command above looks like this:

/dev/md127:
Version : 1.2
Creation Time : Sun Aug 21 23:35:28 2011
Raid Level : raid6
Array Size : 7814047744 (7452.06 GiB 8001.58 GB)
Used Dev Size : 1953511936 (1863.01 GiB 2000.40 GB)
Raid Devices : 6
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Jan 1 11:43:17 2012
State : clean, degraded
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : clop:1 (local to host clop)
UUID : 7ee1e93a:1b011f80:04503b8d:c5dd1e23
Events : 62
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 49 1 active sync /dev/sdd1
2 8 81 2 active sync /dev/sdf1
3 8 65 3 active sync /dev/sde1
4 0 0 4 removed
5 0 0 5 removed

RaidDevice order (sdc1sdd1sdf1sde1) and Chunk Size value are critical.

Record all your raid member parameters:

mdadm --examine /dev/sd[abcde...]1 | egrep 'dev|Update|Role|State|Chunk Size'

Look carefully at the Update time values. If you have RAID members attached to the motherboard and others attached to a RAID card, and the card actually failed while leaving enough members to keep the RAID set operational, you want to make a note of that. Look at the Array State and Update Time values, for example (output is separated with blank lines for better readability):

/dev/sdc1:
Update Time : Wed Jun 15 00:32:35 2011
Array State : AAAA.. ('A' == active, '.' == missing) /dev/sdd1:
Update Time : Thu Jun 16 21:49:27 2011
Array State : .AAA.. ('A' == active, '.' == missing) /dev/sde1:
Update Time : Thu Jun 16 21:49:27 2011
Array State : .AAA.. ('A' == active, '.' == missing) /dev/sdf1:
Update Time : Thu Jun 16 21:49:27 2011
Array State : .AAA.. ('A' == active, '.' == missing) /dev/sdk1:
Update Time : Tue Jun 14 07:09:34 2011
Array State : ....AA ('A' == active, '.' == missing) /dev/sdl1:
Update Time : Tue Jun 14 07:09:34 2011
Array State : ....AA ('A' == active, '.' == missing)

Devices sdc1sdd1sde1 and sdf1 are the last members in the array and they will rebuild correctly. On the other side, sdk1 and sdl1 are droppeed from the array (in this example, due to a RAID card failure).

Also note the RAID member, starting with 0, as the RAID set needs to be rebuilt in the same order. Chunk Size value is also important.

Wipe the drives' superblocks:

mdadm --stop /dev/md0    # halt the array
mdadm --remove /dev/md0 # remove the array
mdadm --zero-superblock /dev/sd[cdefkl]1

Reassemble the RAID set:

mdadm --create /dev/md1 --chunk=4096 --level=6 --raid-devices=6 /dev/sdc1 /dev/sdd1 /dev/sdf1 /dev/sde1 missing missing

Parameter missing tells the create command to rebuild the RAID set in a degraded state. Devices sdk1 and sdl1 can be added later.

Edit /etc/mdadm.conf and add an ARRAY line with the appropriate UUID value. In order to do that, first find the UUID for your RAID set:

mdadm -D /dev/md<x>

And then make the changes:

vi /etc/mdadm.conf

Example of the configuration file is below — note there must be no # in front of the active line you are adding:

#ARRAY /dev/md0 UUID=3aaa0122:29827cfa:5331ad66:ca767371
#ARRAY /dev/md1 super-minor=1
#ARRAY /dev/md2 devices=/dev/hda1,/dev/hdb1
ARRAY /dev/md1 UUID=7ee1e93a:1b011f80:04503b8d:c5dd1e23

Save your edited /etc/mdadm.conf.

Last, mark the array as possibly dirty with:

mdadm --assemble /dev/md1 --update=resync

Monitor the rebuild with:

watch -n 1 cat /proc/mdstat

All your data should be recovered and accessible!

Increasing RAID ReSync Performance[edit]

In order to increase the resync speed, we can use a bitmap, which mdadm will use to mark which areas may be out-of-sync. Add the bitmap with the grow option like below:

mdadm -G /dev/md2 --bitmap=internal
Note: mdadm – v2.6.9 – 10 March 2009 on Centos 5.5 requires this to be run on a stable "clean" array. If the array is rebuilding the following error will be displayed:
mdadm: failed to set internal bitmap.
And the following line is added to the log file:
md: couldn't update array info. -16

then verify that the bitmap was added to the md2 device using

cat /proc/mdstat

you can also adjust Linux kernel limits by editing files /proc/sys/dev/raid/speed_limit_min and /proc/sys/dev/raid/speed_limit_max.

You can also edit this with the sysctl utility

sysctl -w dev.raid.speed_limit_min=50000

References[edit]

External links[edit]

mdadm的更多相关文章

  1. mdadm设定RAID磁盘阵列,且当分区故障后如何重建

    首先,fdisk建立不同分区,且设为fd格式 其次, mdadm -C md0 -a yes -l -n /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sd ...

  2. 在Linux下使用RAID--使用mdadm工具创建软件Raid 0(1)

    在Linux下使用RAID--使用mdadm工具创建软件Raid 0(1) RAID即廉价磁盘冗余阵列,其高可用性和可靠性适用于大规模环境中,相比正常使用,数据更需要被保护.RAID是一些磁盘的集合, ...

  3. 专题:mdadm Raid & LVM

    >FOR FREEDOM!< {A} Introduction Here's a short description of what is supported in the Linux R ...

  4. RAID,mdadm(笔记)

    RAID: 级别:仅代表磁盘组织方式不同,没有上下之分:0: 条带    性能提升: 读,写    冗余能力(容错能力): 无    空间利用率:nS    至少2块盘1: 镜像    性能表现:写性 ...

  5. mdadm命令详解及实验过程

    一.概念 mdadm是multiple devices admin的简称,它是Linux下的一款标准的软件 RAID 管理工具,作者是Neil Brown 二.特点 mdadm能够诊断.监控和收集详细 ...

  6. RHEL 6 mdadm 实现Soft Raid

    环境:RHEL 6.9 x64 1.mdadm命令用于管理系统软件RAID硬盘阵列 格式为:"mdadm [模式] <RAID设备名称> [选项] [成员设备名称]". ...

  7. mdadm语法

    mdadm命令详解及实验过程   一.概念 mdadm是multiple devices admin的简称,它是Linux下的一款标准的软件 RAID 管理工具,作者是Neil Brown 二.特点 ...

  8. mdadm命令详解

    创建阵列(-C或--create) --raid-devices(-n) 功能:指定阵列中成员盘个数. 举例:mdadm --create /dev/md0 -l5 -n2 /dev/sdb /dev ...

  9. [daily][archlinux][mdadm][RAID] 软RAID

    一, 使用mdadm创建RAID 参考:https://wiki.archlinux.org/index.php/RAID 1.  安装 mdadm /home/tong [tong@TStation ...

  10. 软RAID管理命令mdadm详解

    软RAID管理命令mdadm详解 mdadm是linux下用于创建和管理软件RAID的命令,是一个模式化命令.但由于现在服务器一般都带有RAID阵列卡,并且RAID阵列卡也很廉价,且由于软件RAID的 ...

随机推荐

  1. 【转】关于AI的目标导向型行动计划

    作者:Brent Owens 目标导向型行动计划(简称GOAP)是一种能够轻松呈现给你的代理选择的AI系统,也是帮助你可以无需维持一个庞大且复杂的有限状态机而做出明智的决策的机器. 演示版本 在这一演 ...

  2. python学习笔记--python编程基础

    一.一个隆重的仪式 我们在学习语言的时候,第一个写的程序肯定都是hello world.来写第一个程序吧,其实很简单,python的语法就是简单.优雅,一个print就搞定. 1 print('hel ...

  3. 学习 WebService 第二步:知识准备——WSDL文件解析

    原文地址:https://www.cnblogs.com/yzw23333/p/7245104.html Web service中一个 WSDL 对应一个 web service地址. 可以想象成一个 ...

  4. SQL的主键和外键和唯一约束

    SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...

  5. POJ3625 Building Roads

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10803   Accepted: 3062 Description Fa ...

  6. 洛谷 P 1514 引水入城==Codevs 1066

    题目描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个N 行M 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市都有一个海拔高度. ...

  7. 转 Python常见数据结构整理

    http://www.cnblogs.com/jeffwongishandsome/archive/2012/08/05/2623660.html Python常见数据结构整理 Python中常见的数 ...

  8. CSS-@media媒体查询(输出设备中的页面可见区域宽度)

    早上好,仙女刘,首先恭喜你在2019.06.13号也就是昨天生日快乐!希望你在今后的每一天都是开开心心的,爱你哟,早上起床后的在激动心情下的美美哒! 好了,现在进入正题: 在做响应式页面的时候,我经常 ...

  9. python3 - pop 接收邮件/ smtp 发送邮件

    以下通过python3 实现接收和发送邮件,网上相关说明文档很多.请自己查阅,这里只写入代码, # 实例:通过poplib 模块接收指定账号的邮件并进行解码处理,结果可视化. #!/opt/pytho ...

  10. linux编译

    文章一 1)用户点击编译程序时,编译程序将C++源代码转换成目标代码,目标代码通常由 机器指令和记录如何将程序加载到内存的信息组成.其后缀通常为.obj或.o: 2)目标文件中存储的只是用户所编写的代 ...