MAKEDEV
Create device files in the /dev directory
SYNOPSIS
MAKEDEV [-n] [-v] [-r] [-d dirname] target ...
Where target can be:
- A predefined category of devices (e.g., generic, std, console, pty, loop)
- A specific device name (e.g., null, zero, random)
PARAMETERS
target
Specifies which device files to create. This can be a predefined category (like 'generic' for common devices or 'std' for standard I/O devices) or the name of a specific device (like 'null' or 'zero'). Multiple targets can be specified.
-n
Perform a dry run. The script will show what it would do without actually creating or deleting any device files.
-v
Enable verbose output. Provides more detailed information about the actions being performed, such as which device files are being created and their properties.
-r
Remove existing device files before recreating them. This ensures a clean slate, especially useful if device properties (like major/minor numbers) have changed.
-d dirname
Specify an alternative directory to create device files in, instead of the default '/dev'. This is useful for chroot environments or creating device sets for specific purposes.
DESCRIPTION
MAKEDEV is a shell script primarily used on Linux systems to create special device files (also known as device nodes) within the /dev directory. These device files are critical interfaces that allow user-space programs to communicate with hardware devices (like hard drives, keyboards, terminals, etc.) and pseudo-devices (like /dev/null or random number generators).
Historically, before the advent of dynamic device management systems like udev and mdev, MAKEDEV was the standard method for populating the /dev directory during system installation, recovery, or in minimal environments. It typically reads configuration information (often hardcoded within the script or from a simple database) to determine the correct device type (block or character), major number, minor number, and permissions for each device node. While modern Linux distributions largely rely on udev to dynamically create and manage device nodes as hardware is detected or connected, MAKEDEV remains important for certain scenarios, such as bootstrapping a system where udev is not yet running, or for creating static device files in specific embedded or recovery environments where dynamic management is not desired or feasible. It automates what would otherwise be a tedious and error-prone manual process of calling mknod for each device.
CAVEATS
MAKEDEV is largely considered a legacy tool in modern Linux systems, as its functionality has been superseded by dynamic device management systems like udev (or mdev in embedded contexts). Manually running MAKEDEV on a system managed by udev can lead to conflicts or inconsistencies if not done carefully. It does not provide dynamic hotplugging capabilities; new devices connected to the system will not automatically get a device file unless MAKEDEV is run again with the appropriate target. Its primary use case now is often restricted to initial system setup, recovery environments, or minimalistic systems where udev is not employed.
DEVICE FILES AND THE /DEV DIRECTORY
Device files in the /dev directory are special files that represent hardware devices or pseudo-devices. They come in two main types: block devices (for devices that transfer data in fixed-size blocks, like hard drives, identified by 'b' in `ls -l`) and character devices (for devices that transfer data character by character, like terminals or serial ports, identified by 'c'). Each device file is associated with a major number (identifying the device driver) and a minor number (identifying a specific instance of the device). MAKEDEV's primary function is to correctly set these numbers and create the corresponding special files.
MAJOR AND MINOR NUMBERS
Every device node has a major and minor number. The major number identifies the driver that controls the device. For example, all SCSI disks might share the same major number. The minor number identifies a specific device controlled by that driver. So, `sda` might be major X, minor 0; `sdb` major X, minor 1, and so on. MAKEDEV contains an internal database or logic to determine these numbers for a wide range of standard and common devices, ensuring that the created device files correctly link to the intended kernel drivers.
HISTORY
MAKEDEV emerged as a necessary tool in the early days of Linux (and Unix-like systems) when device files in /dev were statically created and managed. System administrators or installation scripts had to manually create each device node using the mknod command, which was prone to errors, especially when dealing with the correct major and minor numbers. MAKEDEV automated this process by encapsulating the knowledge of common device types and their associated numbers. Its importance began to decline with the rise of hotplugging and dynamic device creation frameworks, culminating in udev (initially part of the kernel as devfs, then externalized) becoming the de facto standard for modern Linux distributions. Despite this, MAKEDEV maintains relevance in specific scenarios where a static or minimal /dev is preferred, or during system boot stages before udev takes over.