Is there a way to automatically unmount a filesystem when doing 'exit' command from a chroot?

$ mount --bind /proc proc
$ chroot .
~ exit #now in chroot and call exit.
$ # back to main device.

I would like proc to be unmounted automatically at exit.

Thank you!


You could try to make an alias for chroot to run your umount command or script after it completes, such as:

alias chroot='chroot; umount my/drive'

Or maybe use a different name for it, such as mychroot.

Another option would be to have script running in the background watching for chroot processes and then umount the drive when the process is terminated.

  • 1
    Thank you! The running script in the background is the solution for the case when you have multiple terminals of the same chroot open.
    – loxeen
    Mar 22 '19 at 14:40

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.