Mknod
mknod is the command used to create device files, which can act strangely compared to normal files. Device files are kept in /dev, and unlike normal files, these are files the kernel knows about, and reads/writes to.
mknod follows the syntax
mknod device-name device-type major-number minor-number
- device-name - full name of device, in this example /dev/random
- device-type - device files can represent 2 types of device, a storage device (block) or a device use for other purpose (character) .. block devices are things like cd-roms, hard drives, etc . Character devices are things like /dev/zero, /dev/null, or any other device not used to store info ... as you probably have guessed, for mknod "b" means block, and "c" means character
- major-number - a number usually referring to what ground the device is in
- minor-number - the number of the device within the group
Examples
mknod /dev/random c 1 8
Creates the character device /dev/random and has it point to major number 1, minor number 8.
major and minor numbers are chosen by the writers of the Linux kernel. For a list of these devices, major and minor numbers, and type, look in the kernel documentation, adduming /usr/src/linux refers to the linux source codes: see the file /usr/src/linux/Documentation/devices.txt.
Here is an example of what it might look like (note: this is not a real snippet from the file, but the file has its info arranged in a similar way)
45 block some hard disks 0 /dev/nicedisk nice hard disk 1 /dev/noisydisk noisy hard disk
in the example, 45 is the major number, block is the type, and 0 is the minor number, and /dev/nicedisk is the name .. so
mknod /dev/nicedisk b 45 0
Creates the block device /dev/nicedisk and points it to major number 45, minor number 0.
Provided by
Most (all?) Linux distributions incorporate this from the GNU Coreutils: man page
Related Commands
- link - Make hard links.
- ln - Make hard or soft links
- mkdir - Make directory nodes.
- mkfifo - Make a named pipe directory entry (aka fifo)
- readlink - Make a canonical name.
- rmdir - Remove empty directories.
- unlink - Remove directory entries (other than for subdirectories)