udev-extraconf: update mount scripts to support systemd

The current scripts used the standard mount binary at /bin/mount
for mounting the partitions. Systemd however seems to have a monitor
that eventually umounts such partitions if not mounted by systemd's
specific command 'systemd-mount`.

For platforms using systemd, we need to use this binary together with
parameter --no-block so that partitions are mounted correctly during
the boot process.

This commit merges the two scripts for Digi-handled partitions into
just one:

	mount_bootparts.sh
                          \
                           +--> mount_digiparts.sh
                          /
        mount_partition.sh

The merged script:
 - checks if running with systemd, to use its binary.
 - checks if running with busybox, to not use the unsupported '-o'
   attribute.
 - checks if mounting the 'linux' partition, to mount it read-only.
 - checks for already-attached UBI devices, to avoid re-attaching.

This commit also combines the Digi-handled partitions (linux, update)
into the same udev rule, to simplify it, and breaks the rules lines
for readability.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>

https://jira.digi.com/browse/DEL-6744
This commit is contained in:
Hector Palacios 2019-09-12 16:37:30 +02:00
parent b30c5fa07e
commit 435e085690
5 changed files with 102 additions and 85 deletions

View File

@ -13,19 +13,17 @@
# %% the '%' char itself # %% the '%' char itself
# #
# Boot partitions # Digi-mounted partitions: linux, update
SUBSYSTEM=="block", ENV{ID_PART_ENTRY_NAME}=="linux*", ACTION=="add", RUN+="/etc/udev/scripts/mount_bootparts.sh", GOTO="automount_rules_end" SUBSYSTEM=="block", ENV{ID_PART_ENTRY_NAME}=="linux*|update*", ACTION=="add", RUN+="/etc/udev/scripts/mount_digiparts.sh", GOTO="automount_rules_end"
SUBSYSTEM=="mtd", ATTRS{name}=="linux*|update*", ACTION=="add", RUN+="/etc/udev/scripts/mount_digiparts.sh", GOTO="automount_rules_end"
# Update partition # Avoid mounting recovery partition
SUBSYSTEM=="block", ENV{ID_PART_ENTRY_NAME}=="update*", ACTION=="add", RUN+="/etc/udev/scripts/mount_partition.sh 'update'", GOTO="automount_rules_end"
SUBSYSTEM=="mtd", ATTRS{name}=="update", ACTION=="add", RUN+="/etc/udev/scripts/mount_partition.sh 'update'", GOTO="automount_rules_end"
# Recovery partition
SUBSYSTEM=="block", ENV{ID_PART_ENTRY_NAME}=="recovery*", ACTION=="add", GOTO="automount_rules_end" SUBSYSTEM=="block", ENV{ID_PART_ENTRY_NAME}=="recovery*", ACTION=="add", GOTO="automount_rules_end"
SUBSYSTEM=="mtd", ATTRS{name}=="recovery", ACTION=="add", GOTO="automount_rules_end" SUBSYSTEM=="mtd", ATTRS{name}=="recovery*", ACTION=="add", GOTO="automount_rules_end"
# Media automounting # Media automounting
SUBSYSTEM=="block", ACTION=="add" RUN+="/etc/udev/scripts/mount.sh" SUBSYSTEM=="block", ACTION=="add" RUN+="/etc/udev/scripts/mount.sh"
SUBSYSTEM=="block", ACTION=="remove" RUN+="/etc/udev/scripts/mount.sh" SUBSYSTEM=="block", ACTION=="remove" RUN+="/etc/udev/scripts/mount.sh"
SUBSYSTEM=="block", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1" RUN+="/etc/udev/scripts/mount.sh" SUBSYSTEM=="block", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1" RUN+="/etc/udev/scripts/mount.sh"
LABEL="automount_rules_end" LABEL="automount_rules_end"

View File

