VirtualBox

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page VirtualBox and the translation is 76% complete.
Other languages:

VirtualBox は、ホストペレーティングシステムの中でゲストオペレーティングシステムを再起動の必要なしに実行できるようにする、クロスプラットフォームの仮想化ソフトウェアです。2010 年より、VirtualBox ソフトウェアは Oracle Corporation によって修正および保守されています。

用語

用語 説明
ホストオペレーティングシステム ホストとなるコンピュータ。ほとんどの場合はそこにある物理的なハードウェアです。Gentoo ユーザにとっては、ホストオペレーティングシステムは Gentoo Linux であることでしょう。
ゲストオペレーティングシステム VirtualBox エミュレーション環境内にこれからインストールされる、あるいは現在インストールされているオペレーティングシステム。可能なオペレーティングシステムの選択肢には Microsoft Windows、Solaris、BSD、Debian、Ubuntu などが含まれます。
VirtualBox Guest Additions ゲストオペレーティングシステムのためのドライバ。これらのドライバは、ゲストオペレーティングシステムによってインストールされる標準ドライバと比較して、ホストオペレーティングシステムとのよりスムーズな操作を提供します。

インストール

カーネル

VirtualBox ホストは以下のカーネル設定オプションを必要とします:

カーネル
[*] Enable loadable module support  ---> 
  [ ]   Trim unused exported kernel symbols
[*] Virtualization  --->

USE フラグ

USE flags for app-emulation/virtualbox Family of powerful x86 virtualization products for enterprise and home use

alsa Add support for media-libs/alsa-lib (Advanced Linux Sound Architecture)
dbus Enable dbus support for anything that needs it (gpsd, gnomemeeting, etc)
debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces
dist-kernel Enable subslot rebuilds on Distribution Kernel upgrades
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
dtrace Install dtrace Extension Pack
gui Enable support for a graphical user interface
headless Build without any graphic frontend
java Add support for Java
lvm Build VBoxVolInfo that needs devicemapper from sys-fs/lvm2.
modules-compress Install compressed kernel modules (if kernel config enables module compression)
modules-sign Cryptographically sign installed kernel modules (requires CONFIG_MODULE_SIG=y in the kernel)
nls Add Native Language Support (using gettext - GNU locale utilities)
opengl Add support for OpenGL (3D graphics)
opus Enable Opus audio codec support
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
pax-kernel Apply patch needed for pax enabled kernels.
pch Enable precompiled header support for faster compilation at the expense of disk space and memory
pulseaudio Add sound server support via media-libs/libpulse (may be PulseAudio or PipeWire)
python Add optional support/bindings for the Python language
qt5 Add support for the Qt 5 application and UI framework
sdk Enable building of SDK
sdl Add support for Simple Direct Layer (media library)
strip Allow symbol stripping to be performed by the ebuild for special files
udev Controls installation of special USB udev rules.
vboxwebsrv Build and install the VirtualBox webservice
vde Support for VDE networking via net-misc/vde
vnc Enable VNC (remote desktop viewer) support

メモ
virtualbox 7.0.4 (2022-11 時点では testing ブランチ) 以降、gui USE フラグがグラフィカルユーザインターフェース (GUI) のインストールを制御し、これはデフォルトで有効化されています。virtualbox 7.0.2 までは qt5 USE フラグが GUI のインストールを制御します。これもまたデフォルトで有効化されています。
メモ
virtualbox 7.0.4 以降、headless USE フラグは削除されています。同様の効果は、guiopengl、および sdl USE フラグを無効化することで得ることができます。

Emerge

root #emerge --ask app-emulation/virtualbox

Microsoft Windows ゲスト

すべての必要な Microsoft Windows ゲストドライバを含む Guest Additions ISO イメージを取得するために、app-emulation/virtualbox-additions パッケージをホストシステム上に emerge してください:

root #emerge --ask app-emulation/virtualbox-additions

Gentoo ゲスト

カーネル設定

Gentoo をゲストシステムとして実行するときには、VirtualBox によってエミュレートされるハードウェアへの適切なサポートを得るために、ゲストシステムで以下のカーネルオプションを有効化 (組み込みで、またはモジュールとして) してください:

カーネル カーネル 5.15 より前の汎用フレームバッファ
Bus options (PCI etc.)  --->
    [*] Mark VGA/VBE/EFI FB as generic system framebuffer
カーネル カーネル 5.15 以降の汎用フレームバッファ
Device Drivers  --->
  Firmware Drivers  --->
    [*] Mark VGA/VBE/EFI FB as generic system framebuffer
