minimal之udev

首先给出udev的主页:http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html

 

1.启动错误信息

使用NFS挂载minimal根文件系统,启动时出现mount nbd*设备失败信息。

分析应该是NFS文件系统注册了多个nbd*设备(可以从/sys/block/目录下查看到),而udev在coldplug处理阶段,会去mount这些设备,导致出现失败信息。

"etc/udev/rules.d/60-persistent-storage.rules"中有这么几行

"etc/udev/rules.d/local.rules"中有这么几行

"etc/udev/scripts/mount.sh"中有这么几行

显然可以在mount.blacklist中解决这个问题,如下所示

主要增加了最后一行。。。

 

2.udev的coldplug模式

内核在启动时已经检测到了系统的硬件设备,并把硬件设备信息通过sysfs内核虚拟文件系统导出。sysfs文件系统由系统初始化脚本挂载到/sys上。

udev是用户空间程序而且在内核启动后才start,因此需要基于sysfs文件系统来模拟热插拔事件。在boot 时,内核在sysfs下为所有的硬件设备创建名为uevent的文件,当udev启动时,它可以读取/sys下面所有的uevent文件并为每个冷插拔设备产生热插拔事件,然后udev再读取这些事件,生成对应的硬件设备文件。由于没有实际的硬件插拔动作,所以这一过程被称为coldplug。

 

3.udev的启动流程

详见"etc/rcS.d/S03udev"脚本。

对该脚本的分析有一点需要注意,就是shell编程中命令的成功执行用'0'表示,而执行失败用'1'表示,在命令行可以使用"echo $?"来获得上一个命令的返回值。与C编程最相悖的是,条件测试语句(譬如if then else)以'0'为真,'1'为假。

 

4.write udev rules

详见udev源码包的"docs/writing_udev_rules/index.html"

"find /sys -name dev" 可以找到需要为之建立规则的硬件设备。

利用udevinfo工具可以获得建立规则时需要的一些详细匹配信息。

 

解释代码: #!/bin/bash # # udev This is a minimal non-LSB version of a UDEV startup script. It # was derived by stripping down the udev-058 LSB version for use # with buildroot on embedded hardware using Linux 2.6.34+ kernels. # # You may need to customize this for your system's resource limits # (including startup time!) and administration. For example, if # your early userspace has a custom initramfs or initrd you might # need /dev much earlier; or without hotpluggable busses (like USB, # PCMCIA, MMC/SD, and so on) your /dev might be static after boot. # # This script assumes your system boots right into the eventual root # filesystem, and that init runs this udev script before any programs # needing more device nodes than the bare-bones set -- /dev/console, # /dev/zero, /dev/null -- that's needed to boot and run this script. # # Check for missing binaries # initscripts are responsible for setting an appropriate path themselves. export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin UDEV_BIN=/sbin/udevd test -x $UDEV_BIN || exit 5 # Check for config file and read it UDEV_CONFIG=/etc/udev/udev.conf test -r $UDEV_CONFIG || exit 6 . $UDEV_CONFIG case "$1" in start) printf "Populating ${udev_root:-/dev} using udev: " printf '\000\000\000\000' > /proc/sys/kernel/hotplug $UDEV_BIN -d || (echo "FAIL" && exit 1) udevadm trigger --subsystem-nomatch=net --action=add udevadm settle echo "done" ;; stop) # Stop execution of events udevadm control --stop-exec-queue killall udevd ;; *) echo "Usage: $0 {start|stop}" exit 1 ;; esac exit 0
最新发布
11-14
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值