Download LINUX Rute Users Tutorial and Exposition Version

Transcript
18.6. Creating devices with mknod and /dev/MAKEDEV
18.6
18. U NIX devices
Creating devices with mknod and /dev/MAKEDEV
Although all devices are listed in the /dev directory, you can create a device anywhere
in the file system using the mknod command:
¨
¥
mknod [-m <mode>] <file-name> [b|c] <major-number> <minor-number>
§
¦
The letters b and c are for creating a block or character device respectively.
¨
To demonstrate, try
¥
mknod -m 0600 ˜/my-floppy b 2 0
ls -al /dev/fd0 ˜/my-floppy
¦
§
my-floppy can be used just like /dev/fd0
Note carefully the mode (i.e. the permissions) of /dev/fd0. /dev/fd0 should
be readable and writable only to root and to users belonging to the floppy group,
since we obviously don’t want an arbitrary user to be able to login (remotely) and write
over a floppy disk.
In fact, this is the reason for having devices represented as files in the first place.
U NIXfiles naturally support group access control, and therefore so also do devices.
To create devices that are missing from your /dev directory (some esoteric devices will not be present by default). Simply look up the device’s major and minor
number in /usr/src/linux/Documentation/devices.txt and use the mknod
command. This is however somewhat tedious, and the script /dev/MAKEDEV is usually present for convenience. You must be in the /dev directory before you run this
script.
¨
Typically example usage of MAKEDEV is,
cd /dev
./MAKEDEV -v fd0
./MAKEDEV -v fd1
¥
¦
§
to create a complete set of floppy disk devices.
The man page for MAKEDEV contains more details, and explains the following:
Note that programs giving the error “ENOENT: No such file or directory”
normally means that the device file is missing, whereas “ENODEV: No such
device” normally means the kernel does not have the driver configured or
loaded.
144