2

According to this: Determine what device a directory is located on

I can find which device a file is in by df command in a normal environment:

fpemud-workstation / # df /bin Filesystem 1K-blocks Used Available Use% Mounted on /dev/dm-0 476458008 48307576 403924640 11% / 

But I can't use that method in chroot:

fpemud-workstation / # mount -t proc n /test/proc fpemud-workstation / # mount --rbind /sys /test/sys fpemud-workstation / # mount --make-rslave /test/sys fpemud-workstation / # mount --rbind /dev /test/dev fpemud-workstation / # mount --make-rslave /test/dev fpemud-workstation / # chroot /test df /bin Filesystem 1K-blocks Used Available Use% Mounted on - 476458008 48307604 403924612 11% / 

EDIT:

Yes I have /etc/mtab in my chroot, this is a detailed result:

fpemud-workstation / # mount -t proc n /test/proc fpemud-workstation / # mount --rbind /sys /test/sys fpemud-workstation / # mount --make-rslave /test/sys fpemud-workstation / # mount --rbind /dev /test/dev fpemud-workstation / # mount --make-rslave /test/dev fpemud-workstation / # chroot /test ls /etc/mtab -l lrwxrwxrwx 1 root root 19 May 26 22:37 /etc/mtab -> ../proc/self/mounts fpemud-workstation / # chroot /test df /bin Filesystem 1K-blocks Used Available Use% Mounted on - 476458008 51387464 400844752 12% / fpemud-workstation / # chroot /test cat /proc/mounts n /proc proc rw,relatime 0 0 sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0 cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0 cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0 cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0 cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0 cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0 cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0 cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_cls,net_prio 0 0 cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0 cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0 cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0 configfs /sys/kernel/config configfs rw,relatime 0 0 debugfs /sys/kernel/debug debugfs rw,relatime 0 0 fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0 devtmpfs /dev devtmpfs rw,nosuid,size=1997472k,nr_inodes=499368,mode=755 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0 mqueue /dev/mqueue mqueue rw,relatime 0 0 

1 Answer 1

2

df reads /etc/mtab to find what device is mounted on a particular mount point. This can either be a file which is updated by the mount command, or a symbolic link to /proc/mounts which contains current information provided by the kernel.

/etc/mtab has the advantage that it can provide more precise information: it's what was passed to mount, not some information massaged by the kernel. But it also has limitations: it can get out of synch if mount can't write to it for some reason (e.g. while / is read-only, or if mount is run in a chroot), and it doesn't work in a chroot.

In a system intended to be used chrooted, make /etc/mtab a symbolic link to /proc/mounts.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.