カーネル VirtualBox ハードウェアのサポート
Device Drivers  --->
    <*> Serial ATA and Parallel ATA drivers (libata)  --->
        [*] AHCI SATA support
        [*] ATA SFF support (for legacy IDE and PATA)
        [*]   ATA BMDMA support
        [*]     Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support
    <*> Network device support  --->
        <*> Ethernet driver support  --->
            [*] Intel devices
            [*]   Intel(R) PRO/1000 Gigabit Ethernet support
    Input device support  --->
        <*> Keyboards  --->
            [*] AT keyboard
        <*> Mice  --->
            [*] PS/2 mouse
    <*> Virtio drivers  --->
        <*> PCI driver for virtio devices
    Graphics support  --->
        <*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)  --->
            [*] Enable legacy fbdev support for your modesetting driver
        <*> DRM driver for VMware Virtual GPU
            <*> Enable framebuffer console under vmwgfx by default
        Frame buffer Devices  --->
            <*> Support for frame buffer devices  --->
                [*] Enable Firmware EDID
                [*] Simple framebuffer support
        <*> Console display driver support  --->
            [*] Framebuffer Console support
            [*]   Map the console to the primary display device
    <*> Sound card support  --->
        <*> Advanced Linux Sound Architecture  --->
            <*> PCI sound devices  --->
                [*] Intel/SiS/nVidia/AMD/ALi AC97 Controller
    <*> USB support  --->
        [*] xHCI HCD (USB 3.0) support
        [*] EHCI HCD (USB 2.0) support

Guest Additions

Guest Additions をインストールするには、Gentoo ゲストシステムで以下のコマンドを実行してください:

root #emerge --ask app-emulation/virtualbox-guest-additions

OpenRC を使用している場合は、Guest Additions と D-Bus が再起動後に開始されるようにしてください:

root #rc-update add virtualbox-guest-additions default
root #rc-update add dbus default

systemd を使用している場合は、Guest Additions が再起動後に開始されるようにしてください:

root #systemctl enable --now virtualbox-guest-additions

共有クリップボード、ディスプレイのリサイズ、シームレスモード、ドラッグアンドドロップを有効化するには、(Gentoo ゲストシステム上で) X セッションを実行しているユーザが vboxguest グループに属していることを確認してください:

root #gpasswd -a <user> vboxguest

変更は、ユーザがサインアウトして再びサインインする (再ログインする) まで反映されないでしょう。

メモ
他の Linux ディストリビューションをゲストオペレーティングシステムとしてインストールするには、VirtualBox によって必要とされるドライバをインストールする方法についてのディストリビューションのドキュメンテーションを参照するか、公式の VirtualBox ドキュメンテーションを参照してください。
リサイズが機能しない

Due to the limitations of the VMSVGA described below, a daemon needs to be started in your X11 session for Guest resizing to work.

Usage: VBoxClient --clipboard|--draganddrop|--checkhostversion|--seamless|--vmsvga[-d|--nodaemon]
Starts the VirtualBox DRM/X Window System guest services.
 
Options:
  --clipboard        starts the shared clipboard service
  --draganddrop      starts the drag and drop service
  --checkhostversion starts the host version notifier service
  --seamless         starts the seamless windows service
  --vmsvga           starts VMSVGA dynamic resizing for x11/Wayland guests
  -f, --foreground   run in the foreground (no daemonizing)
  -d, --nodaemon     continues running as a system service
  -h, --help         shows this help text
  -v, --verbose      increases logging verbosity level
  -V, --version      shows version information

If the Guest Additions are installed correctly, the shared clipboard is working, etc., but the display can't be resized, open the VM's settings in the host-side VirtualBox Manager and look at Display → Graphics Controller. If it's set to VMSVGA, try changing it to VBoxSVGA while the guest is powered off. According to the VirtualBox docs, this works because auto-resizing in Linux guests is induced in part by changing the serial number of the simulated monitor, which can't be done under VMSVGA.[1]

GPU アクセラレーション

現代の VirtualBox は、Linux マシンに対してはデフォルトで VMware SVGA をエミュレートします。make.conf でそのサポートを有効化してください:

ファイル /etc/portage/make.conf
VIDEO_CARDS="vmware"

映像出力の選択を変更したら、代替の選択肢を選択してください:

ファイル /etc/portage/make.conf
VIDEO_CARDS="virtualbox"
重要
VIDEO_CARDS 設定に変更を加えた後は、その変更を反映させるために完全なアップグレードを実行したほうがよいでしょう。

Gentoo ゲスト内の VirtualBox 共有フォルダー

