All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rüdiger Meier" <sweet_f_a@gmx.de>
To: util-linux@vger.kernel.org
Subject: find device of a known mountpoint
Date: Fri, 31 Mar 2017 11:00:24 +0200	[thread overview]
Message-ID: <5f3534af-06b5-9c76-f5e3-9c1d489e570c@gmx.de> (raw)

Hi,

I wonder whether we have a command which tells me the device 
corresponding to a known mount point. I want to avoid grepping the 
output of mount because it may not unique (regarding mounts on shared 
bind mounts) and because the original mount point may include symlinks 
which are canonicalized by the kernel.

Example:

$ truncate -s100M /tmp/img
$ losetup /dev/loop0  /tmp/img
$ mkfs.ext2  /dev/loop0

$ mkdir /tmp/mnt
$ ln -s /tmp  /tmp/xyz/symlink

$ mount /dev/loop0 /tmp/xyz/symlink/mnt
$ mount | grep loop
/dev/loop0 on /tmp/mnt type ext2 ...


I need a command which outputs "/dev/loop0" when "/tmp/xyz/symlink/mnt" 
is given.

So far I found df as the only solution (but ugly and maybe GNU-only). 
And it would succeed for any input file, not only mountpoints.

$ df -P /tmp/xyz/symlink/mnt | awk 'NR==2{print $1}'
/dev/loop0

Our mountpoint(1) looks like the right tool but prints the device 
numbers only

$ mountpoint  -d /tmp/xyz/symlink/mnt
7:0

So how could I do this in a non-ugly way?

cu,
Rudi

             reply	other threads:[~2017-03-31  9:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31  9:00 Rüdiger Meier [this message]
2017-03-31  9:19 ` find device of a known mountpoint Karel Zak
2017-03-31 10:03   ` Rüdiger Meier
2017-03-31 10:41     ` Rüdiger Meier
2017-03-31 10:54       ` Karel Zak
2017-03-31 11:20         ` Rüdiger Meier
2017-03-31 10:09   ` [PATCH] test: fix mountpoint device check in libmount/loop Ruediger Meier
2017-03-31 10:57     ` Karel Zak
2017-03-31 11:01     ` Rüdiger Meier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5f3534af-06b5-9c76-f5e3-9c1d489e570c@gmx.de \
    --to=sweet_f_a@gmx.de \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.