$ cd ~/mycloud
$ wget https://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-3.2.6.tar.xz
$ tar -xvf mdadm-3.2.6.tar.xz -C ./busybox-1.23.2/
#生成编译源代码相关的项目
$ cat >> ./busybox-1.23.2/mdadm-3.2.6/Kbuild.src <<EOF
lib-y:=
INSERT
lib-\$(CONFIG_MDADM) += mdadm.o config.o policy.o mdstat.o ReadMe.o util.o maps.o lib.o \
Manage.o Assemble.o Build.o \
Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o \
Incremental.o \
mdopen.o super0.o super1.o super-ddf.o super-intel.o bitmap.o \
super-mbr.o super-gpt.o \
restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o \
platform-intel.o probe_roms.o
CFLAGS_\$(CONFIG_MDADM) += -DDEFAULT_OLD_METADATA -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter
EOF
#生成配置信息
$ cat >> ./busybox-1.23.2/mdadm-3.2.6/Config.src <<EOF
menu "Linux Software RAID MDAMD"
INSERT
config MDADM
bool "mdadm"
default y
help
Linux Software RAID
endmenu
EOF
#添加配置项到busybox项目
$ sed -i '$a\source mdadm-3.2.6/Config.in' ./busybox-1.23.2/Config.in
#添加源代码路径到busybox项目
$ sed -i '/libs-y := \\/{:n;N;/^endif \# KBUILD_EXTMOD/!bn};s/util-linux\/volume_id\/ \\/util-linux\/volume_id\/ \\\n\t\tmdadm-3.2.6\/ \\/' ./busybox-1.23.2/Makefile
#添加帮助信息
$ sed -i 's/#endif/\n#define mdadm_trivial_usage "None"\n#define mdadm_full_usage "None"\n#endif/' ./busybox-1.23.2/include/usage.src.h
#添加命令
$ sed -i 's/^INSERT$/INSERT\nIF_MDADM(APPLET(mdadm, BB_DIR_USR_SBIN, BB_SUID_DROP))/' ./busybox-1.23.2/include/applets.src.h
#调整函数入口名
$ sed -i 's/int main(int argc, char \*argv\[])/int mdadm_main(int argc, char \*argv\[])/' ./busybox-1.23.2/mdadm-3.2.6/mdadm.c
#调整代码,否则编译不通过
$ sed -i 's/inline int count_dirty_bits_byte(char byte, int num_bits)/int count_dirty_bits_byte(char byte, int num_bits)/' ./busybox-1.23.2/mdadm-3.2.6/bitmap.c
#在busybox编译配置中开启我们刚刚增加的功能
$ sed -i '$a\CONFIG_MDADM=y' ./busybox-config
#编译
$ ./build-sys.sh