What is the opposite of `mknod`?

merlin2011 picture merlin2011 · Mar 18, 2014 · Viewed 28.3k times · Source

I am learning to write character device drivers from the Kernel Module Programming Guide, and used mknod to create a node in /dev to talk to my driver.

However, I cannot find any obvious way to remove it, after checking the manpage and observing that rmnod is a non-existent command.

What is the correct way to reverse the effect of mknod, and safely remove the node created in /dev?

Answer

1000 Bites picture 1000 Bites · Aug 10, 2014

The correct command is just rm :)

A device node created by mknod is just a file that contains a device major and minor number. When you access that file the first time, Linux looks for a driver that advertises that major/minor and loads it. Your driver then handles all I/O with that file.

When you delete a device node, the usual Un*x file behavior aplies: Linux will wait until there are no more references to the file and then it will be deleted from disk.

Your driver doesn't really notice anything of this. Linux does not automatically unload modules. Your driver wil simply no longer receive requests do to anything. But it will be ready in case anybody recreates the device node.