macOS High Sierra 安装 VirtualBox 被坑记

由于周六要参加容器化培训,需要Mac虚拟机环境,恰逢我新入手新mac电脑,故而需要重装一个VirtualBox。
本想着简单的事情三五分钟就搞定的,足足用了一个晚上。

  1. 使用安装VirtualBox
    brew cask install virtualbox
    会提示:
    The install failed (The Installer encountered an error that caused the installation to fail. Contact the software manufacturer for assistance.)
    
  2. 执行脚本(需要root权限)
#!/bin/bash

unload() {
        if [ `ps -ef | grep -c VirtualBox$` -ne 0 ]
        then
                echo "VirtualBox still seems to be running. Please investigate!!"
                exit 1;
        elif [ `ps -ef | grep -c [V]ir` -gt 0 ]
        then
                echo "Stopping running processes before unloading Kernel Extensions"
                ps -ef | grep [V]ir | awk '{print $2}' | xargs kill
        fi
        echo "Unloading Kernel Extensions"
        kextstat | grep "org.virtualbox.kext.VBoxUSB" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxUSB
        kextstat | grep "org.virtualbox.kext.VBoxNetFlt" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxNetFlt
        kextstat | grep "org.virtualbox.kext.VBoxNetAdp" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxNetAdp
        kextstat | grep "org.virtualbox.kext.VBoxDrv" > /dev/null 2>&1 && sudo kextunload -b org.virtualbox.kext.VBoxDrv
}

load() {
        echo "Loading Kernel Extentions"
        sudo kextload "/Library/Application Support/VirtualBox/VBoxDrv.kext" -r "/Library/Application Support/VirtualBox/"
        sudo kextload "/Library/Application Support/VirtualBox/VBoxNetAdp.kext" -r "/Library/Application Support/VirtualBox/"
        sudo kextload "/Library/Application Support/VirtualBox/VBoxNetFlt.kext" -r "/Library/Application Support/VirtualBox/"
        sudo kextload "/Library/Application Support/VirtualBox/VBoxUSB.kext" -r "/Library/Application Support/VirtualBox/"
}

case "$1" in
        unload|remove)
                unload
                ;;
        load)
                load
                ;;
        *|reload)
                unload
                load
                ;;
esac

将其保存至shell脚本中直接运行。

  1. 打开System Preferences → Security & Privacy → General
    macOS High Sierra 安装 VirtualBox 被坑记_第1张图片
    image

点击 Allow
重点来了: 在macOS 10.13.4 版本中有bug,鼠标直接点击不了Allow 按钮,所以只能用Tab 键将focus移到Allow上面,按下空格。

  1. 执行重新安装命令
    brew cask reinstall virtualbox

大功告成!

你可能感兴趣的:(macOS High Sierra 安装 VirtualBox 被坑记)