A better way to list partitions and mounting points

Posted by Diego Assencio on 2014.04.27 under Linux (Storage)

The mount -l command (or just mount) is often used to list all mounted partitions on a system, while fdisk -l is often used to list all partitions from any device which contains a partition table (a hard disk being the most common example). There is, however, an alternative tool which offers some functionality from both these tools and has a really nice output: lsblk.

The lsblk command lists all block devices in the system as trees. If a device is mounted somewhere, its mounting point is also shown. Here is the output of lsblk on my laptop (notice that major and minor numbers as well as partition sizes are also shown):

sda                     8:0    0 465.8G  0 disk
├─sda1                  8:1    0     1K  0 part
├─sda2                  8:2    0 433.1G  0 part
│ └─data (dm-1)       252:1    0 433.1G  0 crypt /media/data
├─sda3                  8:3    0   3.7G  0 part
│ └─cryptswap1 (dm-0) 252:0    0   3.7G  0 crypt [SWAP]
├─sda4                  8:4    0    15G  0 part  /
├─sda5                  8:5    0   9.3G  0 part
└─sda6                  8:6    0   4.7G  0 part  /home
sr0                    11:0    1  1024M  0 rom
sdb                     8:16   1  14.5G  0 disk
└─sdb1                  8:17   1  14.5G  0 part

The output above shows my main disk (sda) as well as its partitions:

sda1 is an extended partition which contains sda5 and sda6 (lsblk interprets it as a small partition containing the first EBR of this extended partition, but fdisk would in this case show this extended partition more explicitly)
sda2 is an encrypted partition mounted on /media/data
sda3 is my (encrypted) swap partition
sda4 contains the operational system files and is mounted on /
sda5 is currently not being used
sda6 contains the user home directories

The output shows also my CD-ROM drive (sr0) and another disk (sdb) which is an attached USB disk containing a single partition (sdb1) which is not mounted anywhere. Since lsblk only lists block devices, it will not display encrypted home directories mounted with ecryptfs, partitions mounted with sshfs etc.

The mount command lists all mounted partitions from physical disks as well as RAM disks but does not list unmounted partitions. Although rich in details, visually extracting information from its output is not as easy as it is with lsblk.

/dev/sda4 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/sda6 on /home type ext4 (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
/home/myuser/.Private on /home/myuser type ecryptfs (ecryptfs_check_dev_ruid...)
/dev/mapper/data on /media/data type ext4 (rw)

Notice how mount shows the mounting point for my encrypted home directory (highlighted) and all virtual and temporary file systems of type sysfs, proc, tmpfs etc.

While mount usually keeps a list of mounted partitions on /etc/mtab and uses that file for listing them to the user, lsblk gathers information directly from sysfs.

As a final note, lsblk can build its output as a list with the -l option and also output information about the topology of each block device (e.g. sector size) and device ownerships with the -t and -m options respectively. For more, see the manual of lsblk:

man lsblk


No comments posted yet.