如何使用mdev
之前都是使用udev,為了減少使用空間,採用busybox的mdev
更新記錄
item | note |
---|---|
20170118 | 第一版 |
目錄
mdev
mdev功能:根據kernel訊息來建立dev目錄內容
mdev使用方式:
- /bin/mdev >/proc/sys/kernel/hotplug
- 設定/etc/mdev.conf
[-]DEVNAME UID:GID PERM [>|=PATH] [@|$|*PROG]
當有週邊載入時,kernel由此(/proc/sys/kernel/hotplug)通知mdev
mdev在根據sys相關訊息,來產生dev目錄
在建立dev目錄或移除時會都參考mdev.conf設定
- mdev.conf
修改/etc/mdev.conf配置文件1
2
3
4格式: <device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]
@ 创建了设备之后运行
$ 删除设备之前运行
* 在创建设备之后和删除设备之前运行
mdev 板子設定
/proc/sys/kernel/hotplug :
/rootfs/etc/rcS設定
1
2
3mount -a
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -sfstab
1
2
3
4proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
tmpfs /var tmpfs defaults,size=16M 0 0hi3536上面的kernel(3.10.0), 記得要移除devtmpfs,此時mdev才會正常工作
mdev test
/etc/mdev.conf
1
sd.* 0:0 0600 */etc/add_remove_log.sh
add_remove_log.sh
1
2
3
4#/bin/sh
echo "======" >> /tmp/mdev.log
env >> /tmp/mdev.loglog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59~ # cat /tmp/mdev.log
======
======
DEVNAME=sda
ACTION=add
NPARTS=1
HOME=/
SEQNUM=627
MAJOR=8
MDEV=sda
DEVPATH=/devices/platform/hiusb-ehci.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0/block/sda
SUBSYSTEM=block
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MINOR=0
PWD=/dev
DEVTYPE=disk
DEVNAME=sda1
ACTION=add
HOME=/
SEQNUM=628
PARTNAME=Linux filesystem
MAJOR=8
MDEV=sda1
DEVPATH=/devices/platform/hiusb-ehci.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0/block/sda/sda1
SUBSYSTEM=block
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MINOR=1
PARTN=1
PWD=/dev
DEVTYPE=partition
======
DEVNAME=sda1
ACTION=remove
HOME=/
SEQNUM=633
PARTNAME=Linux filesystem
MAJOR=8
MDEV=sda1
DEVPATH=/devices/platform/hiusb-ehci.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0/block/sda/sda1
SUBSYSTEM=block
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MINOR=1
PARTN=1
PWD=/dev
DEVTYPE=partition
======
DEVNAME=sda
ACTION=remove
NPARTS=0
HOME=/
SEQNUM=635
MAJOR=8
MDEV=sda
DEVPATH=/devices/platform/hiusb-ehci.0/usb1/1-2/1-2:1.0/host4/target4:0:0/4:0:0:0/block/sda
SUBSYSTEM=block
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MINOR=0
PWD=/dev
DEVTYPE=disk
mdev help
- mdev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20~ # mdev --help
BusyBox v1.20.2 (2017-01-09 05:57:30 UTC) multi-call binary.
Usage: mdev [-s]
mdev -s is to be run during boot to scan /sys and populate /dev.
Bare mdev is a kernel hotplug helper. To activate it:
echo /sbin/mdev >/proc/sys/kernel/hotplug
It uses /etc/mdev.conf with lines
[-]DEVNAME UID:GID PERM [>|=PATH]|[!] [@|$|*PROG]
where DEVNAME is device name regex, @major,minor[-minor2], or
environment variable regex. A common use of the latter is
to load modules for hotplugged devices:
$MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"
If /dev/mdev.seq file exists, mdev will wait for its value
to match $SEQNUM variable. This prevents plug/unplug races.
To activate this feature, create empty /dev/mdev.seq at boot.