What are exactly mknod
command parameters?
I want to create a jail in chroot. So I need to do:
mknod /var/chroot/bind/dev/null c 1 3
mknod /var/chroot/bind/dev/random c 1 8
What are c
, 1
, 3
and 8
?
mknod
is creating a device file, usually to be located in the /dev branch, but not necessarily like your example shows.
The first parameter is telling which kind of device to create, here c
for character device. Other choices might be b
for block devices, p
for fifo (pipe).
The second parameter is the major number, it identifies the driver for the kernel to use.
The third parameter is the minor number, it is passed to the driver for its internal usage.
On Linux, major/minor numbers are documented here: devices.txt
So 1 is used for the so called memory devices handled by a single driver.
3
is representing the null
device which returns EOF when read and discard whatever is writen to it.
8
is representing the random
device which returns random numbers.
To get more information, you might to have a look to the device manual pages, e.g.
man -s 4 null
man -s 4 random
null
tells what number to use, other OSes manual pages (like say Solaris) might not.
MAKEDEV
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.
mknod /dev/ttyS0 c 4 64
Good to know:
To get the major/minor numbers of a connected device you can cat the device data:
cat /sys/class/tty/ttyUSB0/uevent
Result:
MAJOR=188
MINOR=0
DEVNAME=ttyUSB0
with this information you can then call:
mknod /dev/ttyUSB0 c 188 0