Installing gentoo in chroot I found that commands like mount and df doesn't work: they try to read file /etc/mtab (which of course is empty).

Can I (for future use) setup or even recompile them so, that they won't read /etc/mtab, taking all needed info from /proc?


df and mount are based on *mntent (ex getmntent) functions, based on /etc/mtab and /etc/fstab. You can patch these tools, but you should simply copy or symlink /proc/mounts to /etc/mtab.

  • 1
    Indeed: I look at /etc/mtab in my archlinux, it is a symlink to /proc/self/mounts. Is there any difference between /proc/self/mounts and /proc/mounts? – Eddy_Em Mar 27 '13 at 8:01
  • 2
    /proc/self is a symlink to /proc/CURPID/. So if you do an ls /proc, it's link to ls current PID. And /proc/mounts is a symlink to /proc/self/mounts. So basicly it's the same file. – GHugo Mar 27 '13 at 10:47
  • thanks for explanation. If I'd have look at /proc/mounts, I wouldn't ask previous question. – Eddy_Em Mar 27 '13 at 10:53

Don't do that: instead, symlink /proc/mounts to /etc/mtab instead, that solve your problem as well.

And notice that in a chrooted environment, you only need a minimal mount table, i.e /sys, /proc, / etc.

  • @Gilles, I think the original answer (before your edit) claims that /etc/mtab should be a separate regular file, not just symlink to /proc/mounts. AFAIK, it's now deprecated but was true some time ago because there were some applications depending on it. Probably they are still here, because /etc/mtab is not a symlink on my Gentoo yet. See discussion here: gentoo.2317880.n4.nabble.com/… So IMHO the edit should be reverted until we get the truth :) – gavv Sep 30 '15 at 14:31
  • @g-v /etc/mtab may be either updated by mount, or symlinked to /proc/mounts. Making a copy from /proc/mounts to /etc/mtab doesn't make much sense: if you want that, let mount update it — but the problem here seems to be that mount is not maintaining /etc/mtab properly, so making a copy that will go stale is not a good idea. – Gilles 'SO- stop being evil' Sep 30 '15 at 14:43
  • @Gilles, making a copy at least did make sense some time ago: see bugs.gentoo.org/show_bug.cgi?id=477498 and marc.info/?l=linux-nilfs&m=138159795211469&w=2 The second bug is fixed I think, but since /etc/mtab is still not a symlink on my one-year-old installation and the first bug above is not closed yet, the original answer is useful. It was a hint that before making it a symlink, you should ensure that it will not break anything (in Gentoo). – gavv Sep 30 '15 at 14:53

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.