- 論壇徽章:
- 5
|
- linux 傳統(tǒng)上使用靜態(tài)設備創(chuàng)建方法,因此大量設備節(jié)點在 /dev 下創(chuàng)建(有時上千個),而不管相應的硬件設備是否真正存在。通常這由一個MAKEDEV腳本,組成它由許多calls of mknod program with the revelant major and minor device number for每一個世界上可能存在的設備。采用udev的方法,只有被kernel檢測到的設備才會get devices nodes created for them.因為這些設備節(jié)點在每次系統(tǒng)啟動時被創(chuàng)建,他們會被stored在a ramfs(a file system in memory,does not take up any disk space).設備節(jié)點不需要much 磁盤空間,因此
- the memory that is used 可以忽略。
- 1:history
- 在2.4版本的kernel中,一種新文件系統(tǒng)called devfs被添加了進去。盡管它在kernel源碼中出現(xiàn),然而這種動態(tài)創(chuàng)建設備的方法從未收到壓倒性的支持from core kernel開發(fā)者;
- devfs 的方法主要問題是 the way:設備檢測,創(chuàng)建,命名。設備節(jié)點命名,可能是最critical的.It is generally accepted that 設備名允許是可配置的,then設備命名策略應該up to一個系統(tǒng)管理員,not 被欺騙by 特殊的開發(fā)者。devfs文件系統(tǒng)同時還忍受著一個紊亂情況,為它的design所固有,且不能被fix,若無實質(zhì)的修改to kernel.現(xiàn)由于缺乏維護已被deprecated.
- 在2.6版本的kernel中,出現(xiàn)了一種叫sysfs的新虛擬文件系統(tǒng)。sysfs的 任務是export系統(tǒng)架構 to 用戶空間進程。有了這種用戶空間visible表示法,the possiblity of seeing a userspace replacement for devfs 變得更加現(xiàn)實。
- 2:udev 執(zhí)行
- sysfs怎樣知道設備出現(xiàn) 在系統(tǒng)?應該使用什么設備號?對于被編進kernel的driver,當被kernel監(jiān)測到時,直接注冊目標with sysfs。使用模塊方式編譯的,當模塊被load時,如前。once sysfs文件系統(tǒng)被mounted (on /sys),the data which the built-in drivers registered with sysfs are available to userspace process and to udev for device node creation.
- udev初始化腳本創(chuàng)建這些 設備節(jié)點當linux boot時;這個腳本starts with 注冊/sbin/udev/ 作為一個 hotplug事件管理者。熱插拔事件不應該發(fā)生在這個過程中,然而udev is registered just in case they do occur.然后udevstart program walk through the /sys filesystem and 創(chuàng)建符合描述的設備在/dev。例如:/sys/class/tty/vcs/dev/包括string "7:0".這個字符串被udevstart使用來創(chuàng)建/dev/vcs,主設備號7and此設備號0。每一個udevstart創(chuàng)建的設備的權限設置來自/etc/udev.d/permission.d/目錄。這些numbered(有限的) 基本相似LFS bootscripts.如果找不到創(chuàng)建的設備權限文件,默認perissions to 600 and ownership to root:root./dev目錄下創(chuàng)建的節(jié)點根據(jù) /etc/udev/rules.d/目錄下的文件來configured.
- 當一個新設備連 接被kernel監(jiān)測到,kernel會產(chǎn)生一個hotplug event 并查找/proc/sys/kernel/hotplug去找出管理設備連接的用戶空間程序。udev初始化腳本注冊udev as this hander.當hotplug events發(fā)生時,kernel通知udev 去檢測/sys 文件系統(tǒng)附屬于這個新設備的信息并create 它的/dev/入口。
- ?這帶給我們一個問題:exists with udev,and likewise with devfs before it.?就像先有雞還是先有蛋。大部分linux distrubtions
- 管 理加載模塊通過/etc/modules.conf.access to 設備節(jié)點引起相應的kernel模塊來加載。然而對于udev,這種方法不能正常工作,因為模塊沒有加載時,設備節(jié)點不存在。為了解決這個問題,模塊腳本加到了lfs-bootscripts包中,和/etc/sysconfig/modules在一起。通過添加module names到module file中,這些模塊在計算機啟動時被加載。這樣,udev就可以去檢測設備并創(chuàng)建相應的設備節(jié)點。
- 3:處理可熱插拔/動態(tài)設備
- 當 你插入一個設備,比如usb mp3 player,內(nèi)核辨認出設備連接同時產(chǎn)生一個熱插拔事件。如果驅(qū)動已經(jīng)loaded(不管是編進kernel還是通過s05modules bootscript加載),udev將被調(diào)用來創(chuàng)建相關的設備節(jié)點,根據(jù)sysfs data in /sys.如果剛插入的設備驅(qū)動以模塊形式然而并未加載,那么剛attach to system 的設備只會引起kernel總線驅(qū)動產(chǎn)生一個熱插拔事件通知用戶空間一個新設備的連接and它不attached to a driver.結(jié)果,什么都沒有發(fā)生,device依然不能使用。
- 如果建立一個system,that具有大量的以模塊形式編譯的驅(qū)動,使用s05modules并不實際。the hotplug package([url]http://linux-hotplug.sourceforge.net[/url])會顯得非常有價值。當此包安裝后,它會響應前述的 kernel總線驅(qū)動hotplug事件。此包將加載相應的模塊并為設備創(chuàng)建節(jié)點。
- 4:創(chuàng)建設備的問題
- 自動創(chuàng)建設備節(jié)點時常遇到的一些問題
- 1)A kernel driver may not exports its data to sysfs
- 當 使用第三方驅(qū)動(在kernel source tree 之外)時常遇到這種問題。這些驅(qū)動end up時沒有創(chuàng)建設備節(jié)點。使用/etc/sysconfig/creatfiles 配置文件to 人工創(chuàng)建設備。參考devices.txt文件(在kernel文檔中)或者驅(qū)動文檔來找出正確的major/minor設備號。
- 2)無硬件設備 is required.這種很常見with the advanced linux sound architecture(ALSA) project's open sound system(oss) compatibility 模塊.這種形式的驅(qū)動可以使用以下下面兩種方法來管理:
- *將module names 加到 /etc/sysconfig/modules;
- * 使用"install"line 在/etc/modprobe.conf中。This tells the modprobe command "when loading this module, also load this other module,at the same time."例如
- install snd-pcm modprobe -i snd-pcm;modprobe snd-pcm-oss;true
- 當系統(tǒng)中有加載snd-pcm驅(qū)動的請求時,這會使系統(tǒng)加載both snd-pcm and snd-pcm-oss modules.
- 5:進一步一些參考資料
- [url]http://fedora.redhat.com/docs/udev/[/url]
- [url]http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html[/url]
- [url]http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf[/url]
- [url]http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-FAQ[/url]
復制代碼 |
|