18

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.

Tim
  • 101,790

6 Answers6

26

Another approach is with findmnt:

findmnt /dev/sda4

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

findmnt /home
mikeserv
  • 58,310
taliezin
  • 9,275
  • any command option that would make it return only the dev or mountpoint, so that it can be directly piped into other commands? – matanox Sep 08 '19 at 16:29
  • 1
    @Matan use the -n|-noheadings and -o|--output options. for mount point to dev translation: findmnt -no SOURCE /mount/point. for dev to mount point translation: findmnt -no TARGET. available output columns are listed at findmnt -h. – pkfm Nov 26 '19 at 06:27
15

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.
petry
  • 978
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.

Mike S
  • 2,502
  • 2
  • 18
  • 29
5

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.

terdon
  • 242,166
  • 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 07: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 00:28
  • df --output=source /home/ | tail -n1 is the only option out of all of them that allows you to find which device a sub directory of another mountpoint is in. – Gaia Sep 02 '20 at 06:00
3

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

2

You're looking for the df command.

John
  • 17,011