How can we identify what partition a filesystem is mounted on in Linux when the partition is not directly referenced in df output?For example, our system's fdisk output is:   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1        2550    20478976   83  Linux/dev/sda2            2550       60736   467378176   83  Linux/dev/sda3           60736       60801      523264   82  Linux swap / SolarisAnd the output from df is:Filesystem      Size  Used Avail Use% Mounted onrootfs           20G  881M   18G   5% //dev/root        20G  881M   18G   5% /devtmpfs        989M  216K  989M   1% /dev/dev/sda2       443G  199M  420G   1% /hometmpfs           990M     0  990M   0% /dev/shm/dev/root        20G  881M   18G   5% /var/named/chroot/etc/named/dev/root        20G  881M   18G   5% /var/named/chroot/var/named/dev/root        20G  881M   18G   5% /var/named/chroot/etc/named.conf/dev/root        20G  881M   18G   5% /var/named/chroot/etc/named.rfc1912.zones/dev/root        20G  881M   18G   5% /var/named/chroot/etc/rndc.key/dev/root        20G  881M   18G   5% /var/named/chroot/usr/lib64/bind/dev/root        20G  881M   18G   5% /var/named/chroot/etc/named.iscdlv.key/dev/root        20G  881M   18G   5% /var/named/chroot/etc/named.root.keyFrom that list the only obvious partition is /dev/sda2; for the others we can't see which partition they reside on (we want to do this via a bash script).For example, we know that /dev/root is mounted on /dev/sda1 as they both have the same 20GB size, but how can we identify this from a script?Output from ls -l /dev/root /dev/sda1:[root@server etc]# ls -l /dev/root /dev/sda1ls: cannot access /dev/root: No such file or directorybrw-rw---- 1 root disk 8, 1 May  7 14:16 /dev/sda1
Identify partition by mount point
linux;bash
That output is misleading.You actually have 2 different filesystems mounted at /.rootfs is the filesystem created by an initramfs. When the bootloaders loads the kernel, it has the ability to load an initramfs which gets unpacked into a tmpfs filesystem. This filesystem cannot be unmounted. When the initramfs is done doing its thing, it simply mounts the real root filesystem on top of it.The reason why df shows it as 20gb is because it can't get to that tmpfs filesystem. When df goes to show the filesystems, it first gets a list of current mounts from /etc/mtab. This gives it 2 mounts using /. It then makes a statfs() syscall on each mountpoint. But since the current root filesystem sits on top of the tmpfs initramfs, it ends up statting the current root filesystem twice.Additionally /dev/root is actually a symlink. To find out where it really points using a shell script, you can use readlink -f /dev/root.Update: Ok, so in this case readlink -f /dev/root does not work as /dev/root does not exist any more. Because the initramfs is what mounted your real root filesystem, /dev/root would have existed there. But since the initramfs is buried, /dev/root is not there any more.In this case it becomes much much more difficult.What you can do is to use stat to get the device number for the mountpoint, and then search through /dev for that.For example, on my system this yields:$ stat --format '%D' /fd00$ stat --format '%02t%02T' /dev/mapper/sys-rootfd00$ for device in $(blkid -o device); do >   [ $(stat --format '%04D' /) = $(stat --format '%02t%02T' $device) ] && \>     echo $device && \>     break> done/dev/mapper/sys-rootBasically what this does is uses stat to get the device major and minor number of /. We then iterate through all known block devices looking for one with that same device major and minor.It's not pretty, but basically the /dev entry has a different name, and so we have to search for it.This could be done more efficiently, but I wanted to keep the code simple