Mknod command details

Source: Internet
Author: User

Mknod [Options] Name {BC} major minor
Mknod [Options] Name P
GNU options (abbreviation ):
[-M mode] [-- help] [-- version] [--]
Description
Mknod uses the specified name to generate a FIFO (Named Pipe), character-specific or block-specific file.
A special file in a file system stores three types of information (Boolean, integer, and integer ). The boolean type selects between the character file and the block file. The two integers are the primary and secondary device numbers.

Generally, a private file does not occupy space on the disk. It only provides communication for the operating system, rather than data storage services. Generally, private files direct to a hardware device (such as a disk, tape, printer, or virtual console) or services provided by the operating system (such as/dev/null, /dev/random ).

Block Files are usually similar to disk devices (a block number is assigned to a place where data can be accessed, which means a block cache is set at the same time ). Any other device is a character file. (In the past, there was a difference between the two types of documents. For example, the character document I/O is not cached, while the block document is .)

The mknod command is used to generate such files.

The following parameters specify the type of the generated file:

B create a block (buffered) special file
C, u create a character (unbuffered) special file
P create a FIFO

The GNU version also allows the use of U ('unbufferd' unbuffered) to maintain consistency with the C language.

When creating a block file or character file, the primary and secondary device numbers must be given after the file type parameter. However, when a P (FIFO) type is specified, the primary and secondary device numbers must be omitted. (The device number is represented in decimal by default. The octal number starts with 0. The GNU version also allows the hexadecimal format starting with 0x)

Option
-M mode, -- mode = Mode
Set the mode for the newly created document, just like the Application Command chmod, and create a new directory using the default mode in the future. By default, the generated document mode is 0666 ('a + RW ')

GNU standard options
-- Help
Display usage information on the standard output and exit smoothly.
-- Version
Display version information on standard output and exit smoothly

The master and secondary device numbers can be found in the kernel source code. /documentation/devices.txt found that mknod can create nodes for these specified devices. Of course, the node location is not necessarily under/dev, but for ease of management, it is generally specified/dev. The driver is located based on the master and secondary device numbers, but when your application opens a device, it must be the node location you specified. For example:

Mknod/dev/input/mouse0 c 13 32
Yes.
Mknod/tmp/mymouse c 13 32

/*************************************** **************************************** ***************************************/

Below is a user who successfully solved the problem that swap partition could not be found using mknod.

Open a large program, use free to see if the memory is used, but the display is as follows
Linuxman :~ # Free
Total used free shared buffers cached
Mem: 248380 243800 4580 0 2928 53344
-/+ Buffers/cache: 187528 60852
Swap: 0 0 0
No, why is swap zero? # Swapon-A is used, but the file/dev/hda7 is not available!
For swap, one line in my fatab file is as follows:
/Dev/hda7 swap pri = 42 0 0
So: # ls/dev/hda *, there is no hda7 block device! Create one!
I will use # mknod/dev/hda7 B 3 7, and then CHMOD and chgrp!
In this case, # ls/dev/hda7 is displayed as follows:
BRW-RW ---- 1 root disk 3, 7/dev/hda7
Then # Swapon-A can be used; # Free display
Total used free shared buffers cached
Mem: 248380 242368 6012 0 5596 55304
-/+ Buffers/cache: 181468 66912
Swap: 334616 0 334616

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.