4

I was making liveUSB iso file, doing many mounts, plus chroot script having mount -t proc proc /proc in the script (chroot is a new thing for me, I noticed the issue when I was ding some "cleaning" and script run with chroot was not running any more). And now have IMO very strange situation, how is it possible for system to behave in such a way?

$ if [ -d "newdir/proc" ]; then echo 1;fi
1
$ if [ -d "newdir/pro" ]; then echo 1;fi
$ sudo ls -al "newdir"
total 0

The issue also is that umount newdir outputs "target is busy". findmnt | grep proc no longer shows "newdir/proc" line.

Added 1:

$ sudo ls -al "newdir/media/root/usb" # another mount
total 0
$ sudo ls -al "newdir/media/root"
total 0
$ sudo ls -al "newdir/media"
total 0

If it could make a difference, newdir is in tmpfs system.

Added 2:
After suggestion from the answer by @Bart I ran lsof and realised I had another terminal where I did chroot newdir to see IIRC results of the script. Now I exited that chroot, lsof | grep nwdir no longer outputs list if those bash commands, only warnings about fuse.gvfsd-fuse and fuse /run/user/1000/doc. Still the same for:

$ sudo ls -al "newdir/media/root"
total 0

However after that I was able to do w/out errors in output umount newdir and after that sudo ls -al "newdir/media/root"gave no such file.

P.S. the cause of the unexpected behavior was identified with help here: not closed terminal with chroot. However, I've read how to access files using handles of open processes, but here "ghosting" evidenced itself for ordinary way to run ls, I still hope I will see explanation why/how it worked that way.

1
  • what does ls -ld /path/to/newdir say about permissions? Dec 22, 2021 at 14:26

1 Answer 1

3

The procfs is not even a real filesystem, rather a representation of the contents of memory and the currently running processes. What you are seeing, indicates that some processes created their files in side the chroot mounted proc, but did not exit and still use file references in that directory.

lsof | grep /newdir/proc should show you what processes still use unexisting location.

What you want is probably to bind mount it to a location inside the chroot:

mkdir -m 0555 newdir/proc
mount --bind /proc newdir/proc

and not mount -t.

6
  • please see "added 1" - noted other mounts also became "ghost" folders, not only proc. How does it affect your answer? Dec 22, 2021 at 14:31
  • 1
    I'd check all the directories that you list with lsof, and since you probably ran chroot, it might not have exited in full, still showing references to the directories that were mounted in the chroot
    – Bart
    Dec 22, 2021 at 14:33
  • see Added 2. Your guess that I left some chroot was correct. Why has it resulted in such strange (IMO) results for ls? Dec 22, 2021 at 14:49
  • 1
    is it possible to create files inside procfs?
    – ilkkachu
    Dec 22, 2021 at 14:56
  • 1
    @ilkkachu I don't think so.
    – terdon
    Dec 22, 2021 at 15:18

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.