As I understand, Linux uses demand paging, which means that when a process is started, only those pages of the process are actually loaded from the file system that are touched during the execution.

But, what does that mean if a file system is unmounted? Would unmounting imply that the remaining pages of affected processes are loaded before the unmounting becomes effective (also 'locking' the affected memory pages)? Or if not, could unmounting lead to later problems with the execution of processes in case of page faults?

Update: After Stephen Kitt has provided an answer (namely that unmounting is simply prevented in such a case), I found some additional information under the following question: Does a boot loader unmount the ramdisk BEFORE mounting the root file system on the hard drive?. The explanation given there leads to the same conclusion, although the aspect of demand paging is not addressed there.

  • Given that an unmount occurs gracefully unless -f is specified, I would assume that the remaining pages would be loaded. – Raman Sailopal Jan 24 '18 at 11:05

The kernel solves that by preventing unmounting a file system which is used as the backing store for a running process:

$ dd if=/dev/zero of=test.img bs=1M count=50
$ /sbin/mke2fs test.img
$ sudo mount test.img /mnt/temp
$ sudo cp /usr/bin/sleep /mnt/temp
$ /mnt/temp/sleep 120 &
$ sudo umount /mnt/temp
umount: /mnt/temp: target is busy.
$ sudo umount -f /mnt/temp
umount: /mnt/temp: target is busy.
$ wait; sudo umount /mnt/temp

The file system can only be unmounted once the process running from it has finished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.