Can I umount or remount a filesystem, when some process has its working or root directory on it?

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












2















If some process has its current working directory or root directory on a mounted filesystem, can I umount/remount that filesystem?



If some process has a read/write file descriptor or read/write/shared mmap of a file on a mounted filesystem, can I remount that filesystem to read-only? If yes, What will happen to these file descriptors and mmaps when you write to them?










share|improve this question




























    2















    If some process has its current working directory or root directory on a mounted filesystem, can I umount/remount that filesystem?



    If some process has a read/write file descriptor or read/write/shared mmap of a file on a mounted filesystem, can I remount that filesystem to read-only? If yes, What will happen to these file descriptors and mmaps when you write to them?










    share|improve this question


























      2












      2








      2








      If some process has its current working directory or root directory on a mounted filesystem, can I umount/remount that filesystem?



      If some process has a read/write file descriptor or read/write/shared mmap of a file on a mounted filesystem, can I remount that filesystem to read-only? If yes, What will happen to these file descriptors and mmaps when you write to them?










      share|improve this question
















      If some process has its current working directory or root directory on a mounted filesystem, can I umount/remount that filesystem?



      If some process has a read/write file descriptor or read/write/shared mmap of a file on a mounted filesystem, can I remount that filesystem to read-only? If yes, What will happen to these file descriptors and mmaps when you write to them?







      linux mount






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 23 at 15:44









      ctrl-alt-delor

      12k42561




      12k42561










      asked Feb 23 at 12:39









      炸鱼薯条德里克炸鱼薯条德里克

      5811316




      5811316




















          1 Answer
          1






          active

          oldest

          votes


















          2














          The working directory and root directory of a process are counted as an active reference to the filesystem, the same as an open file. Therefore they prevent the filesystem from being unmounted. The kernel returns a "busy" error.




          EBUSY target could not be unmounted because it is busy.



          -- man umount




          A filesystem can be remounted as read-only if there are no files open for writing. The working directory and root directory of a process are not counted as files open for writing; they do not prevent the filesystem from being remounted as read-only.




          EBUSY source cannot be remounted read-only, because it still holds files open for writing.



          man mount




          There is another case: at least on some filesystems, you cannot remount as read-only if an unlinked file is open, even for reading. Closing a unlinked file allows the space to be reclaimed, but this may require updating filesystem metadata blocks on disk.



          The command umount -l (which uses umount2(..., MNT_DETACH)) is able to detach busy filesystems from the mount tree. The filesystem remains active. It will be shut down once the last open file is closed. The documentation does not state whether the shut down happens in the background, or whether you can rely on the filesystem having been shut down cleanly after the last close() call returns.






          share|improve this answer

























          • So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

            – 炸鱼薯条德里克
            Feb 23 at 13:50











          • @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

            – sourcejedi
            Feb 23 at 14:28











          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          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%2f502515%2fcan-i-umount-or-remount-a-filesystem-when-some-process-has-its-working-or-root%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          The working directory and root directory of a process are counted as an active reference to the filesystem, the same as an open file. Therefore they prevent the filesystem from being unmounted. The kernel returns a "busy" error.




          EBUSY target could not be unmounted because it is busy.



          -- man umount




          A filesystem can be remounted as read-only if there are no files open for writing. The working directory and root directory of a process are not counted as files open for writing; they do not prevent the filesystem from being remounted as read-only.




          EBUSY source cannot be remounted read-only, because it still holds files open for writing.



          man mount




          There is another case: at least on some filesystems, you cannot remount as read-only if an unlinked file is open, even for reading. Closing a unlinked file allows the space to be reclaimed, but this may require updating filesystem metadata blocks on disk.



          The command umount -l (which uses umount2(..., MNT_DETACH)) is able to detach busy filesystems from the mount tree. The filesystem remains active. It will be shut down once the last open file is closed. The documentation does not state whether the shut down happens in the background, or whether you can rely on the filesystem having been shut down cleanly after the last close() call returns.






          share|improve this answer

























          • So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

            – 炸鱼薯条德里克
            Feb 23 at 13:50











          • @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

            – sourcejedi
            Feb 23 at 14:28
















          2














          The working directory and root directory of a process are counted as an active reference to the filesystem, the same as an open file. Therefore they prevent the filesystem from being unmounted. The kernel returns a "busy" error.




          EBUSY target could not be unmounted because it is busy.



          -- man umount




          A filesystem can be remounted as read-only if there are no files open for writing. The working directory and root directory of a process are not counted as files open for writing; they do not prevent the filesystem from being remounted as read-only.




          EBUSY source cannot be remounted read-only, because it still holds files open for writing.



          man mount




          There is another case: at least on some filesystems, you cannot remount as read-only if an unlinked file is open, even for reading. Closing a unlinked file allows the space to be reclaimed, but this may require updating filesystem metadata blocks on disk.



          The command umount -l (which uses umount2(..., MNT_DETACH)) is able to detach busy filesystems from the mount tree. The filesystem remains active. It will be shut down once the last open file is closed. The documentation does not state whether the shut down happens in the background, or whether you can rely on the filesystem having been shut down cleanly after the last close() call returns.






          share|improve this answer

























          • So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

            – 炸鱼薯条德里克
            Feb 23 at 13:50











          • @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

            – sourcejedi
            Feb 23 at 14:28














          2












          2








          2







          The working directory and root directory of a process are counted as an active reference to the filesystem, the same as an open file. Therefore they prevent the filesystem from being unmounted. The kernel returns a "busy" error.




          EBUSY target could not be unmounted because it is busy.



          -- man umount




          A filesystem can be remounted as read-only if there are no files open for writing. The working directory and root directory of a process are not counted as files open for writing; they do not prevent the filesystem from being remounted as read-only.




          EBUSY source cannot be remounted read-only, because it still holds files open for writing.



          man mount




          There is another case: at least on some filesystems, you cannot remount as read-only if an unlinked file is open, even for reading. Closing a unlinked file allows the space to be reclaimed, but this may require updating filesystem metadata blocks on disk.



          The command umount -l (which uses umount2(..., MNT_DETACH)) is able to detach busy filesystems from the mount tree. The filesystem remains active. It will be shut down once the last open file is closed. The documentation does not state whether the shut down happens in the background, or whether you can rely on the filesystem having been shut down cleanly after the last close() call returns.






          share|improve this answer















          The working directory and root directory of a process are counted as an active reference to the filesystem, the same as an open file. Therefore they prevent the filesystem from being unmounted. The kernel returns a "busy" error.




          EBUSY target could not be unmounted because it is busy.



          -- man umount




          A filesystem can be remounted as read-only if there are no files open for writing. The working directory and root directory of a process are not counted as files open for writing; they do not prevent the filesystem from being remounted as read-only.




          EBUSY source cannot be remounted read-only, because it still holds files open for writing.



          man mount




          There is another case: at least on some filesystems, you cannot remount as read-only if an unlinked file is open, even for reading. Closing a unlinked file allows the space to be reclaimed, but this may require updating filesystem metadata blocks on disk.



          The command umount -l (which uses umount2(..., MNT_DETACH)) is able to detach busy filesystems from the mount tree. The filesystem remains active. It will be shut down once the last open file is closed. The documentation does not state whether the shut down happens in the background, or whether you can rely on the filesystem having been shut down cleanly after the last close() call returns.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 23 at 14:28

























          answered Feb 23 at 12:49









          sourcejedisourcejedi

          25.2k444110




          25.2k444110












          • So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

            – 炸鱼薯条德里克
            Feb 23 at 13:50











          • @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

            – sourcejedi
            Feb 23 at 14:28


















          • So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

            – 炸鱼薯条德里克
            Feb 23 at 13:50











          • @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

            – sourcejedi
            Feb 23 at 14:28

















          So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

          – 炸鱼薯条德里克
          Feb 23 at 13:50





          So, if a filesystem is mounted as rw, while there's no any writable reference to it, it can be re-mounted as ro?

          – 炸鱼薯条德里克
          Feb 23 at 13:50













          @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

          – sourcejedi
          Feb 23 at 14:28






          @炸鱼薯条德里克 yes, except "if an unlinked file is open, even for reading". I have edited my question better, to try and answer each part of your question. Question upvote for mentioning the root directory of the process, that's a nice detail that does not get mentioned very often :-)

          – sourcejedi
          Feb 23 at 14:28


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502515%2fcan-i-umount-or-remount-a-filesystem-when-some-process-has-its-working-or-root%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?