Fedora 37
Sponsored Link

Vagrant : インストール2022/11/22

 
VirtualBox 等の仮想化ソフトウェアのラッパーツール Vagrant をインストールします。
主要な仮想化ソフトウェアには概ね対応していますが、当例では Libvirt インストール済みを前提とします。
[1] Vagrant をインストールしておきます。
[root@dlp ~]#
dnf -y install vagrant
[root@dlp ~]#
systemctl start virtnetworkd
[2] Vagrant の基本操作です。任意の一般ユーザーで利用可能です。
# 仮想マシンイメージをダウンロードして追加
# ダウンロード可能な Box は公式サイト参照
# ⇒ https://app.vagrantup.com/boxes/search

[fedora@dlp ~]$
vagrant box add generic/fedora36 --provider libvirt

==> box: Loading metadata for box 'generic/fedora36'
    box: URL: https://vagrantcloud.com/generic/fedora36
==> box: Adding box 'generic/fedora36' (v4.2.2) for provider: libvirt
    box: Downloading: https://vagrantcloud.com/generic/boxes/fedora36/versions/4.2.2/providers/libvirt.box
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'generic/fedora36' (v4.2.2) for 'libvirt'!

# 初期化 (カレントパスに Vagrantfile が作成される)

[fedora@dlp ~]$
vagrant init generic/fedora36

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

# 仮想マシン起動

[fedora@dlp ~]$
vagrant up

Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'generic/fedora36' version '4.2.2' is up to date...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default:  -- Name:              fedora_default
==> default:  -- Description:       Source: /home/fedora/Vagrantfile
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              2
==> default:  -- Feature:           acpi

.....
.....

    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!

# 仮想マシンの状態

[fedora@dlp ~]$
vagrant status

Current machine states:

default                   running (libvirt)

The Libvirt domain is running. To stop this machine, you can run
`vagrant halt`. To destroy the machine, you can run `vagrant destroy`.

# 仮想マシンへ SSH で接続

[fedora@dlp ~]$
vagrant ssh


[vagrant@fedora36 ~]$ uname -a 
Linux fedora36.localdomain 6.0.5-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 26 15:55:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

[vagrant@fedora36 ~]$ exit 

# 仮想マシン停止

[fedora@dlp ~]$
vagrant halt

==> default: Halting domain...
# 仮想マシンの設定を変更したい場合は設定ファイルを編集

[fedora@dlp ~]$
vi Vagrantfile
# 例として CPU 数とメモリー容量を変更
# 57 行目から以下のようにコメント解除して値を変更

  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
     vb.memory = "4096"
     vb.cpus = 2
  end
関連コンテンツ