0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vagrant で rockylinux/9 を使おうとすると 404 でエラーになってしまう問題の回避策

Last updated at Posted at 2024-12-07

Vagrant で rockylinux/9 を使おうとすると、URL が 404 と言われてしまいます。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'rockylinux/9' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'rockylinux/9'
    default: URL: https://vagrantcloud.com/api/v2/vagrant/rockylinux/9
==> default: Adding box 'rockylinux/9' (v4.0.0) for provider: virtualbox (amd64)
    default: Downloading: https://vagrantcloud.com/rockylinux/boxes/9/versions/4.0.0/providers/virtualbox/amd64/vagrant.box
Download redirected to host: dl.rockylinux.org
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.

The requested URL returned error: 404

これは、RockyLinux 9.5 が出たにもかかわらず、Vagrant Box のカタログが更新されていないのが原因です。
rockylinux/9 - HashiCorp Cloud Platform

回避策1: community/rockylinux-9 を使う

community/rockylinux-9 という有志が作ったカタログがあります。
これは、公式と同じ https://dl.rockylinux.org/ にホストされている Box を使っているので、安心して使えます。
また、Box の URL が Rocky-9-Vagrant-VMware.latest.x86_64.box とバージョンではなく latest になっているので、常に 9.x 系の最新版が使えます。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "community/rockylinux-9"
end

回避策2: URL を直接指定する

community/rockylinux-9 だと常に最新バージョンになっているのですが、言い換えるとダウンロードした時期によって異なるバージョンになってしまいます。
そうではなく、バージョンを固定しておきたいという場合は、公式リポジトリ にある Box の URL とハッシュ値を直接指定してしまうという方法があります。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "rockylinux/9"

  config.vm.box_url = "https://dl.rockylinux.org/pub/rocky/9.5/images/x86_64/Rocky-9-Vagrant-Vbox-9.5-20241118.0.x86_64.box"
  config.vm.box_download_checksum = "5323e2b3007975c60c9a6bab27548e567ec3df41a7cde7ce2bfd7acf15f3b067"
  config.vm.box_download_checksum_type = "sha256"
end

回避策3: 代わりの metadata.json を使う

新しいURLに更新した metadata.json を用意しました。
https://gist.github.com/YujiSoftware/9d52d95c85373f1631f0cac8a40b0944/raw/4cba8574e2921534eae17898e4c122f410bbc997/metadata.json

これをダウンロードして vagrant box add コマンドで取り込んで使います。

$ curl -O https://gist.github.com/YujiSoftware/9d52d95c85373f1631f0cac8a40b0944/raw/4cba8574e2921534eae17898e4c122f410bbc997/metadata.json
$ vagrant box add metadata.json
==> box: Loading metadata for box 'metadata.json'
    box: URL: file:///home/yuji/vm/rocky/metadata.json
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) libvirt
2) virtualbox
3) vmware_desktop

Enter your choice: 2
==> box: Adding box 'rockylinux/9' (v4.0.1) for provider: virtualbox (amd64)
    box: Downloading: https://dl.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-Vagrant-Vbox-9.5-20241118.0.x86_64.box
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'rockylinux/9' (v4.0.1) for 'virtualbox (amd64)'!

あとは、普通に vagrant up すれば起動できます。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "rockylinux/9"
end
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
中略...

$ vagrant ssh

[vagrant@vbox ~]$ cat /etc/redhat-release 
Rocky Linux release 9.5 (Blue Onyx)

今後、もし公式の Vagrant Box カタログが更新されたときは、 vagrant box remove rockylinux/9 で削除してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?