Typo
[linux_from_scratch_hints.git] / OLD / devfs.txt
bloba30fd12705a4c729c47da02191bdc3c149c45338
1 TITLE:          Devfs hint
2 LFS VERSION:    Any recent LFS with kernel > 2.4
3 AUTHOR: Jeroen Coumans <jeroencoumans@gmx.net>
5 SYNOPSIS:
6 This hint explains how to setup devfs with your current LFS-configuration using
7 devfsd. The second section explains how you can use devfs from scratch.
9 HINT:
10 The first section will explain to use devfs with your current LFS-configuration
11 using devfsd. This is the easiest and least problematic. The second section will
12 explain how you can use devfs from scratch.
14 VERSION:        19-04-2003
16 USEFULL DOCUMENTATION:
17 /usr/src/linux/Documentation/filesystems/devfs/README
18 http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html
20 IBM has posted a tutorial on filesystems and devfs on their website and offer an
21 excellent way to implement devfs. It can be found on:
22 http://www-106.ibm.com/developerworks/library/l-fs4.html 
23 (thanks Uwe Kramer).
25 Also see the other devfs hints:
26 http://hints.linuxfromscratch.org/hints/devfsd.txt
27 http://hints.linuxfromscratch.org/hints/devfs+modules.txt
28 http://hints.linuxfromscratch.org/hints/dsp_devfsd.txt
29 http://hints.linuxfromscratch.org/hints/mk_initrd+devfs.txt
31 CHANGES
32 19-04-2003: Grammatical fixes
34 ============
35 Introduction
36 ============
37 Devfs is a new implementation of device management under the /dev
38 directory. Instead of a static /dev directory with hundreds or maybe
39 thousands of files, device files are created 'on the fly'.
40 There are some advantages to this, most notably the fact that the /dev directory
41 represents your current hardware layout in an easy way. It also makes USB
42 devices and other hot pluggable hardware easier to setup and manage, since you
43 don't have to manually create the device nodes (which are documented, as every
44 LFS'er should know, in the kernel documentation under
45 /usr/src/linux/Documentation/devices.txt). It also requires a new naming scheme
46 which breaks compatibility with older programs trying to find the old device
47 files. There are two ways to use the devfs. The first way, described in section
48 2, is to use both the new and the old names. The old names are symlinks to the
49 real device files, and these are managed by a daemon which must be loaded at
50 system startup. This way is the safest way to go, since it won't break any
51 programs relying on the old names, and you still have a less cluttered up /dev
52 directory with the new devfs. The second way, described in section 2, is to not
53 run devfsd, and (re)direct software to the new names. More and more programs are
54 'devfs-aware', so this should become less of a problem. Most changes are only
55 minor though, but there are some catches you need to be aware of.
57 One last note.
58 This hint is not meant to replace the extensive documentation on devfs, it just
59 describes what needs to be done to use it on a LFS-box or how to implement it if
60 you're building a new one. So please make sure to read the appropriate docs,
61 they are located in /usr/src/linux/Documentation/filesystems/devfs. Also, make
62 sure to check out the website http://www.atnf.csiro.au/~rgooch/linux.
64 =========
65 Section 1
66 =========
68 Enabling devfs in your current LFS-configuration.
70 I'll try to explain how you can use devfs without breaking any programs. The new
71 devfs has a naming scheme different from the structure in the static /dev. To
72 use this without reconfiguring your software, you have to run devfsd. This makes
73 sure that all devices are available under their old names by providing symlinks
74 to them. Devfsd has some other advantages, such as  preserving permissions and
75 loading modules. Check out the documentation (man devfsd) for a complete list.
77 Required files:
78 1. linux kernel > 2.4
79 2. devfsd (http://www.atnf.csiro.au/~rgooch/linux)
80 Make sure that you use the latest stable version of both available. Devfs has
81 had some problems in older kernel releases, and I also recall a message on the
82 lfs mailing lists that the newest version of devfsd can give some compilation
83 problems with older kernels.
85 First, you need to enable devfs-support in the kernel. Note that this is only in
86 kernel's 2.4 and higher, which is standard in the latest LFS. I assume you know
87 how to build a new kernel, if not, look at the LFS-book for instructions.
89 Under "Code maturity level options", enable:
91      "Prompt for development and/or incomplete code/drivers"
92      (CONFIG_EXPERIMENTAL).
94 Under "File systems", enable:
96   [*]   "/dev file system support (EXPERIMENTAL)" (CONFIG_DEVFS_FS)
97   [*]   "automatically mount at boot" (CONFIG_DEVFS_MOUNT)
99 If you use pty's (and nearly everybody does), disable:
101      "/dev/pts file system for Unix98 PTYs" (CONFIG_DEVPTS_FS)
103 since devfs will take care of those and it could cause problems logging in.
104 Please note that you still have to enable pty support. Under "Character
105 devices", enable:
106  [*]    "Unix98 PTY support" (CONFIG_UNIX98_PTYS)
108 Build this new kernel and copy the bzImage to /boot/linux-devfs (or whatever
109 name you wish). Add a new entry to your boot manager which points to this image.
110 Again, for instructions, see either the LFS-book, or the appropriate
111 documentation. There are no additional boot-parameters needed, since we enabled
112 CONFIG_DEVFS_MOUNT. If you're interested in the boot parameters, check out the
113 kernel documentation.
115 Now we're going to install devfsd. This is very simple, just issue a make &&
116 make install. These are the files it install:
118         /usr/share/man/man5/devfsd.conf.5
119         /usr/share/man/man8/devfsd.8
120         /etc/devfsd.conf
121         /etc/modules.devfs
122         /sbin/devfsd
124 Last but not least you need to make sure devfsd starts up at boot-time. Copy the
125 template in /etc/rc.d/init.d to devfs and add "/sbin/devfsd /dev" to the start
126 function. Or, copy and paste the following (minimalistic) script and save it as
127 /etc/rc.d/init.d/devfs
129 #!/bin/sh
131 # Begin /etc/rc.d/init.d/devfs
133  . /etc/rc.d/init.d/functions
134  echo -n "Enabling DevFS..."
135  /sbin/devfsd /dev
136  evaluate_retval
138 # End /etc/rc.d/init.d/devfs
140 Now create a symlink to start it:
141 ln -s /etc/rc.d/init.d/devfs /etc/rc.d/rc.sysinit/S001devfs
143 If you're not using the latest LFS-bootscripts, adjust the locations of the
144 bootscripts accordingly.
146 If you're using a BSD-init, just add the line
148  /sbin/devfsd /dev
150 at the beginning of your rc.sysinit.
152 It's important that devfsd starts up first, since we didn't adjust any
153 configuration files yet. The devfs daemon takes care of providing compatibility
154 symlinks so all programs can still access devices.
156 If you've followed the above steps, you can try out devfs by rebooting and
157 selecting the new kernel. The old /dev files aren't deleted, so if something
158 fails, just reboot into your previous kernel. (You may get an error message from
159 devfsd, but this can safely be ignored).
161 =========
162 Section 2
163 =========
165 This section is if you want to build a LFS-system with the new devfs from
166 scratch. Note that this will break compatibility with some older programs you
167 may install after the basic setup, but luckily most are flexible enough to
168 convince them into using the new device names.
170 You don't need to do much to use devfs from scratch. You may save some inodes by
171 not using MAKEDEV in chapter 6 of the book, although you should only do this if
172 you're absolutely sure that you won't need to boot into a non-devfs kernel and
173 if you really need the inodes.
175 None of the packages in the LFS book are affected by the use of devfs as far as
176 I know. But you have to change some configuration files in order to use devfs.
177 Do not skip this step or you'll render your machine nearly unbootable!
179 The following files from the LFS-book are affected:
180 1. /etc/inittab
181 2. /etc/fstab
182 3. /etc/lilo.conf
183 These files will be adjusted to reflect the new naming scheme.
185 1. In /etc/inittab, replace all instances of ttyx with vc/x, where x
186 is the number of the console.
187 Thus,
189   1:2345:respawn:/sbin/agetty tty1 9600
191 becomes:
193   1:2345:respawn:/sbin/agetty vc/1 9600
195 2. When you create the /etc/fstab file, make sure to use the new device names.
196 Do not use the old device names, which are only present if you run devfsd in
197 compatibility mode. These symlinks may not always be present. You can create the
198 device names as presented by the kernel, which look like
199 /dev/ide/host0/bus0/target0/lun0/part5. You can also use the symlinks which are
200 automatically generated by the kernel which look like /dev/discs/disc0/part5.
201 Note that these symlinks are always present if you use devfs without the devfs
202 daemon, so you can safely apply them in your configuration files.
204 3. The same goes for lilo and grub when you specify the root filesystem.
205 Quoted from Peter Havshøi:
206 "Make adjustments to your 'build-distro' /etc/lilo.conf :
207     image=/boot/lfs-devfs
208     label=lfs-devfs
209     read-only
210     append="root=/dev/ide/host0/bus0/target0/lun0/part5"
211 (or whatever your $LFS-partition is). Remember to copy System.map and bzImage to
212 your build-distro /boot, and run '/sbin/lilo -v'. Lilo does not check
213 "append"-statements, so you don't get an error message." When you boot into your
214 LFS, you can change the last line from /etc/lilo.conf to a plain
215 "root=/dev/ide/host0/bus0/target0/lun0/part5".
217 Note: this only seems to apply when using devfsd or when you're not mounting
218 devfs at boottime. The symlinks which appear in the /dev tree without running
219 devfsd or when running it without compatibility are always  there. I have made
220 my grub menu.lst and my /etc/fstab a whole lot more readable and maintainable by
221 using the links. Instead of /dev/ide/host0/bus0/target1/lun0/cd I now use
222 /dev/cdroms/cdrom0. The same for floppy's and harddiscs. This feature of devfs
223 is especially usefull for boot floppy's and bootcd's. Be aware that these
224 symlinks are affected by shuffling your hardware configuration, for example
225 moving the primary harddisk to the secondary IDE channel. I assume that if
226 you're smart enough to build in new hardware, you're also smart enough to change
227 these configuration files accordingly.
229 A note on building the kernel from Rasmus Andersson:
230 "Avoid [auto loading] loadable modules that adds devices. Without devfsd we get
231 a catch-22 since the device does not exist, so the probe fails to load the
232 module...". This affects devices like the cd-rom, floppy, etc. You could
233 probably try to set up a script which loads the driver when a program tries to
234 find a device or adjust /etc/modules.conf, but easiest will be to compile them
235 statically in the kernel.
237 If all is set up right, you should be able to reboot into your shiny new LFS
238 system, with the new devfs. If you experience any problems with software trying
239 to access the old names, you can always set up the devfsd like in section 1 or
240 run it manually, this takes care of compatibility. However, most programs have
241 an option to specify a specific device, and this is almost always sufficient. So
242 far, I'm being able to work this way and haven't encountered any difficulties
243 which couldn't be solved without some common sense (and this means something,
244 since I'm a relative newbie and no programmer!).
246 ========
247 Problems
248 ========
250 KDE Mixer doesn't work:
251 I've noticed that the mixer applet doesn't work. Even though I use alsa, it
252 only looks for the oss mixer. (If anyone knows why, drop me a line). Since the
253 path to the mixer is hard coded I use the following hack when compiling
254 kdemultimedia:
256         tar xyvf kdemultimedia-$VERSION.tar.bz2 &&
257         cp kmix/mixer_oss.cpp kmix/mixer_oss.cpp.backup &&
258         sed s/'\/dev\/mixer/\/dev\/sound\/mixer/' kmix/mixer_oss.cpp.backup > \
259         kmix/mixer_oss.cpp
261 You can also provide a symlink from /dev/sound/mixer to /dev/mixer. I prefer the
262 above, however, since the point of using devfs is a clean /dev directory.
265 Hendrik Hoeth notified me of the following error:
267         If I'm not using devfsd, I need to compile
268         agetty with -DDO_DEVFS_FIDDLING  (I use util-linux-2.11b)
270         If I don't do so, agetty passes e.g. tty2 instead of vc/2 to login when
271         I logout and then try to log in again on vc/2 (even if I put vc/2 into
272         my /etc/inittab). The result is a system on which one can't login twice.
274         to compile util-linux with -DDO_DEVFS_FIDDLING, just add the line
276                         -DDO_DEVFS_FIDDLING
278         to the CFLAGS in MCONFIG (and a backslash at the end of the line
279         before...) Thus CFLAGS become
281         CFLAGS    := $(CFLAGS) $(OPT) -I$(LIB) $(WARNFLAGS) \
282                         $(CURSESFLAGS) $(SLANGFLAGS) \
283                         -D_FILE_OFFSET_BITS=64 \
284                         -DSBINDIR=\"$(SBINDIR)\" \
285                         -DUSRSBINDIR=\"$(USRSBINDIR)\" \
286                         -DLOGDIR=\"$(LOGDIR)\" \
287                         -DVARPATH=\"$(VARPATH)\" \
288                         -DLOCALEDIR=\"$(LOCALEDIR)\" \
289                         -DDO_DEVFS_FIDDLING
291 It seems this error is solved in later version of util-linux (2.11d), since I
292 couldn't reproduce it with that version. Take this example as a lesson: since
293 devfs is an experimental feature (although present in the stable kernel), make
294 sure you use the latest version possible of your software, since patches may
295 have gone in to ensure devfs-compatibility.
297 =========
298 Thanks to
299 =========
300 Well, since I didn't figure all this out by myself, I'd like to thank the
301 following people for providing some answers on the mailing list:
302 Jack Byer
303 Rasmus Andersson
304 Steve Jones
305 Usurpator
306 Björn Lindberg
307 Peter Havshøi
308 Hendrik Hoeth
309 Bryan Breen
310 And probably some others which I have forgotten