> For the complete documentation index, see [llms.txt](https://docs.verge.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verge.io/knowledge-base/zh/virtual-machines/virtual-drive-trim.md).

# 虚拟驱动器 TRIM

从另一台虚拟化管理器导入虚拟机后，虚拟机内可用的剩余空间有时与 VergeOS 平台报告的可用空间不一致。这种差异通常是由于源 VM 中虚拟磁盘采用了厚置备，导致 VergeOS 无法识别未使用的磁盘空间。要解决此问题，需要在虚拟机内部对虚拟磁盘执行 TRIM/UNMAP 操作。

## 运行 TRIM 命令的前提条件

1. 在 VergeOS UI 中编辑相关虚拟驱动器，并确保 **丢弃** 已启用。
2. 确保虚拟驱动器使用的驱动器类型为 **virtIO-SCSI** 或 **SATA**.
3. 确保虚拟驱动器分配到 **固态层** （通常为 1-3 层）。

## 为 Windows 驱动器执行 TRIM

要在 Windows 环境中手动执行 TRIM 操作，请按以下步骤操作：

1. 启动 **PowerShell** ，并使用管理员用户身份运行。
2. 在 PowerShell 提示符下，输入以下命令：

   ```powershell
   Optimize-Volume -DriveLetter YourDriveLetter -ReTrim -Verbose
   ```

   示例：

   ```powershell
   Optimize-Volume -DriveLetter E -ReTrim -Verbose
   ```
3. 按 **Enter** 并等待命令完成。

随着 TRIM 操作的进行，您可以看到 VergeOS 仪表板中报告的可用空间逐渐增加，因为卷中的空白数据被移除。

如果这不能解决问题，可能是未启用 TRIM。要检查 TRIM 是否已启用：

1. 运行以下 **FSUTIL** 命令：

   ```powershell
   fsutil behavior query disabledeletenotify
   ```

   如果值为 **1**，则该驱动器未启用 TRIM。
2. 要启用 TRIM，请运行：

   ```powershell
   fsutil behavior set disabledeletenotify 0
   ```

   启用后，请重新运行 TRIM 命令。

## 为 Linux 驱动器执行 TRIM

较新的 Linux 发行版默认通过 systemd 服务或 cron 作业启用了 TRIM。要检查自动 TRIM 是否已启用，请按以下步骤操作：

1. **确保上面的前提步骤** 已完成。

示例： **Ubuntu Server**

1. 启动终端。
2. 输入以下命令以检查状态：
   * 检查 TRIM 定时器/计划状态：

     ```bash
     sudo systemctl status fstrim.timer
     ```
   * 检查 TRIM 服务状态：

     ```bash
     sudo systemctl status fstrim
     ```

如果已启用 TRIM，操作将在下一个计划时间运行。如果未启用 TRIM，您可以使用以下命令手动执行 TRIM：

```bash
sudo fstrim -av
```

{% hint style="info" %}
建议启用自动 TRIM，以确保 VergeOS 与来宾操作系统之间的数据使用情况能够准确反映。
{% endhint %}

要启用自动 TRIM，请运行：

```bash
sudo systemctl enable fstrim.timer
```

有关 `fstrim`的更多信息，请访问 [man 手册页](https://man7.org/linux/man-pages/man8/fstrim.8.html).

***

{% hint style="info" %}
**文档信息**

* 最后更新：2024-09-03
* VergeOS 版本：4.12.6
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.verge.io/knowledge-base/zh/virtual-machines/virtual-drive-trim.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
