Typo
[linux_from_scratch_hints.git] / OLD / devfsd.txt
blob079d87b6afe29fd09555c3494ca2279d49f004cd
1 TITLE:          Using devfs and devfsd
3 LFS VERSION:    LFS-4.0
5 AUTHOR:         Tushar Teredesai <Tushar@LinuxFromScratch.Org>
7 SYNOPSIS:
8         Using device filesystem and the devfs daemon for storing device
9         permissions across reboots.
11 HINT:
13 Primary Location of this hint:
14         http://www.linuxfromscratch.org/~tushar/
15 The latest version of the hint and any relevant patches are available at that
16 site. Please refer to the primary location before submitting
17 bug-reports/enhancements to this hint.
19 You may freely copy this document or create derivate works or distribute the
20 document in any format. At your discretion, you may give credit to the original
21 author:)
23 Use the hint at your own risk. Neither the author, nor the Linux From Scratch
24 project accept any responsibility for anything that happens when using these
25 documents or associated files.
27 An appropriate place to discuss this hint is blfs-support MailingList/NewsGroup
28 at LinuxFromScratch.Org. I welcome bug reports but for support requests, please
29 use the support list.
31 Change Log:
32 [2003-03-05]
33         * Clarified the purpose of the hint.
34         * Added information on changing sound-device permissions.
35 [2002-12-28]
36         * First public version.
38 Packages to download:
39         * devfsd - 1.3.25
40                 <http://freshmeat.net/projects/devfsd/>
43 What is devfs?
45 Devfs is an alternative to "real" character and block special devices on your
46 root filesystem. Kernel device drivers can register devices by name rather than
47 major and minor numbers. These devices will appear in devfs automatically, with
48 whatever default ownership and protection the driver specified. To know more,
49 (and to answer questions like "why?" and "how does it work?") check out the
50 homepage for devfsd. Please be sure to check out the documentation at the above
51 site.
54 What is devfsd?
56 Devfsd is a daemon that provides:
57         * Compatibility old style device names.
58         * Ability to retain device permissions across reboots.
60 How are we going to set it up?
62 I use devfsd for both reasons mentioned above. I find it preferable to type
63 "fdisk /dev/hda" instead of "fdisk /dev/discs/disc0/disc":) But the primary
64 focus of this hint is the second reason mentioned above. Hence, based on your
65 preference, you may disable the compatibility mode and the system will still
66 work.
68 The hint will discuss enabling devfs while following the book, at the end are
69 short instructions on how to enable it for an installed LFS.
72 Creating directories (Chapter 6):
74 Don't create the directory /dev/pts, create only /dev. Additionally create a
75 directory /dev-state which we will be used by devfsd to store permissions
76 between reboots.
77         rm -rf /dev/pts
78         mkdir /dev-state
81 Creating devices (Chapter 6):
83 Skip the Makedev package, instead create the following two devices manually.
84         mknod -m 611 /dev/console c 5 1
85         chgrp 4 /dev/console
86         mknod -m 666 /dev/null c 1 3
87 These devices are needed since we don't mount devfs at boot. /dev/console is
88 required else you will get the dreaded message "Unable to open initial console".
89 /dev/null is required since the init scripts redirect output to it during
90 execution.
93 Configuring essential software (Chapter 7):
95 When creating /etc/inittab, replace all the ttyN (where N is the tty number) by
96 vc/N. e.g. replace tty1 by vc/1.
99 Creating the /etc/fstab file (Chapter 8):
101 Replace the device names by the new names, especially for the the root
102 partition. For example my root partition /dev/hda2 is replaced by
103 /dev/discs/disc0/part2.
105 Also, don't add the line for devpts since we use devfs to manage /dev/pts
108 Installing Linux i.e. Configuring the Kernel (Chapter 8):
110 Note the following options when configuring the kernel.
111         Code maturity level options
112                 Prompt for development and/or incomplete code/drivers
113                         Enabled
114         File Systems
115                 /dev file system support
116                         Enabled
117                 Automatically mount at boot
118                         Disabled
119                 /dev/pts file system for Unix98 PTYs
120                         Disabled
121 We don't mount devfs at boot since we want to use devfsd. /dev/pts is disabled
122 since it is now managed by devfs.
125 Making the LFS system bootable (Chapter 8):
127 We have to use the new names for the root devices.
129 If you are using LILO, then add a line to the end of the lilo.conf:
130         echo append=\"root=/dev/ide/host0/bus0/target0/lun0/part2\" >> \
131                 /etc/lilo.conf
133 If you are using GRUB, use the following line:
134         kernel /boot/lfskernel root=/dev/ide/host0/bus0/target0/lun0/part2
137 Installing devfsd:
139 Adjust optimization flags based on your preferences or skip them if you don't
140 want to optimize.
141         export CFLAGS="-O2 -march=i686 -fomit-frame-pointer -s -w"
142         cp GNUmakefile GNUmakefile.orig
143         sed -e "s:-O2:${CFLAGS}:g" GNUmakefile.orig > GNUmakefile
144 To compile and install
145         make && make install
147 In the installed /etc/devfsd.conf, there is a section that specifies
148 uncommenting some files to store permissions between reboots, just uncomment the
149 specified lines. The following are the lines that should be uncommented.
150         REGISTER    ^pt[sy]     IGNORE
151         CREATE      ^pt[sy]     IGNORE
152         CHANGE      ^pt[sy]     IGNORE
153         DELETE      ^pt[sy]     IGNORE
154         REGISTER    .*      COPY    /dev-state/$devname $devpath
155         CREATE      .*      COPY    $devpath /dev-state/$devname
156         CHANGE      .*      COPY    $devpath /dev-state/$devname
157         DELETE      .*      CFUNCTION GLOBAL unlink /dev-state/$devname
158         RESTORE     /dev-state
160 If you don't want the older compatibility names, comment out the corresponding
161 lines from /etc/devfsd.conf. Note that this may cause problems for some apps
162 which expect the older style names, but most of the packages have been adapted
163 to accomodate devfs.
165 We also need to create a init script to start devfsd. Create a script using the
166 template that basically does the following
167         if [ ! -d /dev-state ]
168         then
169                 mkdir /dev-state
170         fi
171         mount --bind /dev /dev-state
172         mount -t devfs none /dev
173         devfsd /dev
174 The above script binds the current /dev to /dev-state so that the current /dev
175 is available as /dev-state in case you need to verify/modify the contents.
176 devfsd also uses it to store device permissions. It then mounts devfs on /dev
177 since we choose not to mount it at boot time. If we had mounted devfs at boot
178 time, the original /dev would not have been available to us. It then starts
179 devfsd to manage /dev.
181 Make a link in the /etc/rc.d/rcS.d so that the above script is the first script
182 to be executed.
185 Configuring autoloading of modules:
187 devfs uses modules.conf to decipher which module to load when a particular
188 device is accessed. The easiest way to do this is to add the module to be loaded
189 when a particular device is accessed. For example, for my soundblaster live, I
190 have the following in my /etc/modules.conf
191         alias /dev/sound emu10k1
193 An alternative is to use directives in /etc/devfsd.conf to load the appropriate
194 module
195         LOOKUP sound EXECUTE modprobe emu10k1
197 Please read the documentation for more information on how to use devfs.
199 Changing default device permissions:
201 Since we have configured devfsd to store permissions, if you make an explicit
202 change to any of the devices in /dev, devfsd will automatically backup the new
203 permissions/ownerships to /dev-state and will use the permissions in /dev-state
204 (a behavior which mimics having a static /dev). This procdeure can be used to
205 allow all the users access to the sound devices (/dev/sound/*). If you would
206 like to restrict access to the sound devices to a particular group (e.g. sound),
207 use chown and chmod to change the ownerships and permissions for the
208 /dev/sound/* files as shown below:
209         groupadd sound
210         chmod 664 /dev/sound/*
211         chgrp sound /dev/sound/*
214 For an already running system:
216 If you have a running system and want to use devfs, then:
217 * Reconfigure the kernel ensuring the above changes.
218 * Install devfsd as mentioned above.
219 * Make changes to the configuration files to use new names.
220 * Create /dev-state directory.
221 * Add the init script for devfs.
222 * Reboot.
225 Don't forget to send me bug reports and enhancements so that I can keep the hint
226 updated.