Identify mounted filesystems

Transparency

Article from Issue 222/2019
Author(s):

Tools like mount and findmnt reveal which partitions and filesystems are mounted on your computer.

When creating a boot medium or expanding a system, you often need to create a new partition or add a filesystem to an existing partition. Selecting the wrong device can cost you valuable data.

Tools like partx, fdisk/cfdisk, gdisk/cgdisk, mount, lsblk, and findmnt help you discover which partitions and filesystems are present on the system and where they are currently mounted. We take you on a quick tour of some of these partition and filesystem tools, which are found on most of the standard Linux distributions.

Disk Tools

To make sure that you pass the correct parameters to the commands, you first need an overview of the volumes that exist on the system. The partx program will help you here. The --show switch tells it to list the individual partitions (Figure 1).

Figure 1: partx lets you quickly inventory which partitions exist on the system.

The output includes six columns with the partition number, start and end blocks, number of blocks, size, name, and UUID of the partition. The example shows six partitions /dev/sda1, /dev/sda2, and /dev/sda5 to /dev/sda8.

This output already gives you a brief overview. However, it does not yet show you how the individual partitions are structured. fdisk, which outputs the individual partitions if you pass in the -l option (Figure 2), provides a little more information. However, the program only works for disks with a capacity of up to 2TBe, whereas the gfdisk and Parted tools can analyze larger disks.

Figure 2: Using fdisk, you can determine the partition type, if required. Among other things, the software displays this information when you call up the list of partitions.

Next up is cfdisk. As you can see in Figure 3, cfdisk provides even more information. This information includes the fact that /dev/sda1 is a primary partition, /dev/sda2 is an extended partition, and /dev/sda5 through /dev/sda8 contain logical partitions. In addition, it shows you the partition type – /dev/sda6 turns out to be a swap partition.

Figure 3: cfdisk shows you more information about the disks installed in the computer and the partitions on them.

cfdisk has a counterpart named cgdisk, which works the same way as fdisk/gdisk. When it comes to partition tables, fdisk and cfdisk only support Master Boot Record (MBR) format. MBR is a boot sector format that was popular with BIOS-based computers for many years. On the other hand, gdisk and cgdisk also support the GUID Partition Table (GPT) format. GPT is the successor to MBR for partition tables on hard disks and part of the UEFI standard. FigFigure 4 shows the cgdisk menu after calling cgdisk -l /dev/sda.

Figure 4: With cgdisk you can view the parameters of the partitions. The program reads the data from a GPT.

However, all these programs do not help to detect whether the listed partitions are mounted in the filesystem or where they sit in the directory tree. If you want answers to these questions, the lsblk program comes into play.

Mounted Disks

lsblk (the abbreviation stands for "list block devices") shows all block devices. The default view in lsblk includes only the devices or partitions currently in use (Figure 5). In the right-hand column, you will find the mount point (i.e., the position at which the device is mounted in the directory tree).

Figure 5: Using lsblk, you can discover details of the devices and partitions on the computer.

The output of lsblk has six columns. Table 1 gives an overview of the information you get from this list.

Table 1

lsblk

NAME

Device name

MAJ:MIN

Main and extension numbers of the device

RM

0 for fixed and 1 for removable devices (like CD/DVD drives)

SIZE

Storage capacity of the device in human readable form

TYPE

Type of device (see Table 2)

MOUNTPOINT

Directory in which the device is mounted

Table 2

lsblk Types

disk

Hard disk

loop

Loop device

lvm

Logic Volume Manager (LVM)1 partition

part

Partition on a storage medium

rom

CD/DVD drive

1 LVM is the abstract partitioning schema across disks, partitions, and filesystems. LVM enables dynamically changeable partitions (logical volumes) across multiple hard disks.

Using the -a switch helps lsblk bring more devices to light by including devices that are not currently in use. For example, Figure 6 shows a series of loop devices (virtual block devices that do not map to a physical device, but use a file for underlying storage) from /dev/loop0 to /dev/loop7.

Figure 6: The -a parameter lists the active devices, as well as unused partitions and devices.

Filesystems

The -a switch tells you which partitions exist and under which mount points they are mounted in the filesystem. So far, however, you do not know which options were set when mounting the partition. The mount command shows these kinds of details (Figure 7).

Figure 7: The standard output from mount tells you about the mounted filesystems and their mount options.

The output from the command is quite extensive and often includes numerous virtual devices managed by the kernel and system programs. In many cases, however, only the physical mass storage devices and their mounted partitions are of interest.

Since Linux partitions mostly have the ext filesystem (today mostly ext4), you could filter the output of mount with grep accordingly. However, this detour is not actually necessary. Mount offers a -t (short for --type) switch that outputs filesystems of a certain type only. For example, the command in Figure 8 only returns partitions formatted with ext4.

Figure 8: If you are looking for information about selected partitions only, use the -t option in mount to display them.

mount provides so much information that clarity can suffer. The output of findmnt from the same software package offers a better structure. When called without further options, findmnt shows a tree view (Figure 9) from which you can see how the individual filesystems are mounted. The findmnt command also identifies the origin and type of the filesystem and the options with which it was mounted.

Figure 9: findmnt provides an overview of the mounted filesystems in the form of a tree view, including further information on each entry.

findmnt also supports the -t option, with which you can filter for ext4 filesystems, for example (Figure 10). Unlike mount, findmnt isn't limited to a single filesystem parameter but lets you enter several if required.

Figure 10: Like mount, findmnt also offers the option to filter the output by filesystems for clarification.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Custom Rasp Pi OS

    A few simple steps let you create a preconfigured Raspberry Pi operating system that lets you cut the time required to burn and configure your OS images.

  • ASK KLAUS!

    Klaus Knopper is the creator of Knoppix and co-founder of the LinuxTag expo. He currently works as a teacher, programmer, and consultant. If you have a configuration problem, or if you just want to learn more about how Linux works, send your questions to: klaus@linux-magazine. com

  • Tuning Your SSD

    Nothing accelerates a PC like transitioning to an SSD, but some special configuration might be in order if you want to get the most from your drive.

  • Command Line: Encrypting Partitions

    Modern installers offer the option of encryption with just a few clicks, but you might want to take control of the process. We show how to encrypt your partitions safely without sacrificing convenience.

  • Command Line: Partitioning

    Despite the popularity of LVM, traditional partitioning is still preferred by some admins. We provide some tips to consider before choosing a partitioning scheme for your setup.

comments powered by Disqus