How can I know if a partition is mounted or unmounted?

55,133

Solution 1

The mount command is the usual way. On Linux, you can also check /etc/mtab, or /proc/mounts.

Solution 2

You can also use df, which will give you a nicer printout and show the disk usage of the mounted file systems:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        27G  8.6G   17G  35% /
dev             2.0G     0  2.0G   0% /dev
run             2.0G  488K  2.0G   1% /run
tmpfs           2.0G  456K  2.0G   1% /dev/shm
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           2.0G  738M  1.3G  38% /tmp
/dev/sdb2       715G  515G  164G  76% /home
tmpfs           396M  4.0K  396M   1% /run/user/1000

Solution 3

lsblk is a nice way for humans to see devices and mount-points. See also this answer.

$ lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   7.3T  0 disk
└─dataGB-dataVB 253:1    0  14.6T  0 lvm  /mnt/dataB
sdb               8:16   0   7.3T  0 disk
└─dataGB-dataVB 253:1    0  14.6T  0 lvm  /mnt/dataB
sdc               8:32   0   7.3T  0 disk
└─sdc1            8:33   0   7.3T  0 part
  └─dataG-data  253:0    0   7.3T  0 lvm  /mnt/data
sdd               8:48   0   7.3T  0 disk
└─sdd1            8:49   0   7.3T  0 part
sde               8:64   0   9.1T  0 disk
└─sde1            8:65   0   9.1T  0 part /mnt/dataC
nvme0n1         259:0    0 232.9G  0 disk
└─nvme0n1p1     259:1    0 232.9G  0 part /

findmnt is useful for scripting or to query a specific device:

$ findmnt /dev/sde1
TARGET     SOURCE    FSTYPE OPTIONS
/mnt/dataC /dev/sde1 xfs    rw,relatime,attr2,inode64,noquota

Solution 4

I suppose you could use the command blkid to list what is mounted (DQMOT). I would suggest setting up your sudo gedit /etc/fstab - if you didn't know of it - with the outputs for the hard drives blkid picks up. The UUIDs "universally unique identifier" are a better way of mounting than other methods.

For example:

# <file system> <mount point>                   <type>  <options>                      <dump>  <pass>
UUID=9ee10f9f-c7fa-4c94-93dc-d8ca02db9c2f /     ext4    errors=remount-ro              0       1
UUID=48ee8-657-3154044569-d52005b00ded-68 none  swap    sw                             0       0
UUID=C8CE6F14CE6EF9D8 /media/john/windows       ntfs    defaults                       0       0
UUID=F4644D2D644CF3C0 /media/john/e             ntfs    defaults                       0       0

You can also often see in the file manager GUI: win+e and look at whether or not the disks are mounted with the up-turned arrows. You can also mount/un-mount from this menu.

enter image description here

Solution 5

How about gnome-disks? Depending on the Ubuntu release, it appears in classic menus as Disks under either Accessories or Utilities?

It gives a graphical map of each disc unit and full details of device name, size, mount status, etc, and also allows mount/dismount. It has the advantage over mount of showing both mounted and unmounted partitions, but as a GUI program it does not have an output that can be piped to other processes in a script. Unlike blkid it does not need root priveleges.

Share:
55,133

Related videos on Youtube

AndreaNobili
Author by

AndreaNobili

Updated on September 18, 2022

Comments

  • AndreaNobili
    AndreaNobili over 1 year

    maybe this is a simple thing but I have the following doubt.

    If I perform fdisk -l, in the output I can find these devices that represent 2 partitions on the /dev/sdb device that is my SD card:

    Dispositivo Boot      Start         End      Blocks   Id  System
    /dev/sdb1            8192      122879       57344    c  W95 FAT32 (LBA)
    /dev/sdb2          122880    15523839     7700480   83  Linux
    

    From this output can I know is these partitions are mounted or unmounted ? (I think no).

    What can I do to know if a specific partition is mounted on my system?

  • Rich Homolka
    Rich Homolka almost 10 years
    Thanks, but this shows what's mounted, but not the device node, so it wouldn't answer the original question - how can I see which device nodes are actually mounted? Is there a way of showing device nodes in this GUI?
  • Matthew Ayers
    Matthew Ayers almost 10 years
    Note that mount simply displays the contents of /etc/mtab, which is a static file that can become out-of-date (most notably if the root fs is mounted read-only, but also if mounts are changed via direct syscalls rather than using the mount and umount utilities). /proc/mounts is guaranteed to be accurate, but obviously only exists if the /proc filesystem is correctly mounted. df reads /etc/mtab via the functions in <mntent.h>, so is no more reliable than this method.
  • Matthew Ayers
    Matthew Ayers almost 10 years
    @cjm I didn't know that; I'm a long-time debian/ubuntu user, where it isn't.
  • Soutzikevich
    Soutzikevich over 5 years
    Best answer under my opinion. Displayed the exact information I needed, in a well-formatted way. +1