Linux – What happens if you delete a device file

block-devicedeviceslinuxlinux-kerneludev

I roughly know about the files located under /dev.

I know there are two types (character/block), accessing these files communicates with a driver in the kernel.

I want to know what happens if I delete one — specifically for both types of file. If I delete a block device file, say /dev/sda, what effect — if any —
does this have? Have I just unmounted the disk?

Similarly, what if I delete /dev/mouse/mouse0 — what happens? Does the mouse stop working? Does it automatically replace itself?

Can I even delete these files? If I had a VM set up, I'd try it.

Best Answer

Those are simply (special) files. They only serve as "pointers" to the actual device. (i.e. the driver module inside the kernel.)

If some command/service already opened that file, it already has a handle to the device and will continue working.

If some command/service tries to open a new connection, it will try to access that file and fail because of "file not found".

Usually those files are populated by udev, which automatically creates them at system startup and on special events like plugging in a USB device, but you could also manually create those using mknod.

Related Question