@ -1,27 +0,0 @@
#!/bin/sh
#===============================================================================
#
# mount_bootparts.sh
#
# Copyright (C) 2014 by Digi International Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# !Description: Attempt to mount boot partitions read-only (called from udev)
#
#===============================================================================
MOUNT="/bin/mount"
# Use 'silent' if util-linux's mount (busybox's does not support that option)
[ "$(readlink ${MOUNT})" = "/bin/mount.util-linux" ] && MOUNT="${MOUNT} -o silent"
MOUNTPOINT="/mnt/${ID_PART_ENTRY_NAME}"
mkdir -p ${MOUNTPOINT}
if ! ${MOUNT} -t auto -r ${DEVNAME} ${MOUNTPOINT}; then
logger -t udev "mount_bootparts.sh: mount ${DEVNAME} under ${MOUNTPOINT} failed!"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi

View File

@ -0,0 +1,92 @@
#!/bin/sh
#===============================================================================
#
# mount_bootparts.sh
#
# Copyright (C) 2014-2019 by Digi International Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# !Description: Attempt to mount boot partitions read-only (called from udev)
#
#===============================================================================
BASE_INIT="$(readlink -f "@base_sbindir@/init")"
INIT_SYSTEMD="@systemd_unitdir@/systemd"
if [ "${SUBSYSTEM}" = "block" ]; then
PARTNAME="${ID_PART_ENTRY_NAME}"
elif [ "${SUBSYSTEM}" = "mtd" ]; then
MTDN="$(echo ${DEVNAME} | cut -f 3 -d /)"
PARTNAME="$(grep ${MTDN} /proc/mtd | sed -ne 's,.*"\(.*\)",\1,g;T;p')"
fi
MOUNT_PARAMS="-o silent"
# Mount 'linux' partition as read-only
if [ "${PARTNAME}" = "linux" ]; then
MOUNT_PARAMS="${MOUNT_PARAMS} -o ro"
fi
if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then
# systemd as init uses systemd-mount to mount block devices
MOUNT="/usr/bin/systemd-mount"
MOUNT_PARAMS="${MOUNT_PARAMS} --no-block"
if [ -x "$MOUNT" ];
then
logger "Using systemd-mount to finish mount"
else
logger "Linux init is using systemd, so please install systemd-mount to finish mount"
exit 1
fi
else
MOUNT="/bin/mount"
if [ "$(readlink ${MOUNT})" != "/bin/mount.util-linux" ]; then
# Busybox mount. Clear default params
MOUNT_PARAMS=""
# Mount 'linux' partition as read-only
if [ "${PARTNAME}" = "linux" ]; then
MOUNT_PARAMS="${MOUNT_PARAMS} -r"
fi
fi
fi
# Create mount point if needed
MOUNTPOINT="/mnt/${PARTNAME}"
[ -d "${MOUNTPOINT}" ] || mkdir -p ${MOUNTPOINT}
if [ "${SUBSYSTEM}" = "block" ]; then
if ! ${MOUNT} -t auto ${MOUNT_PARAMS} ${DEVNAME} ${MOUNTPOINT}; then
logger -t udev "ERROR: Could not mount ${DEVNAME} under ${MOUNTPOINT}"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi
elif [ "${SUBSYSTEM}" = "mtd" ]; then
# Before attaching, find out if partition already attached
MTD_NUM="$(echo ${MTDN} | sed -ne 's,.*mtd\([0-9]\+\),\1,g;T;p')"
for ubidev in /sys/devices/virtual/ubi/*; do
echo "${ubidev}" | grep -qs '/sys/devices/virtual/ubi/\*' && continue
mtd_att="$(cat ${ubidev}/mtd_num)"
if [ "${mtd_att}" = "${MTD_NUM}" ]; then
dev_number="$(echo ${ubidev} | sed -ne 's,.*ubi\([0-9]\+\),\1,g;T;p')"
fi
done
# If not already attached, attach and get UBI device number
if [ -z "${dev_number}" ]; then
dev_number="$(ubiattach -p ${DEVNAME} 2>/dev/null | sed -ne 's,.*device number \([0-9]\).*,\1,g;T;p' 2>/dev/null)"
fi
# Check if volume exists.
if ubinfo /dev/ubi${dev_number} -N ${PARTNAME} >/dev/null 2>&1; then
# Mount the volume.
if ! mount -t ubifs ubi${dev_number}:${PARTNAME} ${MOUNT_PARAMS} ${MOUNTPOINT}; then
logger -t udev "ERROR: Could not mount '${PARTNAME}' partition"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi
else
logger -t udev "ERROR: Could not mount '${PARTNAME}' partition, volume not found"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi
fi

View File

@ -1,46 +0,0 @@
#!/bin/sh
#===============================================================================
#
# mount_partition.sh
#
# Copyright (C) 2017 by Digi International Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# !Description: Attempt to mount the partition triggered by udev
#
#===============================================================================
MOUNT="/bin/mount"
PARTITION_NAME="${1}"
MOUNTPOINT="/mnt/${PARTITION_NAME}"
# Use 'silent' if util-linux's mount (busybox's does not support that option)
[ "$(readlink ${MOUNT})" = "/bin/mount.util-linux" ] && MOUNT="${MOUNT} -o silent"
if mkdir -p "${MOUNTPOINT}" && ! mountpoint -q "${MOUNTPOINT}"; then
if [ "${SUBSYSTEM}" = "block" ]; then
FSTYPE="$(blkid ${DEVNAME} | sed -e 's,.*TYPE="\([^"]\+\)".*,\1,g')"
if ! mount ${FSTYPE:+-t ${FSTYPE}} "${DEVNAME}" "${MOUNTPOINT}"; then
logger -t udev "ERROR: Could not mount '${PARTITION_NAME}' partition"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi
elif [ "${SUBSYSTEM}" = "mtd" ]; then
# Attach and get UBI device number
dev_number="$(ubiattach -p ${DEVNAME} 2>/dev/null | sed -ne 's,.*device number \([0-9]\).*,\1,g;T;p' 2>/dev/null)"
# Check if volume exists.
if ubinfo "/dev/ubi${dev_number}" -N "${PARTITION_NAME}" >/dev/null 2>&1; then
# Mount the volume.
if ! mount -t ubifs "ubi${dev_number}:${PARTITION_NAME}" "${MOUNTPOINT}"; then
logger -t udev "ERROR: Could not mount '${PARTITION_NAME}' partition"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi
else
logger -t udev "ERROR: Could not mount '${PARTITION_NAME}' partition, volume not found"
rmdir --ignore-fail-on-non-empty ${MOUNTPOINT}
fi
fi
fi

View File

@ -3,15 +3,15 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
SRC_URI += " \ SRC_URI += " \
file://mount_bootparts.sh \ file://mount_digiparts.sh \
file://mount_partition.sh \
file://81-spi-spidev.rules \ file://81-spi-spidev.rules \
file://blacklist.conf \ file://blacklist.conf \
" "
do_install_append() { do_install_append() {
install -m 0755 ${WORKDIR}/mount_bootparts.sh ${D}${sysconfdir}/udev/scripts/ install -m 0755 ${WORKDIR}/mount_digiparts.sh ${D}${sysconfdir}/udev/scripts/
install -m 0755 ${WORKDIR}/mount_partition.sh ${D}${sysconfdir}/udev/scripts/ sed -i -e 's|@base_sbindir@|${base_sbindir}|g' ${D}${sysconfdir}/udev/scripts/mount_digiparts.sh
sed -i -e 's|@systemd_unitdir@|${systemd_unitdir}|g' ${D}${sysconfdir}/udev/scripts/mount_digiparts.sh
install -m 0644 ${WORKDIR}/81-spi-spidev.rules ${D}${sysconfdir}/udev/rules.d/ install -m 0644 ${WORKDIR}/81-spi-spidev.rules ${D}${sysconfdir}/udev/rules.d/
# Bluetooth tty symlink # Bluetooth tty symlink