Typo
[linux_from_scratch_hints.git] / OLD / devfs+modules.txt
blobe99ab2d0cd8a431d8689f5c8ef544f8386b8d284
1 TITLE:          Devfs with kernel modules
2 LFS VERSION:    All
3 AUTHOR:         Mark Ellis (mark.uzumati@virgin.net)
5 SYNOPSIS:
6         How to use kernel module autoloading with devfs and devfsd
8 HINT:
9 --------------------------------------------------------------------------------
10 Devfs is a virtual filesystem, like /proc, that an appropriately configured
11 kernel generates to replace the device nodes found in /dev, used to access the
12 hardware, but you probably already knew that. For more see
14 http://www.atnf.csiro.au/people/rgooch/linux/
16 and the kernel docs (linux/Documentation/filesystems/devfs).
18 A common problem when using devfs appears to be the use of auto loaded kernel
19 modules that provide device nodes under /dev. It's a chicken and egg problem,
20 modules are loaded when the node is accessed in /dev, but until the module loads
21 there is no device node. This hint attempts to explain how auto loading using
22 devfs is done the way it was intended, the "intended" part being important
23 because there are a number of workarounds, all of which duplicate to a certain
24 extent functionality that is already present.
26 All of this is to my personal understanding, particulary the why's which I have
27 deduced from scatterings of documentation and the functionality i have found,
28 if anyone knows that it is wrong, mistaken or otherwise, please shout :)
30 Throughout this hint I'm going to use ALSA, the Advanced Linux Sound
31 Architecture modules, as an example, primarily because they are the most complex
32 set of modules i have come across and involve practically everything you need to
33 know about modules, and also because it crops up time and again on the BLFS
34 support mailing list. This hint will probably look like it is actually for ALSA,
35 but everything here should hopefully be applicable to any kernel module.
38 1) Aliasing device nodes to modules
39 -----------------------------------
41 I'm assuming you know the basics of module configuration, particularly aliases,
42 using /etc/modules.conf. If not, go and have a look at the modutils
43 documentation.
45 The ALSA documentation gives a basic setup for autoloading modules using a
46 normal /dev directory, it looks something like this :-
48        alias char-major-116 snd
49        options snd snd_major=116 snd_cards_limit=1
50        alias snd-card-0 snd-<your sound card>
51        options snd-<your sound card> snd_index=0 snd_id="GusPnP"
53 The important part for us is the first line, which essentially says, when a
54 device node is accessed that has a major number of 116, we need the module
55 called snd.o. This won't work with devfs because we dont have the device file
56 until the module is loaded.
58 This is the one of the functions associated with devfsd, the devfs daemon. A lot
59 of people think that devfsd is only needed to provide all those backwards
60 compatible symlinks for non-devfs aware applications, but it also helps fix this
61 non-existent device file problem, which devfs alone cannot do. You'll therefore
62 need to start devfsd at boot, see the appendix if you don't already have it
63 set up.
65 Now for a more helpful alias in modules.conf.
67         alias snd-card-0 snd-<your sound card>
68         alias /dev/snd* snd-card-0
70 ALSA with devfs puts all the native sound device files in the /dev/snd/
71 directory, so now whenever a node in /dev/snd/ is accessed, and that includes
72 listing the directory, devfsd notices the node does not exist, finds that the
73 node(s) are aliased to snd-whatever, and requests that the module be loaded.
74 The modules create the devices and the application doesn't know they weren't
75 there a second ago.
78 An alternative to aliasing in modules.conf is available, using the devfsd
79 configuration file /etc/devfsd.conf directly. I prefer the method above, it
80 comes across as being a little more straightforward, but if you want to try
81 something like :-
83         LOOKUP snd MODLOAD snd-<your sound card>
85 in devfsd.conf, this should give similar results.
88 Enabling OSS emulation with ALSA requires a little more work. The ALSA
89 documentation says :-
91         alias sound-slot-0 snd-card-0
92         alias sound-service-0-0 snd-mixer-oss
93         alias sound-service-0-1 snd-seq-oss
94         alias sound-service-0-3 snd-pcm-oss
95         alias sound-service-0-8 snd-seq-oss
96         alias sound-service-0-12 snd-pcm-oss
98 The first number in "sound-service-?-?" corresponds to the number of the sound
99 card, in many cases literally the slot it occupies on the motherboard, and
100 corresponds to the "sound-slot-?" entry.
101 The second number is the minor number of the corresponding device file, so
102 /dev/sound/dsp has a minor number of 3, and requires the snd-pcm-oss module. In
103 devfs speak this translates to :-
105         alias /dev/sound snd-card-0
106         alias /dev/sound/mixer snd-mixer-oss
107         alias /dev/sound/sequencer* snd-seq-oss
108         alias /dev/sound/dsp* snd-pcm-oss
109         alias /dev/sound/audio* snd-pcm-oss
110         alias /dev/sound/adsp* snd-pcm-oss
112 Note that different sound cards will support different features, and these
113 entries may be more than enough or insufficient for your needs. I deduced most of
114 these using an ISA PnP SoundBlaster 16, but the adsp* entry isn't relevant for
115 me, it came out of devices.txt in the kernel documentation, must reading for any
116 LFSer :) If you have problems with specific features of your card under OSS
117 emulation, manually modprobe each oss mudule in turn and see what devices it
118 creates.
120 If you want your entries in devfsd.conf rather than modules.conf :-
122         LOOKUP sound MODLOAD snd-<your sound card>
123         LOOKUP sound/mixer MODLOAD snd-mixer-oss
124         LOOKUP sound/sequencer MODLOAD snd-seq-oss
125         LOOKUP sound/dsp MODLOAD snd-pcm-oss
126         LOOKUP sound/audio MODLOAD snd-pcm-oss
127         LOOKUP sound/adsp MODLOAD snd-pcm-oss
131 You should hopefully now have a setup that will at least auto load modules for
132 sound applications run as root that can work with devfs naming schemes.
135 2) Adding entries for backward compatibility
136 --------------------------------------------
138 Alas many (most ?) applications do not yet support the relatively new naming
139 scheme used by devfs. In some cases it is easy to re-configure these programs
140 to point to the new namespace, and for the rest devfsd will happily create
141 a host of symlinks to point from the old names to the new. However, it must be
142 told which of the old names correspond to modules that need to be loaded, in the
143 same way as the 'true' devices. It's easy to find out what you need, just
144 modprobe the modules by hand and see where the symlinks go.
146 Native ALSA devices all live in /dev/snd/ whether you use devfs or a static
147 /dev, so you'll only need backwards compatibility for OSS devices :-
149         alias /dev/mixer snd-mixer-oss
150         alias /dev/sequencer* snd-seq-oss
151         alias /dev/dsp* snd-pcm-oss
152         alias /dev/audio* snd-pcm-oss
153         alias /dev/adsp* snd-pcm-oss
155         alias /dev/dmfm snd-card-0
156         alias /dev/dmmidi snd-card-0
157         alias /dev/midi00 snd-card-0
159 Notice the last three entries. With the old naming scheme there is no common
160 element we can use to autoload the basic functionality, such as a shared
161 directory name, so each entry must be listed individually.
163 So assuming you remembered to turn on compatibility mode in devfsd (the first
164 REGISTER/UNREGISTER lines in devfsd.conf), accessing /dev/dsp will load the
165 oss module and create a symlink to /dev/sound/dsp.
167 Again, if you'd rather use devfsd.conf :-
169         LOOKUP mixer MODLOAD snd-mixer-oss
170         LOOKUP sequencer MODLOAD snd-seq-oss
171         LOOKUP dsp MODLOAD snd-pcm-oss
172         LOOKUP audio MODLOAD snd-pcm-oss
173         LOOKUP adsp MODLOAD snd-pcm-oss
175         LOOKUP dmfm MODLOAD snd-<your sound card>
176         LOOKUP dmmidi MODLOAD snd-<your sound card>
177         LOOKUP midi00 MODLOAD snd-<your sound card>
181 3) More configuration
182 ---------------------
184 You've got your modules autoloading by device entry, and compatibility
185 symlinks, which is suffucient for many uses.
187 Devfs by default creates device nodes owned by user and group root,
188 with restrictive permissions in most cases, not much use unless you like
189 danger and always login as root :)
191 For our ALSA setup, a good solution is to create an 'audio' group and
192 give its members read/write access to the audio devices. The following
193 in devfsd.conf accomplishes just that:-
195         REGISTER       ^sound$          PERMISSIONS root.audio 0750
196         REGISTER       ^sound/.*        PERMISSIONS root.audio 0660
197         REGISTER       ^snd$            PERMISSIONS root.audio 0750
198         REGISTER       ^snd/.*          PERMISSIONS root.audio 0660
200 If you use compatibility symlinks and find the permissions on these are
201 not to your liking, remember to add entries for these as well.
204 Finally, since modules may be loaded and unloaded a number of times,
205 any extra configuration related to devices may be lost, hence the
206 'post-install' and 'pre-remove' entries in modules.conf, which
207 do exectly that, run arbitrary commands after module loading and
208 before unloading. The ALSA sound channels are muted by default,
209 you must unmute them the first time they are used. To retain your
210 volume settings, in modules.conf use :-
212 post-install snd-sb16 /usr/sbin/alsactl restore
213 pre-remove snd-sb16 /usr/sbin/alsactl store
215 which store the settings when the modules are unloaded, and restore
216 them the next time the modules are loaded.
218 For other modules these commands can be anything you like. For example
219 when i hotplug my USB mouse, the hotplug system inserts the
220 appropriate modules, then i have a post-install entry to start gpm.
223 Appendix
224 --------
225 Installing devfsd is easy. Get it from the devfs web page above.
226 After unpacking, edit the GNUmakefile for stuff like CFLAGS if you
227 want, then just:-
229 make
230 make install
232 which puts the daemon in /sbin and a couple of config files in /etc.
234 Make an addition to your bootscripts to run '/sbin/devfsd /dev' as the
235 very first thing that happens. Thats it !
237 The default devfsd.conf enables all those compatibility symlinks. If
238 you don't need them coment out the first REGISTER/UNREGISTER lines.