VirtualBox 共有フォルダーは virtualbox-guest-additions サービスが開始された後でのみマウントすることができます。これはブートシーケンス (OpenRC) の終わりの方で起こるため、/etc/fstab での共有フォルダーマウントは失敗するでしょう。以下のいずれかをお試しください:

  • noauto マウントオプションを追加し、/etc/local.d 内にマウント/アンマウントのペアのスクリプトを追加する。
  • サービスの追加依存を追加するための情報を /etc/rc.conf で確認する。

ユーザに手動で共有フォルダーをマウントさせたい場合は、そのユーザを vboxsf グループに追加する必要があります:

root #gpasswd -a larry vboxsf

高度なネットワーク関連

VirtualBox がインストールされた後の ebuild のメッセージに従って、高度なネットワーク構成のために sys-apps/usermode-utilities および net-misc/bridge-utils をインストールすることができます。高度なネットワーキングが必要な場合のみ、それらをインストールしてください:

root #emerge --ask sys-apps/usermode-utilities
root #emerge --ask net-misc/bridge-utils

設定

カーネルモジュール

vboxusers グループのメンバではないユーザは、VirtualBox を実行して使用することができないでしょう:

root #gpasswd -a <user> vboxusers

変更はユーザが再ログインするまで反映されないでしょう。

必要なドライバモジュールをカーネルにロードしてください。このモジュールは app-emulation/virtualbox-modules を emerge すると利用可能になります:

root #modprobe vboxdrv

省略可能なモジュール:

root #modprobe vboxnetadp
root #modprobe vboxnetflt

システムがブートするたびにモジュールを自動的にロードすることができます。/etc/modules-load.d ディレクトリ下に新しいファイルを作成して、ロードするカーネルモジュールを改行区切りで列挙してください:

ファイル /etc/modules-load.d/virtualbox.conf
vboxdrv
vboxnetadp
vboxnetflt

systemd

systemd システム上では、以下を実行することでモジュールをただちにロードすることができます:

root #systemctl start systemd-modules-load

ゲストマシンへのポートフォワーディングを有効化する

When booting LiveCDs or other live media, it can be handy to enable port forwarding from the host machine to the guest machine. None of the additional network configuration modes are necessary for a simple port forwarding setup, so do not dig too deep into upstream docs. Port forwarding can be handy when running a web server, an SSH daemon, or any other service that runs on a specific port.

まず、ゲスト VM がシャットダウンされていることを確認して、コマンドラインから次を実行してください:

user $VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

Be sure to replace "VM name" with the proper name of the guest virtual machine. The first number (2222) will be the port on the host machine. The second number (22) will be the port on the guest machine. Adjust accordingly, then reboot the virtual machine. This can also be performed via the GUI by clicking Settings -> Network -> Advanced (drop down) -> Port Forwarding.

さらなる詳細は上流のドキュメンテーションで見つけることができます。

使い方

There are many options which can influence behavior and performance of the virtual machines. If you don't know what these options are doing, leave them to their defaults. Virtual machines may become unbootable if the wrong options are set.

Here is a list of options that are safe to use:

  • Host I/O cache can safely be enabled for all virtual storage controllers.
  • If the host system's CPU supports hardware virtualization, enable the 'VT-x/AMD-V' option. It can drastically increase the performance of the virtual machines.

トラブルシューティング

virtualbox のビルドに失敗する

When the app-emulation/virtualbox package fails to build because the javac command cannot be found (even with a Java JDK (Java Development Kit) and a Java JRE (Java Runtime Environment) installed), it is likely the JRE has been set as the default system-vm. JRE packages do not contain javac. Make sure the correct system-vm (JDK) has been selected using the java-config command and then try rebuilding virtualbox. More information can be found in the Installing a virtual machine section of the Java User Guide.

virtualbox-modules のビルドに失敗する

Some users have issues with the app-emulation/virtualbox-modules package failing to build. This can be caused by an improper kernel/profile configuration. Verify the chosen kernel and the selected profile match each other. For example, if a hardened profile is set, a hardened kernel should be used. If a default AMD64 profile is set, then the default gentoo-sources should be used. Run the eselect command to view the list of profile options:

