Manual creation of device nodes under / dev / in linux
/ There are many device node files in dev / directory, such as file / dev/sda of u disk, file / dev/mmcblk0 of mmc card. These files are usually created automatically by udev or mdev program after uevent event is detected. We can also create it manually with the mknod command.
The following mmc card as an example, describes how to create its device node file.
1. mknod command
The format of the command is:
mknod device name device type (character: c, block: b) master device number and slave device number
Among them, the main device number is used to distinguish different types of equipment, while the secondary device number is used to distinguish multiple devices of the same type.
Therefore, to create a device node, you need to know the device type and its master-slave device number.
2. Getting device type
/ # cat /proc/devices Character devices: 1 mem 2 pty 3 ttyp 4 /dev/vc/0 ... 254 ttySDIO Block devices: 1 ramdisk 259 blkext 7 loop 179 mmc / #
3. Obtain the master-slave device number of the device
/ # ls /sys/block/ loop0 loop4 mmcblk0 ram11 ram15 ram5 ram9 loop1 loop5 ram0 ram12 ram2 ram6 loop2 loop6 ram1 ram13 ram3 ram7 loop3 loop7 ram10 ram14 ram4 ram8 / # ls /sys/block/mmcblk0/ bdi device mmcblk0p1 removable slaves uevent capability ext_range queue ro stat dev holders range size subsystem / # cat /sys/block/mmcblk0/uevent MAJOR=179 MINOR=0 DEVTYPE=disk PHYSDEVPATH=/class/mmc_host/mmc0/mmc0:0002 PHYSDEVBUS=mmc PHYSDEVDRIVER=mmcblk / # / # cat /sys/block/mmcblk0/mmcblk0p1/uevent MAJOR=179 MINOR=1 DEVTYPE=partition PHYSDEVPATH=/class/mmc_host/mmc0/mmc0:0002 PHYSDEVBUS=mmc PHYSDEVDRIVER=mmcblk / #
4. Creating Nodes
Once created, you can see the following newly created nodes in the / dev / directory.mknod /dev/mmcblk0 b 179 0 mknod /dev/mmcblk0p1 b 179 1
/ # ls /dev/mmcblk0* -l brw-r--r-- 1 root root 179, 0 Jan 1 00:34 /dev/mmcblk0 brw-r--r-- 1 root root 179, 1 Jan 1 00:36 /dev/mmcblk0p1
5. Mount partition
After mounting the partition, we can access the files in the mmc card./ # mount /dev/mmcblk0p1 /mnt/ / # ls /mnt/ a dd x.docx / #
6. Delete Nodes
/ # rm /dev/mmcblk0p1 -f / # / # ls /dev/mmcblk0* -l brw-r--r-- 1 root root 179, 0 Jan 1 00:34 /dev/mmcblk0 / #