21

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.

1
  • 1
    I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again. Commented Feb 9, 2018 at 16:30

3 Answers 3

30

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.

8
  • 4
    This doesn't really answer the question... Commented Feb 9, 2018 at 16:53
  • "Usually those files are populated by udev" Usually, but on Linux. There's makedev command which usually does the job, and unlike udev it seems to be present among most unix-like os. Commented Feb 9, 2018 at 17:07
  • 1
    @Gogeta70 which part of the question does this post leave unanswered? Commented Feb 10, 2018 at 17:40
  • @RonJohn The question is tagged linux and udev Commented Feb 10, 2018 at 23:18
  • 1
    @RonJohn Yes,but with a "but". The Ubuntu Hacks book which is from like '06 shows there is /etc/init.d/makedev. The freebsd manual mentions MAKEDEV appeared in 4.2BSD (from 1983). I think in 1983 it would be just as logical to make MAKEDEV automated via init as in 06 Commented Feb 11, 2018 at 1:01
9

Device files are actually a filesystem alias for an entry in the kernel's device table. If you look at the /dev files with "ls -l" you'll see they have a major device number and a minor device number. If you delete the files from the filesystem, you can always recreate them using the appropriate tools to relink the special file to the entry in the kernel device table -- see mknod(1).

3

From that moment on, they can only be accessed by programs that had those devices already open. So, it's no way to unmount filesystems. And with udev, a reboot might restore those devices. A strange way to learn unix.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.