user $eselect profile list
Available profile symlink targets:                                                                                                                                                                                                           
  [1]   default/linux/amd64/13.0 (stable)
  [2]   default/linux/amd64/13.0/selinux (dev)
  [3]   default/linux/amd64/13.0/desktop (stable)
  [4]   default/linux/amd64/13.0/desktop/gnome (stable)
  [5]   default/linux/amd64/13.0/desktop/gnome/systemd (stable)
  [6]   default/linux/amd64/13.0/desktop/plasma (stable)
  [7]   default/linux/amd64/13.0/desktop/plasma/systemd (stable)
  [8]   default/linux/amd64/13.0/developer (stable)
  [9]   default/linux/amd64/13.0/no-multilib (stable)
  [10]  default/linux/amd64/13.0/systemd (stable)
  [11]  default/linux/amd64/13.0/x32 (dev)
  [12]  default/linux/amd64/17.0 (stable) *
  [13]  default/linux/amd64/17.0/selinux (dev)
  [14]  default/linux/amd64/17.0/hardened (dev)
  [15]  default/linux/amd64/17.0/hardened/selinux (dev)
  [16]  default/linux/amd64/17.0/desktop (stable)
  [17]  default/linux/amd64/17.0/desktop/gnome (stable)
  [18]  default/linux/amd64/17.0/desktop/gnome/systemd (stable)
  [19]  default/linux/amd64/17.0/desktop/plasma (stable)
  [20]  default/linux/amd64/17.0/desktop/plasma/systemd (stable)
  [21]  default/linux/amd64/17.0/developer (stable)
  [22]  default/linux/amd64/17.0/no-multilib (stable)
  [23]  default/linux/amd64/17.0/no-multilib/hardened (dev)
  [24]  default/linux/amd64/17.0/no-multilib/hardened/selinux (dev)
  [25]  default/linux/amd64/17.0/systemd (stable)
  [26]  default/linux/amd64/17.0/x32 (dev)
  [27]  default/linux/amd64/17.1 (exp)
  [28]  default/linux/amd64/17.1/selinux (exp)
  [29]  default/linux/amd64/17.1/hardened (exp)
  [30]  default/linux/amd64/17.1/desktop (exp)
  [31]  default/linux/amd64/17.1/desktop/gnome (exp)
  [32]  default/linux/amd64/17.1/desktop/gnome/systemd (exp)
  [33]  default/linux/amd64/17.1/desktop/plasma (exp)
  [34]  default/linux/amd64/17.1/desktop/plasma/systemd (exp)
  [35]  default/linux/amd64/17.1/developer (exp)
  [36]  default/linux/amd64/17.1/no-multilib (exp)
  [37]  default/linux/amd64/17.1/no-multilib/hardened (exp)
  [38]  default/linux/amd64/17.1/no-multilib/hardened/selinux (exp)
  [39]  default/linux/amd64/17.1/systemd (exp)
  [40]  hardened/linux/amd64 (stable)
  [41]  hardened/linux/amd64/selinux (stable)
  [42]  hardened/linux/amd64/no-multilib (stable)
  [43]  hardened/linux/amd64/no-multilib/selinux (stable)
  [44]  hardened/linux/amd64/x32 (dev)
  [45]  default/linux/musl/amd64 (exp)
  [46]  hardened/linux/musl/amd64 (exp)
  [47]  default/linux/musl/amd64/x32 (exp)
  [48]  hardened/linux/musl/amd64/x32 (exp)
  [49]  default/linux/uclibc/amd64 (exp)
  [50]  hardened/linux/uclibc/amd64 (exp)

Then use the eselect command again to display which kernel is selected:

user $eselect kernel list
[1]   linux-3.13.10-hardened
[2]   linux-3.16.3-hardened-r1
[3]   linux-3.17.2-hardened-r1
[4]   linux-3.18.4-hardened
[5]   linux-3.18.5-gentoo *

Looking at the output of these two commands, a user can determine if the system is setup properly (the profile matches the kernel) and should have no issues installing app-emulation/virtualbox-modules. Remember: Make sure the system profile and the selected kernel match!

virtualbox-modules permission denied errors

The following "Permission denied" errors can be caused by a strict file mode creation mask (e.g. umask 077):

cc1: error: ./arch/x86/include/generated/uapi: Permission denied
cc1: error: ./arch/x86/include/generated/uapi: Permission denied
cc1: error: ./include/generated/uapi: Permission denied
cc1: error: ./include/generated/uapi: Permission denied
cc1: error: ./arch/x86/include/generated/uapi: Permission denied
cc1: error: ./include/generated/uapi: Permission denied
cc1: error: ./arch/x86/include/generated/uapi: Permission denied
cc1: error: ./include/generated/uapi: Permission denied

The easiest solution would be to backup .config, run make distclean and use the default umask 022.

Host key failing to operate in the virtual machine

If the host key (typically the right Ctrl key) is failing to operate within the virtual (guest) machine, be sure any desktop environment or window manager hooks to host key have been disabled from the host machine's desktop environment or window manager.

