# 24.4.使用 VirtualBox™ 安装 FreeBSD

FreeBSD 在 VirtualBox™ 中作为虚拟机运行效果良好。该虚拟化软件可在大多数常见操作系统上运行，包括 FreeBSD 本身。

VirtualBox™ 的虚拟机增强功能提供以下支持：

* 剪贴板共享。
* 鼠标指针集成。
* 宿主时间同步。
* 窗口缩放。
* 无缝模式。

> **注意**
>
> 以下命令在 FreeBSD 虚拟机中执行。

首先，在 FreeBSD 虚拟机中安装 [emulators/virtualbox-ose-additions](https://cgit.freebsd.org/ports/tree/emulators/virtualbox-ose-additions/) 软件包或 Ports。这将安装该 Ports：

```sh
# cd /usr/ports/emulators/virtualbox-ose-additions && make install clean
```

在 **/etc/rc.conf** 中添加以下内容：

```ini
vboxguest_enable="YES"
vboxservice_enable="YES"
```

如果使用了 [ntpd(8)](https://man.freebsd.org/cgi/man.cgi?query=ntpd\&sektion=8\&format=html) 或 [ntpdate(8)](https://man.freebsd.org/cgi/man.cgi?query=ntpdate\&sektion=8\&format=html)，应禁用宿主时间同步：

```sh
vboxservice_flags="--disable-timesync"
```

Xorg 会自动识别 `vboxvideo` 驱动。也可以在 **/etc/X11/xorg.conf** 中手动指定：

```ini
Section "Device"
	Identifier "Card0"
	Driver "vboxvideo"
	VendorName "InnoTek Systemberatung GmbH"
	BoardName "VirtualBox Graphics Adapter"
EndSection
```

若要使用 `vboxmouse` 驱动，请修改 **/etc/X11/xorg.conf** 中的鼠标部分：

```ini
Section "InputDevice"
	Identifier "Mouse0"
	Driver "vboxmouse"
EndSection
```

在宿主机和虚拟机之间传输文件的共享文件夹，可通过 `mount_vboxvfs` 挂载访问。可以使用 VirtualBox 图形界面或 `vboxmanage` 创建共享文件夹。例如，要为名为 *BSDBox* 的虚拟机创建一个名为 *myshare* 的共享文件夹，并将其挂载到 **/mnt/bsdboxshare**，请执行：

```sh
# vboxmanage sharedfolder add 'BSDBox' --name myshare --hostpath /mnt/bsdboxshare
```

注意，共享文件夹名称不得包含空格。在虚拟机系统中挂载共享文件夹的命令如下：

```sh
# mount_vboxvfs -w myshare /mnt
```


---

# 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://handbook.bsdcn.org/di-24-zhang-xu-ni-hua/24.4.-shi-yong-virtualbox-an-zhuang-freebsd.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.
