Skip to content

Commit

Permalink
feat: add mdadm package
Browse files Browse the repository at this point in the history
The mdadm/udev-rules help to activate soft raid on boot time or then it attached.
  • Loading branch information
sergelogvinov committed Nov 20, 2021
1 parent cea93f1 commit dfaf8a9
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
36 changes: 36 additions & 0 deletions mdadm/files/udev-md-raid-arrays.rules
Original file line number Diff line number Diff line change
@@ -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"
30 changes: 30 additions & 0 deletions mdadm/files/udev-md-raid-assembly.rules
Original file line number Diff line number Diff line change
@@ -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"
28 changes: 28 additions & 0 deletions mdadm/pkg.yaml
Original file line number Diff line number Diff line change
@@ -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: /

0 comments on commit dfaf8a9

Please sign in to comment.