Hardware, Devices, and Tools
Knowledge speaks, but wisdom listens. Jimi Hendrix
This chapter gives an overview of what a device file is, and how to create one. The canonical list of device files is /usr/src/linux/Documentation/devices.txt kerneldevices if you have the Linux kernel source code installed on your system. The devices listed here are correct as of kernel version 2.6.8. Hardware Utilities The <command>MAKEDEV</command><indexterm id="ch04-makedev"> <primary>commands</primary><secondary>MAKEDEV</secondary> </indexterm> Script Most device files will already be created and will be there ready to use after you install your Linux system. If by some chance you need to create one which is not provided then you should first try to use the MAKEDEV script. This script is usually located in /dev/MAKEDEV but might also have a copy (or a symbolic link) in /sbin/MAKEDEV. If it turns out not to be in your path then you will need to specify the path to it explicitly. In general the command is used as: # /dev/MAKEDEV -v ttyS0 create ttyS0 c 4 64 root:dialout 0660 This will create the device file /dev/ttyS0 filesystem /dev/dev/ttyS0 with major node 4 and minor node 64 as a character device with access permissions 0660 with owner root and group dialout. ttyS0 is a serial port. The major and minor node numbers are numbers understood by the kernel. The kernel refers to hardware devices as numbers, this would be very difficult for us to remember, so we use filenames. Access permissions of 0660 means read and write permission for the owner (root in this case) and read and write permission for members of the group (dialout in this case) with no access for anyone else. The <command>mknod</command><indexterm id="ch04-mknod"> <primary>commands</primary><secondary>mknod</secondary> </indexterm> command MAKEDEV commandsMAKEDEV is the preferred way of creating device files which are not present. However sometimes the MAKEDEV script will not know about the device file you wish to create. This is where the mknod command comes in. In order to use mknod you need to know the major and minor node numbers for the device you wish to create. The devices.txt kerneldocumentation devices.txt file in the kernel source documentation is the canonical source of this information. To take an example, let us suppose that our version of the MAKEDEV commandsMAKEDEV script does not know how to create the /dev/ttyS0 filesystem/dev /dev/ttyS0 device file. We need to use mknod commandsmknod to create it. We know from looking at the devices.txt kerneldocumentation devices.txt that it should be a character device with major number 4 and minor number 64. So we now know all we need to create the file. # mknod /dev/ttyS0 c 4 64 # chown root.dialout /dev/ttyS0 # chmod 0644 /dev/ttyS0 # ls -l /dev/ttyS0 crw-rw---- 1 root dialout 4, 64 Oct 23 18:23 /dev/ttyS0 As you can see, many more steps are required to create the file. In this example you can see the process required however. It is unlikely in the extreme that the ttyS0 file would not be provided by the MAKEDEV commandsMAKEDEV script, but it suffices to illustrate the point. The <command>lspci</command><indexterm id="ch04-lspci"> <primary>commands</primary><secondary>lspci</secondary> </indexterm> command lspci TO BE ADDED The <command>lsdev</command><indexterm id="ch04-lsdev"> <primary>commands</primary><secondary>lsdev</secondary> </indexterm> command lsdev TO BE ADDED The <command>lsusb</command><indexterm id="ch04-lsusb"> <primary>commands</primary><secondary>lsusb</secondary> </indexterm> command lsusb TO BE ADDED The <command>lsraid</command><indexterm id="ch04-lsraid"> <primary>commands</primary><secondary>lsraid</secondary> </indexterm> command lsraid TO BE ADDED The <command>hdparm</command><indexterm id="ch04-hdparm"> <primary>commands</primary><secondary>hdparm</secondary> </indexterm> command hdparm TO BE ADDED More Hardware Resources More information on what hardware resources the kernel is using can be found in the /proc directory. Refer to in chapter 3. Kernel Modules<indexterm id="ch04-modules"><primary>kernel</primary> <secondary>modules</secondary></indexterm> This section will discuss kernel modules. TO BE ADDED lsmod<indexterm id="ch04-lsmod1"><primary>commands</primary> <secondary>lsmod</secondary></indexterm><indexterm id="ch04-lsmod2"> <primary>kernel</primary><secondary>modules</secondary> <tertiary>lsmod</tertiary></indexterm> lsmod TO BE ADDED insmod<indexterm id="ch04-insmod1"><primary>commands</primary> <secondary>insmod</secondary></indexterm><indexterm id="ch04-insmod2"> <primary>kernel</primary><secondary>modules</secondary> <tertiary>insmod</tertiary></indexterm> insmod TO BE ADDED depmod<indexterm id="ch04-depmod1"><primary>commands</primary> <secondary>depmod</secondary></indexterm><indexterm id="ch04-depmod2"> <primary>kernel</primary><secondary>modules</secondary> <tertiary>depmod</tertiary></indexterm> depmod TO BE ADDED rmmod<indexterm id="ch04-rmmod1"><primary>commands</primary> <secondary>rmmod</secondary></indexterm><indexterm id="ch04-rmmod2"> <primary>kernel</primary><secondary>modules</secondary> <tertiary>rmmod</tertiary></indexterm> rmmod TO BE ADDED modprobe<indexterm id="ch04-modprobe1"><primary>commands</primary> <secondary>modprobe</secondary></indexterm><indexterm id="ch04-modprobe2"> <primary>kernel</primary><secondary>modules</secondary> <tertiary>modprobe</tertiary></indexterm> modprobe TO BE ADDED