lsblk | grep <mountpoint>

Find partition name using mount point

lsblk | grep mountpoint
Sample Output
lsblk | grep data
&#9500;&#9472;sdb4   8:20   0    75G  0 part /media/user/data

2
By: totti
2014-02-05 09:41:00

These Might Interest You

  • Suppose you made a backup of your hard disk with dd: dd if=/dev/sda of=/mnt/disk/backup.img This command enables you to mount a partition from inside this image, so you can access your files directly. Substitute PARTITION=1 with the number of the partition you want to mount (returned from sfdisk -d yourfile.img). Show Sample Output


    6
    INFILE=/path/to/your/backup.img; MOUNTPT=/mnt/foo; PARTITION=1; mount "$INFILE" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "$INFILE" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ]
    Alanceil · 2009-03-06 21:29:13 3

  • -1
    mount | grep "mount point"
    mimivx · 2011-01-31 10:21:09 0
  • mkdir local-mount-point sshfs user@host:/path/to/remote/dir local-mount-point diff -r /path/to/local/dir local-mount-point fusermount -u local-mount-point # to unmount


    0
    sshfs user@host:/path/to/remote/dir local-mount-point
    okedialf · 2012-10-05 22:10:33 0
  • Assuming we have a disk image, created by dd if=/dev/sda of=image.dd we can check the image's partition layout with fdisk -ul image.dd, then substitute "x" with starting sector of the partition we want to mount. This example assumes that the disk uses 512Byte sectors


    0
    mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path
    0disse0 · 2011-06-14 19:30:54 0
  • Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.


    4
    lomount -diskimage /path/to/your/backup.img -partition 1 /mnt/foo
    olorin · 2009-07-22 11:32:52 1
  • Assuming we have a disk image, ie. created by dd if=/dev/sda of=image.dd we can check the image's partition layout with fdisk -ul image.dd then, we substitute "x" with starting sector of the partition we want to mount. This example assumes that the disk uses 512 B sectors


    4
    mount -o loop,offset=$((512*x)) /path/to/dd/image /mount/path
    rocku · 2009-11-25 15:49:30 1

What Others Think

Hmm... It works, but the output's a bit ugly. This is a bit better (-l / --list): lsblk -l | grep <mountpoint> Also, there can be multiple matches, especially if you want the partition of / I'd change the grep to be more specific: lsblk -l | grep " <mountpoint>$" (That's space, mountpoint, dollar). Finally, if you wanted to find the partition name and nothing else, you could add 'cut': lsblk -l | grep " <mountpoint>$" | cut -d' ' -f1
flatcap · 224 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: