6

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?

Eddy_Em
  • 1,293
  • 1
  • 12
  • 18

2 Answers2

8

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.

GHugo
  • 792
  • 4
  • 10
  • 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 08: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
2

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 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
daisy
  • 53,527
  • 78
  • 236
  • 383
  • @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: http://gentoo.2317880.n4.nabble.com/rfc-converting-etc-mtab-to-a-symlink-td270774.html 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 https://bugs.gentoo.org/show_bug.cgi?id=477498 and http://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