From dfaf8a99e7f49b7157d5c1cfe4e6e7927240d5e9 Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Sat, 7 Aug 2021 09:05:38 +0000 Subject: [PATCH] feat: add mdadm package The mdadm/udev-rules help to activate soft raid on boot time or then it attached. --- Makefile | 2 +- mdadm/files/udev-md-raid-arrays.rules | 36 +++++++++++++++++++++++++ mdadm/files/udev-md-raid-assembly.rules | 30 +++++++++++++++++++++ mdadm/pkg.yaml | 28 +++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 mdadm/files/udev-md-raid-arrays.rules create mode 100644 mdadm/files/udev-md-raid-assembly.rules create mode 100644 mdadm/pkg.yaml diff --git a/Makefile b/Makefile index 819e10d59..e62843375 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ COMMON_ARGS += --build-arg=https_proxy=$(https_proxy) empty := space = $(empty) $(empty) -TARGETS = ca-certificates cni containerd cryptsetup dosfstools eudev fhs grub ipmitool iptables ipxe kernel kmod libaio libjson-c liblzma libpopt libressl libseccomp linux-firmware lvm2 musl open-iscsi open-isns raspberrypi-firmware runc socat syslinux u-boot util-linux xfsprogs +TARGETS = ca-certificates cni containerd cryptsetup dosfstools eudev fhs grub ipmitool iptables ipxe kernel kmod libaio libjson-c liblzma libpopt libressl libseccomp linux-firmware lvm2 mdadm musl open-iscsi open-isns raspberrypi-firmware runc socat syslinux u-boot util-linux xfsprogs all: $(TARGETS) ## Builds all known pkgs. diff --git a/mdadm/files/udev-md-raid-arrays.rules b/mdadm/files/udev-md-raid-arrays.rules new file mode 100644 index 000000000..fc663fddf --- /dev/null +++ b/mdadm/files/udev-md-raid-arrays.rules @@ -0,0 +1,36 @@ +# do not edit this file, it will be overwritten on update + +SUBSYSTEM!="block", GOTO="md_end" + +# handle md arrays +ACTION!="add|change", GOTO="md_end" +KERNEL!="md*", GOTO="md_end" + +# partitions have no md/{array_state,metadata_version}, but should not +# for that reason be ignored. +ENV{DEVTYPE}=="partition", GOTO="md_ignore_state" + +# container devices have a metadata version of e.g. 'external:ddf' and +# never leave state 'inactive' +ATTR{md/metadata_version}=="external:[A-Za-z]*", ATTR{md/array_state}=="inactive", GOTO="md_ignore_state" +TEST!="md/array_state", GOTO="md_end" +ATTR{md/array_state}=="clear*|inactive", GOTO="md_end" +LABEL="md_ignore_state" + +IMPORT{program}="/sbin/mdadm --detail --no-devices --export $devnode" +ENV{DEVTYPE}=="disk", ENV{MD_NAME}=="?*", SYMLINK+="disk/by-id/md-name-$env{MD_NAME}", OPTIONS+="string_escape=replace" +ENV{DEVTYPE}=="disk", ENV{MD_UUID}=="?*", SYMLINK+="disk/by-id/md-uuid-$env{MD_UUID}" +ENV{DEVTYPE}=="disk", ENV{MD_DEVNAME}=="?*", SYMLINK+="md/$env{MD_DEVNAME}" +ENV{DEVTYPE}=="partition", ENV{MD_NAME}=="?*", SYMLINK+="disk/by-id/md-name-$env{MD_NAME}-part%n", OPTIONS+="string_escape=replace" +ENV{DEVTYPE}=="partition", ENV{MD_UUID}=="?*", SYMLINK+="disk/by-id/md-uuid-$env{MD_UUID}-part%n" +ENV{DEVTYPE}=="partition", ENV{MD_DEVNAME}=="*[^0-9]", SYMLINK+="md/$env{MD_DEVNAME}%n" +ENV{DEVTYPE}=="partition", ENV{MD_DEVNAME}=="*[0-9]", SYMLINK+="md/$env{MD_DEVNAME}p%n" + +IMPORT{builtin}="blkid" +OPTIONS+="link_priority=100" +OPTIONS+="watch" +ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}" +ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-partuuid/$env{ID_PART_ENTRY_UUID}" +ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}" + +LABEL="md_end" diff --git a/mdadm/files/udev-md-raid-assembly.rules b/mdadm/files/udev-md-raid-assembly.rules new file mode 100644 index 000000000..c12935197 --- /dev/null +++ b/mdadm/files/udev-md-raid-assembly.rules @@ -0,0 +1,30 @@ +# do not edit this file, it will be overwritten on update + +# assemble md arrays +SUBSYSTEM!="block", GOTO="md_inc_end" + +# handle potential components of arrays (the ones supported by md) +ENV{ID_FS_TYPE}=="linux_raid_member", GOTO="md_inc" + +# "noiswmd" on kernel command line stops mdadm from handling +# "isw" (aka IMSM - Intel RAID). +# "nodmraid" on kernel command line stops mdadm from handling +# "isw" or "ddf". +IMPORT{cmdline}="noiswmd" +IMPORT{cmdline}="nodmraid" + +ENV{nodmraid}=="?*", GOTO="md_inc_end" +ENV{ID_FS_TYPE}=="ddf_raid_member", GOTO="md_inc" +ENV{noiswmd}=="?*", GOTO="md_inc_end" +ENV{ID_FS_TYPE}=="isw_raid_member", ACTION!="change", GOTO="md_inc" +GOTO="md_inc_end" + +LABEL="md_inc" + +# remember you can limit what gets auto/incrementally assembled by +# mdadm.conf(5)'s 'AUTO' and selectively whitelist using 'ARRAY' +ACTION=="add|change", IMPORT{program}="/sbin/mdadm --incremental --export $devnode --offroot $env{DEVLINKS}" +ACTION=="remove", ENV{ID_PATH}=="?*", RUN+="/sbin/mdadm -If $name --path $env{ID_PATH}" +ACTION=="remove", ENV{ID_PATH}!="?*", RUN+="/sbin/mdadm -If $name" + +LABEL="md_inc_end" diff --git a/mdadm/pkg.yaml b/mdadm/pkg.yaml new file mode 100644 index 000000000..34e0d1988 --- /dev/null +++ b/mdadm/pkg.yaml @@ -0,0 +1,28 @@ +name: mdadm +variant: scratch +shell: /toolchain/bin/bash +dependencies: + - stage: base + - stage: eudev +steps: + - sources: + - url: http://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-4.2-rc3.tar.gz + destination: mdadm.tar.gz + sha256: 65e26e4c7a45c8dbfbeaa2230181a4226483c4ce0579bb6d2bb25a3bf4656e2b + sha512: d0eb0dd151120c8860def555200a07f6cdf9396bf7e21a8545fae25d1d7d52ffe3ebc7798ab717a554932cb2e553c1483c5db31e99633adfd3211736c891f717 + prepare: + - | + tar -xzf mdadm.tar.gz --strip-components=1 + build: + - | + mkdir -p /run/mdadm + make -j $(nproc) mdadm + install: + - | + mkdir -p /rootfs/sbin /rootfs/usr/lib/udev/rules.d + cp mdadm /rootfs/sbin + cp /pkg/files/udev-md-raid-arrays.rules /rootfs/usr/lib/udev/rules.d/63-md-raid-arrays.rules + cp /pkg/files/udev-md-raid-assembly.rules /rootfs/usr/lib/udev/rules.d/64-md-raid-assembly.rules +finalize: + - from: /rootfs + to: /