What's?
ちょっといろんな事情でWSLを使える環境を用意するのに苦戦していまして。
VirtualBoxならどうだろうと試してみました。個人的にVirtualBoxを直接使う機会は少ないので、Vagrantと組み合わせることにします。
※問題切り分けのメモみたいな記事です
ちなみに、両方ともwingetでインストール可能でした。よいですね。
環境
今回の環境はこちら。
PS > [System.Environment]::OSVersion
Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 10.0.22621.0 Microsoft Windows NT 10.0.22621.0
PS > $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 22621 6060
Hyper-Vは有効にしていません。
PS > Get-WindowsOptionalFeature -Online | Where-Object { $_.FeatureName -EQ "Microsoft-Hyper-V-All" }
FeatureName : Microsoft-Hyper-V-All
State : Disabled
Vagrantをインストールする
まずはVagrantをインストールしましょう。検索すると見つかります。
PS > winget search vagrant
名前 ID バージョン ソース
--------------------------------------------
Vagrant Hashicorp.Vagrant 2.4.9 winget
インストール。
PS > winget install Hashicorp.Vagrant
PowerShellを再起動するとvagrantコマンドが使えるようになっています。
PS > vagrant --version
Vagrant 2.4.9
インストール先はこちらですね。
PS > Get-Command vagrant
CommandType Name Version Source
----------- ---- ------- ------
Application vagrant.exe 0.0.0.0 C:\Program Files\Vagrant\bin\vagrant.exe
では、AlmaLinux 9を例に使ってみましょう。
PS > vagrant init almalinux/9
起動しようとすると、Hyper-Vが有効になっていない状態なので失敗します。
PS > vagrant up
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
The Hyper-V cmdlets for PowerShell are not available! Vagrant
requires these to control Hyper-V. Please enable them in the
"Windows Features" control panel and try again.
使えるプロバイダがなにもない状態です。
VirtualBoxをインストールする
というわけで、VirtualBoxをインストールします。
PS > winget search virtualbox
名前 ID バージョン 一致 ソース
-----------------------------------------------------------------------------------
Oracle VirtualBox Oracle.VirtualBox 7.2.4 Moniker: virtualbox winget
Enigma Virtual Box Enigma.VirtualBox 11.30 winget
Hyper-V-Switch RaynerSec.Hyper-V-Switch 1.0.1.0 Tag: oraclevirtualbox winget
P
こちらのwingetであっさりインストールできます。
PS > winget install Oracle.VirtualBox
再度vagrant up。
PS > vagrant up
--provider指定が要るのかなと思っていましたが、VirtualBoxを認識しました。
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'almalinux/9' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'almalinux/9'
default: URL: https://vagrantcloud.com/api/v2/vagrant/almalinux/9
==> default: Adding box 'almalinux/9' (v9.7.20251119) for provider: virtualbox (amd64)
default: Downloading: https://vagrantcloud.com/almalinux/boxes/9/versions/9.7.20251119/providers/virtualbox/amd64/vagrant.box
SSHで接続。
PS > vagrant ssh
OKですね。
[vagrant@localhost ~]$ cat /etc/redhat-release
AlmaLinux release 9.7 (Moss Jungle Cat)
割とあっさりですが、Vagrant+VirtualBoxの環境を構築できました。