diff options
| author | Hongzhi.Song <hongzhi.song@windriver.com> | 2018-04-17 03:03:43 -0400 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-09-17 08:41:44 +0100 |
| commit | 4ca9402c37205df4ea70c154f17b01c91a48176a (patch) | |
| tree | 323483a6ea46e137e3c79f566a942ca3dc7ccc74 | |
| parent | dd29a499a15f4bd043115f53795108ae5eb64240 (diff) | |
| download | poky-4ca9402c37205df4ea70c154f17b01c91a48176a.tar.gz | |
udev-extraconf: Add systemd-mount to udev-extraconf/mount.sh
Udev-extraconf works correctly with sysvinit in the aspect of automounting
block devices. But it has a serious problem in case of systemd. Block devices
automounted by udev is unaccessible to host space(out of udevd's private
namespace). For example, we cannot format those block devices.
e.g.
root@qemux86:~# mkfs.ext4 /dev/sda1
mke2fs 1.43.8 (1-Jan-2018)
/dev/sda1 contains a ext4 file system
last mounted on Tue Apr 3 06:22:41 2018
Proceed anyway? (y,N) y
/dev/sda1 is apparently in use by the system; will not make a filesystem here!
Other distributions has no such problem, because they use a series of rules to
manager block devices. Different types of block devices match different rules.
But udev-extraconf just use one rule, automount.rules, which results in this
problem.
The 'systemd-mount' command is recommended by the systemd community to solve such
problems.
This patch makes use of 'systemd-mount' to solve the above problem.
[YOCTO #12644]
(From OE-Core rev: a0b3389c5afc23f622f793cbad8b4135093e6f08)
(From OE-Core rev: 4af22800a7af4fcb80cafe08d982a4850d9dd2ad)
Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/recipes-core/udev/udev-extraconf/mount.sh | 83 | ||||
| -rw-r--r-- | meta/recipes-core/udev/udev-extraconf_1.1.bb | 3 |
2 files changed, 69 insertions, 17 deletions
diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh index d760328a09..067d4e2a16 100644 --- a/meta/recipes-core/udev/udev-extraconf/mount.sh +++ b/meta/recipes-core/udev/udev-extraconf/mount.sh | |||
| @@ -4,10 +4,28 @@ | |||
| 4 | # | 4 | # |
| 5 | # Attempt to mount any added block devices and umount any removed devices | 5 | # Attempt to mount any added block devices and umount any removed devices |
| 6 | 6 | ||
| 7 | BASE_INIT="`readlink "@base_sbindir@/init"`" | ||
| 8 | INIT_SYSTEMD="@systemd_unitdir@/systemd" | ||
| 9 | |||
| 10 | if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then | ||
| 11 | # systemd as init uses systemd-mount to mount block devices | ||
| 12 | MOUNT="/usr/bin/systemd-mount" | ||
| 13 | UMOUNT="/usr/bin/systemd-umount" | ||
| 14 | |||
| 15 | if [ -x $MOUNT ] && [ -x $UMOUNT ]; | ||
| 16 | then | ||
| 17 | logger "Using systemd-mount to finish mount" | ||
| 18 | else | ||
| 19 | logger "Linux init is using systemd, so please install systemd-mount to finish mount" | ||
| 20 | exit 1 | ||
| 21 | fi | ||
| 22 | else | ||
| 23 | MOUNT="/bin/mount" | ||
| 24 | UMOUNT="/bin/umount" | ||
| 25 | fi | ||
| 7 | 26 | ||
| 8 | MOUNT="/bin/mount" | ||
| 9 | PMOUNT="/usr/bin/pmount" | 27 | PMOUNT="/usr/bin/pmount" |
| 10 | UMOUNT="/bin/umount" | 28 | |
| 11 | for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*` | 29 | for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*` |
| 12 | do | 30 | do |
| 13 | if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ]; | 31 | if [ ` expr match "$DEVNAME" "$line" ` -gt 0 ]; |
| @@ -17,7 +35,35 @@ do | |||
| 17 | fi | 35 | fi |
| 18 | done | 36 | done |
| 19 | 37 | ||
| 20 | automount() { | 38 | automount_systemd() { |
| 39 | name="`basename "$DEVNAME"`" | ||
| 40 | |||
| 41 | [ -d "/run/media/$name" ] || mkdir -p "/run/media/$name" | ||
| 42 | |||
| 43 | MOUNT="$MOUNT -o silent" | ||
| 44 | |||
| 45 | # If filesystemtype is vfat, change the ownership group to 'disk', and | ||
| 46 | # grant it with w/r/x permissions. | ||
| 47 | case $ID_FS_TYPE in | ||
| 48 | vfat|fat) | ||
| 49 | MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`" | ||
| 50 | ;; | ||
| 51 | # TODO | ||
| 52 | *) | ||
| 53 | ;; | ||
| 54 | esac | ||
| 55 | |||
| 56 | if ! $MOUNT --no-block -t auto $DEVNAME "/run/media/$name" | ||
| 57 | then | ||
| 58 | #logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!" | ||
| 59 | rm_dir "/run/media/$name" | ||
| 60 | else | ||
| 61 | logger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful" | ||
| 62 | touch "/tmp/.automount-$name" | ||
| 63 | fi | ||
| 64 | } | ||
| 65 | |||
| 66 | automount() { | ||
| 21 | name="`basename "$DEVNAME"`" | 67 | name="`basename "$DEVNAME"`" |
| 22 | 68 | ||
| 23 | ! test -d "/run/media/$name" && mkdir -p "/run/media/$name" | 69 | ! test -d "/run/media/$name" && mkdir -p "/run/media/$name" |
| @@ -26,7 +72,7 @@ automount() { | |||
| 26 | then | 72 | then |
| 27 | MOUNT="$MOUNT -o silent" | 73 | MOUNT="$MOUNT -o silent" |
| 28 | fi | 74 | fi |
| 29 | 75 | ||
| 30 | # If filesystem type is vfat, change the ownership group to 'disk', and | 76 | # If filesystem type is vfat, change the ownership group to 'disk', and |
| 31 | # grant it with w/r/x permissions. | 77 | # grant it with w/r/x permissions. |
| 32 | case $ID_FS_TYPE in | 78 | case $ID_FS_TYPE in |
| @@ -68,23 +114,26 @@ if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_t | |||
| 68 | elif [ -x $MOUNT ]; then | 114 | elif [ -x $MOUNT ]; then |
| 69 | $MOUNT $DEVNAME 2> /dev/null | 115 | $MOUNT $DEVNAME 2> /dev/null |
| 70 | fi | 116 | fi |
| 71 | 117 | ||
| 72 | # If the device isn't mounted at this point, it isn't | 118 | # If the device isn't mounted at this point, it isn't |
| 73 | # configured in fstab (note the root filesystem can show up as | 119 | # configured in fstab (note the root filesystem can show up as |
| 74 | # /dev/root in /proc/mounts, so check the device number too) | 120 | # /dev/root in /proc/mounts, so check the device number too) |
| 75 | if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then | 121 | if expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; then |
| 76 | grep -q "^$DEVNAME " /proc/mounts || automount | 122 | if [ "`basename $MOUNT`" = "systemd-mount" ];then |
| 77 | fi | 123 | grep -q "^$DEVNAME " /proc/mounts || automount_systemd |
| 124 | else | ||
| 125 | grep -q "^$DEVNAME " /proc/mounts || automount | ||
| 126 | fi | ||
| 127 | fi | ||
| 78 | fi | 128 | fi |
| 79 | 129 | ||
| 80 | |||
| 81 | if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then | 130 | if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then |
| 82 | for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " ` | 131 | for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " ` |
| 83 | do | 132 | do |
| 84 | $UMOUNT $mnt | 133 | $UMOUNT $mnt |
| 85 | done | 134 | done |
| 86 | 135 | ||
| 87 | # Remove empty directories from auto-mounter | 136 | # Remove empty directories from auto-mounter |
| 88 | name="`basename "$DEVNAME"`" | 137 | name="`basename "$DEVNAME"`" |
| 89 | test -e "/tmp/.automount-$name" && rm_dir "/run/media/$name" | 138 | test -e "/tmp/.automount-$name" && rm_dir "/run/media/$name" |
| 90 | fi | 139 | fi |
diff --git a/meta/recipes-core/udev/udev-extraconf_1.1.bb b/meta/recipes-core/udev/udev-extraconf_1.1.bb index 43a1cff731..90f933d981 100644 --- a/meta/recipes-core/udev/udev-extraconf_1.1.bb +++ b/meta/recipes-core/udev/udev-extraconf_1.1.bb | |||
| @@ -29,6 +29,9 @@ do_install() { | |||
| 29 | install -d ${D}${sysconfdir}/udev/scripts/ | 29 | install -d ${D}${sysconfdir}/udev/scripts/ |
| 30 | 30 | ||
| 31 | install -m 0755 ${WORKDIR}/mount.sh ${D}${sysconfdir}/udev/scripts/mount.sh | 31 | install -m 0755 ${WORKDIR}/mount.sh ${D}${sysconfdir}/udev/scripts/mount.sh |
| 32 | sed -i 's|@systemd_unitdir@|${systemd_unitdir}|g' ${D}${sysconfdir}/udev/scripts/mount.sh | ||
| 33 | sed -i 's|@base_sbindir@|${base_sbindir}|g' ${D}${sysconfdir}/udev/scripts/mount.sh | ||
| 34 | |||
| 32 | install -m 0755 ${WORKDIR}/network.sh ${D}${sysconfdir}/udev/scripts | 35 | install -m 0755 ${WORKDIR}/network.sh ${D}${sysconfdir}/udev/scripts |
| 33 | } | 36 | } |
| 34 | 37 | ||
