Typo
[linux_from_scratch_hints.git] / OLD / devfs+kernel_modules.txt
blob6382e61ea33d8d0ad4f94354f9736a1463f35faf
1 AUTHOR: Mark Ellis (markp.ellis@virgin.net)
3 DATE: 2003-09-23
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: How to use kernel module autoloading with devfs and devfsd
9 DESCRIPTION:
10 Kernel module autoloading with modutils requires a slightly different approach
11 when using devfs rather than a static /dev. This hint explains how to configure
12 your modutils for devfs(d).
14 PREREQUISITES:
15 Almost any system should do, providing you enabled devfs in the kernel.
17 HINT:
18 Devfs is a virtual filesystem, like /proc, that an appropriately configured
19 kernel generates to replace the device nodes found in /dev, used to access the
20 hardware, but you probably already knew that. For more see
22   http://www.atnf.csiro.au/people/rgooch/linux/
24 the kernel docs
26   linux/Documentation/filesystems/devfs
28 and the devfs hint at linuxfromscratch.
30 A common problem when using devfs appears to be the use of auto loaded kernel
31 modules that are associated with device nodes under /dev. It's a chicken and egg
32 problem, modules are loaded when the node is accessed in /dev, but until the
33 module loads there is no device node. This hint attempts to explain how auto
34 loading using devfs is done the way it was intended, the "intended" part being
35 important because there are a number of workarounds, all of which duplicate to a
36 certain extent functionality that is already present.
38 All of this is to my personal understanding, particulary the why's, which I have
39 deduced from scatterings of documentation and the functionality i have found.
40 If anyone knows that it is wrong, mistaken or otherwise, please shout :)
42 Throughout this hint I'm going to use ALSA, the Advanced Linux Sound
43 Architecture modules, as an example, primarily because they are the most complex
44 set of modules i have come across and involve practically everything you need to
45 know about modules, and also because it crops up time and again on the BLFS
46 support mailing list. This hint will probably look like it is actually for ALSA,
47 but everything here should hopefully be applicable to any kernel module.
50 1) Aliasing device nodes to modules
51 -----------------------------------
53 I'm assuming you know the basics of module configuration, particularly aliases,
54 using /etc/modules.conf. If not, go and have a look at the modutils
55 documentation.
57 The ALSA documentation gives a basic setup for autoloading modules using a
58 normal /dev directory, it looks something like this :-
60        alias char-major-116 snd
61        options snd snd_major=116 snd_cards_limit=1
62        alias snd-card-0 snd-<your sound card>
63        options snd-<your sound card> snd_index=0 snd_id="GusPnP"
65 The important part for us is the first line, which essentially says, when a
66 device node is accessed that has a major number of 116, we need the module
67 called snd.o. This won't work with devfs because we dont have the device file
68 until the module is loaded.
70 This issue is addressed by devfsd, the devfs daemon. A lot of people think
71 that devfsd is only needed to provide all those backwards compatible symlinks
72 for non-devfs aware applications, but it also helps fix this non-existent
73 device file problem, which devfs alone cannot do. You'll therefore need to
74 start devfsd at boot, see the appendix if you don't already have it set up.
76 Now for a more helpful alias in modules.conf.
78         alias snd-card-0 snd-<your sound card>
79         alias /dev/snd* snd-card-0
81 ALSA with devfs puts all the native sound device files in the /dev/snd/
82 directory, so now whenever a node in /dev/snd/, or the directory itself, is
83 accessed, and that includes listing the directory, devfsd notices the node
84 does not exist, finds that the node(s) are aliased to module snd-whatever,
85 and requests that the module be loaded. The module creates the device nodes
86 and the application never knows they weren't there a second ago.
89 An alternative to aliasing in modules.conf is available, using the devfsd
90 configuration file /etc/devfsd.conf directly. I prefer the method above, it
91 comes across as being a little more straightforward, but if you want to try
92 something like :-
94         LOOKUP snd MODLOAD snd-<your sound card>
96 in devfsd.conf, this should give similar results.
99 Enabling OSS emulation with ALSA requires a little more work. The ALSA
100 documentation says :-
102         alias sound-slot-0 snd-card-0
103         alias sound-service-0-0 snd-mixer-oss
104         alias sound-service-0-1 snd-seq-oss
105         alias sound-service-0-3 snd-pcm-oss
106         alias sound-service-0-8 snd-seq-oss
107         alias sound-service-0-12 snd-pcm-oss
109 The first number in "sound-service-?-?" corresponds to the number of the sound
110 card, in many cases literally the slot it occupies on the motherboard, and
111 corresponds to the "sound-slot-?" entry.
112 The second number is the minor number of the corresponding device file, so
113 /dev/sound/dsp has a minor number of 3, and requires the snd-pcm-oss module. In
114 devfs speak this translates to :-
116         alias /dev/sound/mixer snd-mixer-oss
117         alias /dev/sound/sequencer* snd-seq-oss
118         alias /dev/sound/dsp* snd-pcm-oss
119         alias /dev/sound/audio* snd-pcm-oss
120         alias /dev/sound/adsp* snd-pcm-oss
121         alias /dev/sound* snd-card-0
123 Note that the least specific match, /dev/sound*, must be at the end of the
124 sequence, or the more specific entries will effectively be ignored.
126 Note that different sound cards will support different features, and these
127 entries may be more than enough or insufficient for your needs. I deduced most of
128 these using an ISA PnP SoundBlaster 16, but the adsp* entry isn't relevant for
129 me, it came out of devices.txt in the kernel documentation, must reading for any
130 LFSer :) If you have problems with specific features of your card under OSS
131 emulation, manually modprobe each oss mudule in turn and see what devices it
132 creates.
134 If you want your entries in devfsd.conf rather than modules.conf :-
136         LOOKUP sound MODLOAD snd-<your sound card>
137         LOOKUP sound/mixer MODLOAD snd-mixer-oss
138         LOOKUP sound/sequencer MODLOAD snd-seq-oss
139         LOOKUP sound/dsp MODLOAD snd-pcm-oss
140         LOOKUP sound/audio MODLOAD snd-pcm-oss
141         LOOKUP sound/adsp MODLOAD snd-pcm-oss
145 You should hopefully now have a setup that will at least auto load modules for
146 sound applications, run as root, that can work with devfs naming schemes.
149 2) Adding entries for backward compatibility
150 --------------------------------------------
152 Alas many applications do not yet support the relatively new naming scheme
153 used by devfs. In some cases it is easy to re-configure these programs
154 to point to the new namespace, and for the rest devfsd will happily create
155 a host of symlinks to point from the old names to the new. However, it must be
156 told which of the old names correspond to modules that need to be loaded, in the
157 same way as the 'true' devices. It's easy to find out what you need, just
158 modprobe the modules by hand and see where the symlinks go.
160 Native ALSA devices all live in /dev/snd/ whether you use devfs or a static
161 /dev, so you'll only need backwards compatibility for OSS devices :-
163         alias /dev/mixer snd-mixer-oss
164         alias /dev/sequencer* snd-seq-oss
165         alias /dev/dsp* snd-pcm-oss
166         alias /dev/audio* snd-pcm-oss
167         alias /dev/adsp* snd-pcm-oss
169         alias /dev/dmfm snd-card-0
170         alias /dev/dmmidi snd-card-0
171         alias /dev/midi00 snd-card-0
173 Notice the last three entries. With the old naming scheme there is no common
174 element we can use to autoload the basic functionality, such as a shared
175 directory name, so each entry must be listed individually.
177 So assuming you remembered to turn on compatibility mode in devfsd (the first
178 REGISTER/UNREGISTER lines in devfsd.conf), accessing /dev/dsp will load the
179 oss module and create a symlink to /dev/sound/dsp.
181 Again, if you'd rather use devfsd.conf :-
183         LOOKUP mixer MODLOAD snd-mixer-oss
184         LOOKUP sequencer MODLOAD snd-seq-oss
185         LOOKUP dsp MODLOAD snd-pcm-oss
186         LOOKUP audio MODLOAD snd-pcm-oss
187         LOOKUP adsp MODLOAD snd-pcm-oss
189         LOOKUP dmfm MODLOAD snd-<your sound card>
190         LOOKUP dmmidi MODLOAD snd-<your sound card>
191         LOOKUP midi00 MODLOAD snd-<your sound card>
195 3) More configuration
196 ---------------------
198 You've got your modules autoloading by device entry, and compatibility
199 symlinks, which is sufficient for many uses.
201 Devfs by default creates device nodes owned by user and group root,
202 with restrictive permissions in most cases, not much use unless you like
203 danger and always login as root :)
205 For our ALSA setup, a good solution is to create an 'audio' group and
206 give its members read/write access to the audio devices. The following
207 in devfsd.conf accomplishes just that:-
209         REGISTER       ^sound$          PERMISSIONS root.audio 0750
210         REGISTER       ^sound/.*        PERMISSIONS root.audio 0660
211         REGISTER       ^snd$            PERMISSIONS root.audio 0750
212         REGISTER       ^snd/.*          PERMISSIONS root.audio 0660
214 Finally, since modules may be loaded and unloaded a number of times,
215 any extra configuration related to devices may be lost, hence the
216 'post-install' and 'pre-remove' entries in modules.conf, which
217 do exectly that, run arbitrary commands after module loading and
218 before unloading. The ALSA sound channels are muted by default,
219 you must unmute them the first time they are used. To retain your
220 volume settings, in modules.conf use :-
222 post-install snd-sb16 /usr/sbin/alsactl restore
223 pre-remove snd-sb16 /usr/sbin/alsactl store
225 which store the settings when the modules are unloaded, and restore
226 them the next time the modules are loaded.
228 For other modules these commands can be anything you like. For example
229 when i hotplug my USB mouse, the hotplug system inserts the
230 appropriate modules, then i have a post-install entry to start gpm.
233 Appendix
234 --------
235 Installing devfsd is easy. Get it from the devfs web page above.
236 After unpacking, edit the GNUmakefile for stuff like CFLAGS if you
237 want, then just:-
239 make
240 make install
242 which puts the daemon in /sbin and a couple of config files in /etc.
244 Make an addition to your bootscripts to run '/sbin/devfsd /dev' as the
245 very first thing that happens. Thats it !
247 The default devfsd.conf enables all those compatibility symlinks. If
248 you don't need them comment out the first REGISTER/UNREGISTER lines.
251 CHANGELOG:
252 [2002-08-15]
253  * Initial hint.
254 [2003-09-23]
255  * updated to new format.
256  * minor text changes.
257  * added /dev/sound* wildcard
258  * new contact email 
259  * more descriptive name
260 [2003-12-02]
261  * removed spurious statement about symlink permissions.