VirtualBox上安装FreeBSD

发布时间:2026/7/15 6:39:38
VirtualBox上安装FreeBSD 环境Windows操作系统VirtualBox Version 7.1.8 r168469 (Qt6.5.3)。想安装FreeBSD操作系统。下载介质FreeBSD官网提供虚机下载。虚机提供多种格式一定要先读READMEFreeBSD virtual machine disk images are available in various formats for several hypervisors. Disk image formats and the supported hypervisors are: vhd: VirtualPC, Hyper-V, Xen, VirtualBox vmdk: VMWare qcow2: Qemu, KVM raw: bhyve, other hypervisors that support unformatted raw disk image因为我的VMM是VirtualBox所以要下载vhd格式。我选择的是FreeBSD 14.4版本即使是vhd格式也有3个文件可供下载FreeBSD-14.4-RELEASE-amd64-ufs.vhd.xz经典安装FreeBSD-14.4-RELEASE-amd64-zfs.vhd.xz 企业级安装ZFS包括快照等功能FreeBSD-14.4-RELEASE-amd64.vhd.xz (默认安装)最终我选择的是默认安装。文件大小为600M$ls-1sh*.xz 605M FreeBSD-14.4-RELEASE-amd64.vhd.xz创建虚机解压下载的文件Windows下可以用7zip解压后2.5G。$ls-1sh*.vhd2.5G FreeBSD-14.4-RELEASE-amd64.vhd启动VirtualBox选择’New’创建虚机设定VM NameOS选择BSD内存配置为默认的1G:然后展开Specify Virtual hardware在Specify virtual hard disk下选择Use an Existing Virtual Hard Disk File:这个新的磁盘还不存在需要通过Add添加磁盘大小为6.03G 使用已有磁盘时也可以先把磁盘移动到比较规范的位置如C:\Users\XiaoYu\VirtualBox VMs\FreeBSD。扩容虚拟磁盘其实这是事后才知道的。因为后续安装VirtualBox Guest Addition需要2G多的空间。此时先不要启动虚机因为虚拟磁盘的大小只有在关机时才能修改。进入菜单FileToolsMedia将磁盘的Virtual Size修改为10G。启动虚机启动FreeBSD用户名输入root口令回车即可当前空间状态rootfreebsd:~# df -hFilesystem Size Used Avail Capacity Mounted on /dev/gpt/rootfs8.7G2.4G5.6G30% / devfs1.0K 0B1.0K0% /dev /dev/gpt/efiesp 32M 649K 31M2% /boot/efirootfs不到9G因为还有1G的swap。rootfreebsd:~# gpart show -l ada03420971446ada0 GPT(10G)341221bootfs(61K)156665842efiesp(33M)6674020971523swapfs(1G)2163892188075884rootfs(9G)配置SSH登录我们把配置SSH放在第一步是因为终端字符界面太丑了而且也没法拷贝粘贴。配置sshd允许root登录vi/etc/ssh/sshd_config PermitRootLoginyes配置和启动sshd服务sysrcsshd_enableYESservicesshd start为root用户设置口令passwdroot为虚机配置port forwarding例如将宿主机的8822端口映射为客户机的22端口。然后PuTTY ssh登录成功也可以拷贝粘贴了安装VirtualBox Guest Additions先更新系统pkg update-f输出如下rootfreebsd:~# pkg update -fThe package management tool is not yet installed on your system. Do you want to fetch andinstallit now?[y/N]: y Bootstrapping pkg from pkghttps://pkg.FreeBSD.org/FreeBSD:14:amd64/quarterly, please wait... Verifying signature with trusted certificate pkg.freebsd.org.2013102301...doneInstalling pkg-2.7.5... Extracting pkg-2.7.5:100% Updating FreeBSD repository catalogue... Fetching meta.conf:100%179B0.2kB/s 00:01 Fetching data:100%11MiB1.2MB/s 00:09 Processing entries:100% FreeBSD repository update completed.37777packages processed. Updating FreeBSD-kmods repository catalogue... Fetching meta.conf:100%179B0.2kB/s 00:01 Fetching data:100%36KiB37.0kB/s 00:01 Processing entries:100% FreeBSD-kmods repository update completed.245packages processed. All repositories are up to date.更新后空间状态只用了0.1Grootfreebsd:~# df -h /Filesystem Size Used Avail Capacity Mounted on /dev/gpt/rootfs8.7G2.5G5.5G31% /然后安装VirtualBox Guest Additionspkginstall-yvirtualbox-ose-additions日志如下rootfreebsd:~# pkg install -y virtualbox-ose-additionsUpdating FreeBSD repository catalogue... FreeBSD repository is up to date. Updating FreeBSD-kmods repository catalogue... FreeBSD-kmods repository is up to date. All repositories are up to date. Updating database digests format:100% The following60package(s)will be affected(of0checked):... Number of packages to be installed:60The process will require2GiBmorespace.364MiB to be downloaded.... Checking integrity...done(0conflicting)...CreatinggroupsCreating groupmessagebuswith gid556CreatingusersCreating usermessagebuswith uid556... VirtualBox Guest Additions are installed. Toenableand start the required services:# sysrc vboxguest_enableYES# sysrc vboxservice_enableYESTo start the services, restart the system. In some situations, a panic will occur when the kernel module loads. Having nomorethan one virtual CPU might mitigate the issue. For features such as window scaling and clipboard sharing, membership of the wheel group is required. With usernamejerryas an example:# pw groupmod wheel -m jerryThe settings dialogueforFreeBSD guests encourages use of the VMSVGA graphics controller. Whilst this might suit installations of FreeBSD without a desktop environment(a common usecase), it is not appropriate where Guest Additions are installed. Where Guest Additions are installed:1. prefer VBoxSVGA2.donotenable3D acceleration(doing so will invisibly lose the preferenceforVBoxSVGA)You may ignore the yellow alert that encourages use of VMSVGA. --NOTICE: This port is deprecated;you may wish to reconsider installing it: Upstream EOL reaches on2024-01-31, use emulators/virtualbox-ose-additions-72 instead. It is scheduled to be removed on or after2026-12-31.从输出可知此安装需要至少2 GiB 空间这也是之前我们需要扩容的原因。当前空间没想到安装Guest Addition使用了2.7Grootfreebsd:~# df -h .Filesystem Size Used Avail Capacity Mounted on /dev/gpt/rootfs8.7G5.2G2.8G65% /根据上面命令输出的提示需要将virtualbox-ose-additions更新为virtualbox-ose-additions-72。很快就完成了空间几乎没变# pkg install -y virtualbox-ose-additions-72# pkg info | grep virtualbox-ose-additionsvirtualbox-ose-additions-72-7.2.12.1404000 VirtualBox additionsforFreeBSD guests设置服务并重启系统sysrcvboxguest_enableYESsysrcvboxservice_enableYES确认服务正常以及模块已加载# service vboxservice statusvboxservice is running as pid766.# kldstat | grep vboxguest420xffffffff8281f000 36b40 vboxguest.ko配置主机客户机共享目录在virtualbox中创建共享目录例如名称为Downloads配置共享目录后需重启才能生效。确认共享文件系统的模块已加载注意最新的模块名为vboxvfs而非vboxsf了# find /boot -name *.ko | grep -i vbox/boot/modules/vboxvfs.ko /boot/modules/vboxguest.ko# kldload vboxvfs# kldstat | grep vbox420xffffffff8281f000 38d00 vboxguest.ko510xffffffff82858000 26bd1 vboxvfs.ko然后挂载共享文件系统# mount_vboxvfs Downloads /mnt/share# df -h /mnt/shareFilesystem Size Used Avail Capacity Mounted on Downloads 237G 190G 48G80% /mnt/share