For example, the GNOME 3 desktop environment includes a "Show location of the [mouse] pointer" option in the Keyboard and Mouse section of the Tweak Tool (gnome-extra/gnome-tweak-tool). This option will enable a ripple effect to be displayed around the mouse when either the right or left Ctrl key is pressed. This mouse locator handle conflicts with the virtual machine's handle on the right Ctrl key. Disabling this setting (via switching the rocker switch to Off in the Tweak Tool interface) should fix the problem by re-assigning the right Ctrl key as the handle for the host key within the virtual machine.

No audio after upgrade

If there is no sound after upgrading VirtualBox, increasing the VirtualBox ALSA buffer size may fix the issue[2].

user $VBoxManage setextradata global VBoxInternal2/Audio/ALSAAudio/BufferSizeMs "100"

性能の問題

Microsoft Windows ゲスト

  • According to the documentation, the I/O APIC feature (VM -> Settings -> System -> Motherboard -> Enable I/O APIC), which is enabled by default, 'slightly increases the overhead of virtualization and therefore slows down the guest OS a little'. However, there have been reports that the performance impact may actually be quite severe on some host/guest system combinations (e.g. forum post). Be aware that disabling this feature might require additional steps on the guest system as described by this forum post.
  • Using a SATA controller, it is necessary to choose the right driver version from Intel's SATA drivers. Using a wrong version will cause performance problems along with blue screen errors! Refer to this post for a list of working SATA drivers.
  • Slow performance using SATA driver? Only use the SATA controller interface for the hard disk. Remove any CDROMs from the SATA controller and place them onto a IDE Controller.
    メモ
    This can also be a problem of using the wrong SATA-driver version.
  • When installing the VirtualBox Guest Additions into your Windows operating system, do not select to enable Direct3D (experimental) option as this will cause resizing problems and other anomalies. Also, you need to install the Guest Additions from Safe Mode.
  • Do not use the ICH9 chipset with Windows. It is still considered experimental. Using it can cause temporary freezes of the whole VM when used with Windows 7. See this post for more informations.
  • Slow read/write speed to the virtual disk? If the host system has sufficient RAM, try checking (enabling) the Use Host I/O Cache check box in the virtual machine's Storage frame. This will cache much of the guest machine's page file into the host's memory effectively limiting the amount of I/O guest machine will use the virtual disk image file. This is particularly helpful when running Windows guests because of the amount of paging Windows based operating systems regularly perform.

Linux ゲスト

  • When running Gentoo as a guest system make sure you start the virtualbox-guest-additions init script during bootup.
  • Having the guest VDI images on a btrfs filesystem might slow down Linux guests up to the point where the guest kernel remounts its filesystems readonly and no longer performs any I/O. This can be fixed by disabling btrfs' copy on write for the VDI image files on the host.

Kernel driver not installed

VirtualBox-Error: Kernel driver not installed

This may occur after building a new kernel and causes an error message:

user $VirtualBox
WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (4.9.0-gentoo) or it failed to load. Please recompile the kernel module and install it by
 
for m in vbox{drv,netadp,netflt}; do modprobe $m; done
 
You will not be able to start VMs until this problem is fixed.

Solution: Rebuild the VirtualBox kernel modules via:

root #emerge --ask --oneshot @module-rebuild

The system may need rebooted for changes to take effect.

Nonexistent host networking interface, named 'vboxnet0'

root #VBoxManage hostonlyif create

Newly created interface will now be shown as available, but not activated (down):

user $ifconfig -a

An IP will need to be assigned to it:

root #VBoxManage hostonlyif ipconfig vboxnet0 --ip 192.168.56.101

Virtualbox を実行中にホストをサスペンドするとカーネルパニックする

If you experience such behavior, try removing the vbox family of modules before suspending. If this solves the kernel panic, you can add the vbox modules to the list of permanently removed modules before suspend, these modules are loaded automatically after suspend:

root #echo 'SUSPEND_MODULES="vboxpci vboxnetflt vboxnetadp vboxdrv"' >> /etc/pm/config.d/gentoo

関連項目

  • PhpVirtualBox — a web-based administration utility for VirtualBox.
  • QEMU — a generic, open source hardware emulator and virtualization suite.
  • Virtualization — the concept and technique that permits running software in an environment separate from a computer operating system.
  • VMware

外部資料

  1. https://www.virtualbox.org/wiki/Guest_resizing
  2. Section_8. VirtualBox - No sound after update, Gentoo Forums, November 12th, 2019. Retrieved on September 14th, 2020.