# virt-df

`virt-df` is a tool that provides a summary of disk space usage for virtual machines (VMs) running under a hypervisor, such as **libvirt**, **KVM**, or other virtualization technologies. It works similarly to the traditional `df` command in Linux but is specifically designed for virtualized environments. This command helps you track how much disk space is being used by different virtual disks attached to virtual machines.

#### Purpose of `virt-df`

The primary purpose of `virt-df` is to give you an overview of the disk space usage for virtual machines. It can be helpful for administrators managing virtualized infrastructures, as it allows you to track how much disk space VMs are consuming, identify potential issues like low disk space, and plan resource allocation effectively.

#### How `virt-df` Works

`virt-df` queries the metadata of virtual disks attached to VMs and reports the disk space used within the virtual machines. It can show usage statistics for both the disk image files and the underlying virtualized filesystems within the VMs themselves.

#### Basic Syntax

```bash
virt-df [options] [VM-name]
```

* **VM-name**: The name or ID of the virtual machine. If not specified, it will report disk usage for all VMs.

#### Common Options

* `-a, --all`: Show disk usage for all virtual machines. This is the default if no VM name is specified.
* `-h, --human-readable`: Makes the output more human-readable (e.g., uses MB, GB for sizes).
* `-v, --verbose`: Provides more detailed information about the virtual machines and disk usage.
* `--sort <field>`: Sort the output by a specific field, like disk space usage or VM name.
* `-l, --list`: Lists all available virtual machines.
* `--no-mount`: Avoids trying to mount virtual disks, which can speed up the operation if disk mounting is not required.

#### Example Usage

1. **List Disk Space for All VMs**:

   To display the disk space usage for all virtual machines managed by **libvirt** (or the hypervisor in use):

   ```bash
   virt-df
   ```

   This will show disk space usage for all virtual machines in a simple summary format.
2. **Check Disk Usage for a Specific VM**:

   To check the disk usage of a specific VM, you can specify the VM name or ID. For example:

   ```bash
   virt-df vm1
   ```

   This will show the disk usage statistics only for the virtual machine named `vm1`.
3. **Human-Readable Output**:

   To make the output more readable, you can use the `-h` option to show disk sizes in a human-readable format:

   ```bash
   virt-df -h vm1
   ```

   This will display disk usage in a more convenient format (e.g., GB, MB).
4. **Verbose Output**:

   For detailed output, including more information about each virtual disk, use the `-v` flag:

   ```bash
   virt-df -v
   ```

   This will display additional information about the disk space and the VM configurations.
5. **Sorting Output by Disk Usage**:

   To sort the output by disk space usage, you can use the `--sort` option. For example:

   ```bash
   virt-df --sort size
   ```

   This will sort the output by the size of the virtual disks.

#### Sample Output

Here’s an example of what `virt-df` might output when run:

```bash
$ virt-df -h
Filesystem                Size  Used Avail Use% Mounted on
/dev/sda1                 50G   10G   40G  20% /
/dev/sdb1                 100G  60G   40G  60% /data
```

* **Filesystem**: The virtual disk (e.g., `/dev/sda1`, `/dev/sdb1`).
* **Size**: The total size of the virtual disk.
* **Used**: The amount of disk space that is used.
* **Avail**: The available disk space.
* **Use%**: The percentage of disk space used.
* **Mounted on**: The mount point within the VM where the disk is mounted.

#### Use Cases for `virt-df`

1. **Track Disk Usage in Virtualized Environments**:\
   Administrators can use `virt-df` to keep an eye on disk usage across multiple virtual machines and ensure that no VM runs out of disk space.
2. **Monitor Virtual Disk Growth**:\
   As VMs grow in usage, disk space can become a bottleneck. Using `virt-df`, you can track the disk growth over time and plan accordingly for storage needs.
3. **Efficiency Optimization**:\
   Identifying VMs with low disk space or over-provisioned storage can help optimize the virtualized environment by reallocating resources or adding more storage to specific VMs.
4. **VM Migration Planning**:\
   When migrating VMs, knowing their disk usage is important to ensure the target host has enough space available for the virtual disks.

#### Considerations and Limitations

* **Disk Type**: `virt-df` works with virtualized disks that are managed by **libvirt** or a compatible hypervisor. If you're using a hypervisor that is not supported by libvirt, `virt-df` may not work.
* **Permissions**: The user running `virt-df` must have sufficient permissions to query the virtual machines and their disk images. This typically requires root or appropriate privileges on the system running the hypervisor.
* **Filesystem Mounting**: By default, `virt-df` may attempt to mount virtual disks to read the filesystem data. In some cases, the tool may be configured to avoid mounting, which could speed up the process when mounting is unnecessary.

#### Conclusion

`virt-df` is a useful tool for administrators managing virtualized environments. It allows them to quickly assess the disk space usage across multiple virtual machines, ensuring that resources are allocated effectively. The tool provides essential information for managing storage in virtualized environments, helping avoid potential issues with disk space.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/file-systems-cocepts/lpic3-305/virt-df.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
