在 Hyper-v 上运行 FreeBSD 的最佳做法Best practices for running FreeBSD on Hyper-V

适用于: Azure Stack HCI,版本 20H2;Windows Server 2019,Windows Server 2016,Hyper-v Server 2016,Windows Server 2012 R2,Hyper-v server 2012 R2,Windows Server 2012,Hyper-v Server 2012,Windows Server 2008 R2,Windows 10,Windows 8.1,Windows 8,Windows 7.1,Windows 7Applies To: Azure Stack HCI, version 20H2; Windows Server 2019, Windows Server 2016, Hyper-V Server 2016, Windows Server 2012 R2, Hyper-V Server 2012 R2, Windows Server 2012, Hyper-V Server 2012, Windows Server 2008 R2, Windows 10, Windows 8.1, Windows 8, Windows 7.1, Windows 7

本主题包含在 Hyper-v 虚拟机上作为来宾操作系统运行 FreeBSD 的建议列表。This topic contains a list of recommendations for running FreeBSD as a guest operating system on a Hyper-V virtual machine.

在 Hyper-v 上的 FreeBSD 10.2 中启用 CARPEnable CARP in FreeBSD 10.2 on Hyper-V

(CARP) 的常见地址冗余协议允许多台主机共享相同的 IP 地址和虚拟主机 ID (VHID) ,以帮助提供一个或多个服务的高可用性。The Common Address Redundancy Protocol (CARP) allows multiple hosts to share the same IP address and Virtual Host ID (VHID) to help provide high availability for one or more services. 如果一个或多个主机出现故障,其他主机会以透明方式接管,因此用户不会注意到服务失败。若要在 FreeBSD 10.2 中使用 CARP,请按照 FreeBSD 手册 中的说明进行操作,然后在 Hyper-v 管理器中执行以下操作。If one or more hosts fail, the other hosts transparently take over so users won't notice a service failure.To use CARP in FreeBSD 10.2, follow the instructions in the FreeBSD handbook and do the following in Hyper-V Manager.

  • 验证虚拟机是否具有网络适配器,并为其分配一个虚拟交换机。Verify the virtual machine has a Network Adapter and it's assigned a virtual switch. 选择虚拟机并选择 "操作 > 设置"。Select the virtual machine and select Actions > Settings.

已选择网络适配器的虚拟机设置的屏幕截图

  • 启用 MAC 地址欺骗。Enable MAC address spoofing. 为此,请按以下步骤操作:To do this,

    1. 选择虚拟机并选择 "操作 > 设置"。Select the virtual machine and select Actions > Settings.

    2. 展开 " 网络适配器 ",然后选择 " 高级功能"。Expand Network Adapter and select Advanced Features.

    3. 选择 " 启用 MAC 地址欺骗"。Select Enable MAC Address spoofing.

为磁盘设备创建标签Create labels for disk devices

在启动过程中,将在发现新设备时创建设备节点。During startup, device nodes are created as new devices are discovered. 这可能意味着在添加新设备时,设备名称可能会改变。This can mean that device names can change when new devices are added. 如果在启动过程中出现根装入错误,则应为每个 IDE 分区创建标签,以避免冲突和更改。If you get a ROOT MOUNT ERROR during startup, you should create labels for each IDE partition to avoid conflicts and changes. 若要了解如何操作,请参阅为 磁盘设备添加标签To learn how, see Labeling Disk Devices. 下面是示例。Below are examples.

重要

在进行任何更改之前,请创建 fstab 的备份副本。Make a backup copy of your fstab before making any changes.

  1. 将系统重新启动到单用户模式。Reboot the system into single user mode. 为此,可以选择 "启动" 菜单选项 2 for FreeBSD 10.3 + (选项4进行 FreeBSD) ,或从启动提示符执行 "启动"。This can be accomplished by selecting boot menu option 2 for FreeBSD 10.3+ (option 4 for FreeBSD 8.x), or performing a 'boot -s' from the boot prompt.

  2. 在单用户模式下,创建 fstab 中列出的每个 IDE 磁盘分区的几何标签 (根和交换) 。In Single user mode, create GEOM labels for each of the IDE disk partitions listed in your fstab (both root and swap). 下面是 FreeBSD 10.3 的示例。Below is an example of FreeBSD 10.3.

    # cat  /etc/fstab
    # Device           Mountpoint      FStype  Options   Dump   Pass#
    /dev/da0p2         /               ufs     rw        1       1
    /dev/da0p3         none            swap    sw        0       0
    
    # glabel  label rootfs  /dev/da0p2
    # glabel  label swap   /dev/da0p3
    # exit
    

    有关几何标签的其他信息,请参阅: 标记磁盘设备Additional information on GEOM labels can be found at: Labeling Disk Devices.

  3. 系统将继续执行多用户启动。The system will continue with multi-user boot. 启动完成后,编辑/etc/fstab 并将常规设备名称替换为各自的标签。After the boot completes, edit /etc/fstab and replace the conventional device names, with their respective labels. 最终的/etc/fstab 将如下所示:The final /etc/fstab will look like this:

    # Device                Mountpoint      FStype  Options         Dump    Pass#
    /dev/label/rootfs       /               ufs     rw              1       1
    /dev/label/swap         none            swap    sw              0       0
    
  4. 现在可以重新启动系统。The system can now be rebooted. 如果一切正常,会正常运行,装载将显示:If everything went well, it will come up normally and mount will show:

    # mount
    /dev/label/rootfs on / (ufs, local, journaled soft-updates)
    devfs on /dev (devfs, local, mutilabel)
    

使用无线网络适配器作为虚拟交换机Use a wireless network adapter as the virtual switch

如果主机上的虚拟交换机基于无线网络适配器,请使用以下命令将 ARP 过期时间减少到60秒。If the virtual switch on the host is based on wireless network adapter, reduce the ARP expiration time to 60 seconds by the following command. 否则,VM 网络可能会在一段时间后停止工作。Otherwise the networking of the VM may stop working after a while.

   # sysctl net.link.ether.inet.max_age=60

另请参阅See also