10

This question already has an answer here:

How can we check the mount points for partitions listed in /dev/sd*? For example, I would like know if the partition for my home is /dev/sda4.

marked as duplicate by mikeserv, don_crissti, Braiam, Archemar, chaos Mar 25 '15 at 12:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

15

Another approach is with findmnt:

findmnt /dev/sda4

...to get mountpoint from dev. Or vice-versa:

findmnt /home
  • any command option that would make it return only the dev or mountpoint, so that it can be directly piped into other commands? – Matan Sep 8 at 16:29
12

You can use:

  • mount for a list of all mounted filesystems and mount options for each of them;
  • lsblk for a tree of block devices, size and mount point (if mounted);
  • df for a list of mounted block devices, size, used space, available space and mount point.
  • lsblk is linux specific? – Milind Dumbare Mar 24 '15 at 19:29
  • Yes, util-linux package. – petry Mar 24 '15 at 20:04
  • 1
    @Miline /dev/sd* to refer to disks and partitions is Linux-specific as well. Other Unix-like systems solve the same problem but have different naming conventions. – a CVn Mar 25 '15 at 10:26
  • lsblk was exactly what I needed. Thank you – Timothy Pulliam Oct 20 '16 at 17:52
5

You're actually asking two questions. The easiest thing to do if you want to know where your home is:

cd
df -h .

Or

df -h $HOME

Where is /tmp mounted?

df -h /tmp

...etc.

If you want to know what is mounted on a certain device,

mount | grep ^/dev/sda1

(for example). Or

mount | grep ^/dev/sd

to see all the sd's.

4

Depends on what you're after. If you want to check which of the partitions in /dev/sd* has a default mountpoint and what that mountpoint is, you could do

for part in /dev/sd*; do grep -w "$part" /etc/fstab | awk '{print $1,$2}; done

However, on most modern systems, partitions are mounted by UUID and not dev name, so a better approach1 would be:

for uuid in /dev/disk/by-uuid/*; do 
    mpoint=$(grep "$(basename $uuid)" /etc/fstab | awk '{print $2}')
    [ -n "$mpoint" ]  && echo  "$(basename $(readlink $uuid)) : $mpoint"; 
done

On my system, for example, that returns:

sda3 : swap
sda1 : /
sda2 : /home
sdc1 : /mnt/bigboy
sdb3 : /mnt/movies
sdb1 : /winblows

You could also extend that to report those partitions with no default mount point:

for uuid in /dev/disk/by-uuid/*; do 
    dev=$(basename $(readlink $uuid))
    mpoint=$(grep "$dev" /etc/fstab | awk '{print $2}')
    if [ -n "$mpoint" ]; then
      echo  "$dev : $mpoint"; 
    else
      echo "$dev : No mountpoint"
    fi
done

If you want to find out the partition of a given directory, for example ~/, you can use df:

$ df /home/
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda2      442047744 266441120 153128800  64% /home

Or, to get the device name only (note that the --output flag is not POSIX):

 $ df --output=source /home/ | tail -n1
 /dev/sda2

To get a list of currently mounted partitions and their mountpoints:

mount | awk '/^\/dev/{print $1,$3}'

Finally, a very useful command is lsblk:

$ lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
├─sda1   8:1    0  29.3G  0 part /
├─sda2   8:2    0 428.4G  0 part /home
└─sda3   8:3    0     8G  0 part [SWAP]
sdb      8:16   0   1.4T  0 disk 
├─sdb1   8:17   0   9.8G  0 part /winblows
├─sdb2   8:18   0     1K  0 part 
├─sdb3   8:19   0   1.2T  0 part /mnt/movies
├─sdb5   8:21   0  46.6G  0 part 
├─sdb6   8:22   0    14G  0 part 
├─sdb7   8:23   0 117.4G  0 part 
└─sdb8   8:24   0   2.3G  0 part 
sdc      8:32   0   1.8T  0 disk 
└─sdc1   8:33   0   1.8T  0 part /mnt/bigboy

1An even better approach is findmnt but I'd never heard of that before reading @taliezin's answer.

  • I guess the mention of /etc/fstab is good, but your loops over it seem needlessly complex. Also, /proc/mounts is always up-to-date, but /etc/fstab doesn't necessarily match. The first script could be awk '/^[^#]*\/dev\// {print $1, $2 }' /etc/fstab. You typically don't need grep if you're also using awk. The regex is more complex because I'm filtering out comments, and I have to escape the /es since I'm inside a /pattern/. Anyway, quick one-off scripting stylistic debate aside, df is probably the best recommendation for everyday use. fstab can have LABEL= as well as UUID=. – Peter Cordes Mar 25 '15 at 7:43
  • @PeterCordes as I mention in my answer, fstab is used to show the default mount point. Of course it's not always up to date, that's the point! As I also explain, I am using the loops to show which of the partitions in /dev has a default mount point. I did it that way because I wanted to include an example that listed those that don't. That and for the sake of readability is why I didn't just use awk. We're talking about parsing about a dozen lines of text, for such simple tasks I always choose readability and succinctness over cold efficiency. – terdon Mar 25 '15 at 12:33
  • @terdon - mtab is for showing up-to-date mount points. – mikeserv Mar 28 '15 at 0:28
2

You're looking for the df command.

2

You can use mount command. It also shows options with which the mounting is done.

Not the answer you're looking for? Browse other questions tagged or ask your own question.