What happens if you delete a device file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
20
down vote

favorite
2












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.







share|improve this question


















  • 1




    I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again.
    – Brad Lanam
    Feb 9 at 16:30














up vote
20
down vote

favorite
2












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.







share|improve this question


















  • 1




    I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again.
    – Brad Lanam
    Feb 9 at 16:30












up vote
20
down vote

favorite
2









up vote
20
down vote

favorite
2






2





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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








edited Feb 16 at 1:07









Jeff Schaller

31.3k846105




31.3k846105










asked Feb 9 at 11:21









alpha

1,241317




1,241317







  • 1




    I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again.
    – Brad Lanam
    Feb 9 at 16:30












  • 1




    I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again.
    – Brad Lanam
    Feb 9 at 16:30







1




1




I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again.
– Brad Lanam
Feb 9 at 16:30




I deleted /dev/zero on a SVR4 system once. Bad idea. Took a bit of work to get my system bootable again.
– Brad Lanam
Feb 9 at 16:30










3 Answers
3






active

oldest

votes

















up vote
30
down vote



accepted










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.






share|improve this answer


















  • 3




    This doesn't really answer the question...
    – Gogeta70
    Feb 9 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.
    – Sergiy Kolodyazhnyy
    Feb 9 at 17:07






  • 1




    @Gogeta70 which part of the question does this post leave unanswered?
    – Ruslan
    Feb 10 at 17:40










  • @RonJohn The question is tagged linux and udev
    – Michael Mrozek♦
    Feb 10 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
    – Sergiy Kolodyazhnyy
    Feb 11 at 1:01

















up vote
8
down vote













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).






share|improve this answer



























    up vote
    3
    down vote













    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.






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f423012%2fwhat-happens-if-you-delete-a-device-file%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      30
      down vote



      accepted










      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.






      share|improve this answer


















      • 3




        This doesn't really answer the question...
        – Gogeta70
        Feb 9 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.
        – Sergiy Kolodyazhnyy
        Feb 9 at 17:07






      • 1




        @Gogeta70 which part of the question does this post leave unanswered?
        – Ruslan
        Feb 10 at 17:40










      • @RonJohn The question is tagged linux and udev
        – Michael Mrozek♦
        Feb 10 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
        – Sergiy Kolodyazhnyy
        Feb 11 at 1:01














      up vote
      30
      down vote



      accepted










      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.






      share|improve this answer


















      • 3




        This doesn't really answer the question...
        – Gogeta70
        Feb 9 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.
        – Sergiy Kolodyazhnyy
        Feb 9 at 17:07






      • 1




        @Gogeta70 which part of the question does this post leave unanswered?
        – Ruslan
        Feb 10 at 17:40










      • @RonJohn The question is tagged linux and udev
        – Michael Mrozek♦
        Feb 10 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
        – Sergiy Kolodyazhnyy
        Feb 11 at 1:01












      up vote
      30
      down vote



      accepted







      up vote
      30
      down vote



      accepted






      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.






      share|improve this 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.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Feb 16 at 1:00









      Jeff Schaller

      31.3k846105




      31.3k846105










      answered Feb 9 at 11:30









      michas

      14.5k33468




      14.5k33468







      • 3




        This doesn't really answer the question...
        – Gogeta70
        Feb 9 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.
        – Sergiy Kolodyazhnyy
        Feb 9 at 17:07






      • 1




        @Gogeta70 which part of the question does this post leave unanswered?
        – Ruslan
        Feb 10 at 17:40










      • @RonJohn The question is tagged linux and udev
        – Michael Mrozek♦
        Feb 10 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
        – Sergiy Kolodyazhnyy
        Feb 11 at 1:01












      • 3




        This doesn't really answer the question...
        – Gogeta70
        Feb 9 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.
        – Sergiy Kolodyazhnyy
        Feb 9 at 17:07






      • 1




        @Gogeta70 which part of the question does this post leave unanswered?
        – Ruslan
        Feb 10 at 17:40










      • @RonJohn The question is tagged linux and udev
        – Michael Mrozek♦
        Feb 10 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
        – Sergiy Kolodyazhnyy
        Feb 11 at 1:01







      3




      3




      This doesn't really answer the question...
      – Gogeta70
      Feb 9 at 16:53




      This doesn't really answer the question...
      – Gogeta70
      Feb 9 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.
      – Sergiy Kolodyazhnyy
      Feb 9 at 17:07




      "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.
      – Sergiy Kolodyazhnyy
      Feb 9 at 17:07




      1




      1




      @Gogeta70 which part of the question does this post leave unanswered?
      – Ruslan
      Feb 10 at 17:40




      @Gogeta70 which part of the question does this post leave unanswered?
      – Ruslan
      Feb 10 at 17:40












      @RonJohn The question is tagged linux and udev
      – Michael Mrozek♦
      Feb 10 at 23:18




      @RonJohn The question is tagged linux and udev
      – Michael Mrozek♦
      Feb 10 at 23:18




      1




      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
      – Sergiy Kolodyazhnyy
      Feb 11 at 1:01




      @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
      – Sergiy Kolodyazhnyy
      Feb 11 at 1:01












      up vote
      8
      down vote













      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).






      share|improve this answer
























        up vote
        8
        down vote













        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).






        share|improve this answer






















          up vote
          8
          down vote










          up vote
          8
          down vote









          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).






          share|improve this answer












          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).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 9 at 16:11









          Stephen M. Webb

          23113




          23113




















              up vote
              3
              down vote













              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.






              share|improve this answer
























                up vote
                3
                down vote













                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.






                share|improve this answer






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 9 at 11:28









                  Gerard H. Pille

                  1,179212




                  1,179212






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f423012%2fwhat-happens-if-you-delete-a-device-file%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      Palaiologos

                      The Forum (Inglewood, California)