How many disks and partitions do I have mounted?

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,525
Reaction score
3,287
Credits
31,524

Using the df Command in Linux​

The df (disk free) command in Linux is used to display the amount of available disk space for file systems. It provides a quick overview of the disk usage on your system.

Basic Usage​

The basic syntax of the df command is:

Code:
 df [options] [file]

Example Output​

Here is an example output of the df -h command:

Code:
prompt> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb4 45G 17G 29G 37%
/ devtmpfs 4.0M 0 4.0M 0%
/dev tmpfs 32G 19M 32G 1%
/dev/shm efivarfs 128K 48K 76K 39%
/sys/firmware/efi/efivars tmpfs 13G 2.1M 13G 1%
/run tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-journald.service
tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-network-generator.service tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-udev-load-credentials.service tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-tmpfiles-setup-dev-early.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-sysctl.service
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-tmpfiles-setup-dev.service tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-vconsole-setup.service
tmpfs 32G 260K 32G 1%
/tmp /dev/sdb3 2.9G 543M 2.4G 19%
/boot /dev/sdb5 35G 24G 12G 68%
/var /dev/sdb7 385G 91G 294G 24%
/home /dev/sdb2 340M 7.6M 333M 3%
/boot/efi tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-tmpfiles-setup.service tmpfs 1.0M 0 1.0M 0%
/run/credentials/systemd-resolved.service tmpfs 6.3G 136K 6.3G 1%
/run/user/1000 /dev/sda1 300M 6.8M 294M 3%
/sda /dev/nvme0n1p1 1.8T 762G 979G 44% /nvme
tmpfs 6.3G 84K 6.3G 1% /run/user/0

Using the -k Option​

The -k option displays the disk space in kilobytes.

Code:
 df -k

Using the -h Option​

The -h option displays the disk space in a human-readable format (e.g., KB, MB, GB).

Code:
 df -h

Specifying a Specific Partition​

You can also specify a specific partition to see its disk usage. For example, to see the disk usage of /dev/sdb4, you can use:

Code:
 df -h /dev/sdb4

Understanding the Output​

In the example output above, you have three disks: sda, sdb, and nvme0n1. Each disk can have multiple partitions. For example, /dev/sdb has several partitions such as /dev/sdb4, /dev/sdb3, /dev/sdb5, /dev/sdb7, and /dev/sdb2.

  • Filesystem: The name of the disk or partition.
  • Size: The total size of the disk or partition.
  • Used: The amount of space used.
  • Avail: The amount of available space.
  • Use%: The percentage of space used.
  • Mounted on: The mount point of the filesystem.

Viewing Disk Partitions​

To see the size, used space, and free space of each partition, you can use the df command with the -h option:

Code:
 df -h

Understanding tmpfs and devtmpfs​

  • tmpfs: A temporary filesystem that uses your system's RAM to store files. It is often used for temporary files that do not need to be stored permanently.
  • devtmpfs: A special filesystem used by the Linux kernel to manage device nodes in the /dev directory. It is also stored in RAM and is not a physical partition on your hard drives.
These filesystems are not actual physical partitions but are used to manage temporary and device-related files efficiently.

Understanding /run/credentials File Systems​

The /run/credentials file systems are part of the systemd service manager's credential management system. This system is designed to securely acquire and pass credential data to services and applications.

  • Purpose: The /run/credentials directories store sensitive information such as cryptographic keys, certificates, passwords, and other authentication data required by various services and applications.
  • Location: Credentials are placed in /run/credentials/@system/ for regular credentials and /run/credentials/@encrypted/ for credentials that need to be decrypted or validated before use.
  • Security: These credentials are stored in non-swappable memory (RAM) to ensure they are not written to disk, enhancing security.

How They Work​

  • Acquisition: Credentials are acquired at the moment of service activation and released when the service is deactivated. They remain immutable during the service runtime.
  • Access: Services access these credentials as regular files, with paths derived from the environment variable $CREDENTIALS_DIRECTORY. Access is restricted to the service's user, and each access is checked by the kernel.
  • Encryption: Credentials can be encrypted and authenticated using keys derived from a TPM2 chip or stored in /var/, or both.

Benefits​

  • Security: Unlike environment variables, which can be inherited down the process tree and have size limitations, the credential system provides a more secure and flexible way to handle sensitive data.
  • Isolation: If a service uses file system namespacing, the loaded credential data is invisible to other services, ensuring isolation.

Example Usage​

To see the credentials in use, you can navigate to the /run/credentials directory and list its contents:

Code:
 ls /run/credentials

This will show you the credentials currently managed by systemd for your services.

Conclusion​

The df command is a useful tool to see what disks you have in use, how many partitions are on them, and how big each partition is. By using options like -k and -h, you can get a detailed view of your disk usage in different formats. Additionally, you can specify a specific partition to get more focused information. Understanding the /run/credentials file systems helps in managing sensitive data securely and efficiently.
 
Last edited:


mount​

  • Purpose: The mount command is used to attach file systems to the file system hierarchy at a specified mount point. It can also display all currently mounted file systems.
  • Usage: It helps you manage and view the file systems that are currently mounted and their mount points.
  • Example Output:/dev/sda1 on / type ext4 (rw,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    /dev/sdb1 on /backup type ext4 (rw,relatime)

Key Differences​

  • Functionality: df -h is primarily for checking disk space usage, while mount is for managing and viewing mounted file systems.
  • Output: df -h provides information about disk space usage in a human-readable format, whereas mount shows details about the file systems and their mount points.
 


Members online


Top