Debian 11 Bullseye
Sponsored Link

Vagrant : インストール
2021/08/27
 
VirtualBox 等の仮想化ソフトウェアのラッパーツール Vagrant をインストールします。
主要な仮想化ソフトウェアには概ね対応していますが、当例では Libvirt インストール済みを前提とします。
[1] Vagrant をインストールしておきます。
root@dlp:~#
apt -y install vagrant-libvirt
# 一般ユーザーで利用する場合は [libvirt] グループに追加

root@dlp:~#
usermod -G libvirt debian
[2] Vagrant の基本操作です。[libvirt] グループに追加した任意の一般ユーザーで利用可能です。
# 仮想マシンイメージをダウンロードして追加

# ダウンロード可能な Box は公式サイト参照

# ⇒ https://app.vagrantup.com/boxes/search

debian@dlp:~$
vagrant box add generic/debian10 --provider libvirt

==> box: Loading metadata for box 'generic/debian10'
    box: URL: https://vagrantcloud.com/generic/debian10
==> box: Adding box 'generic/debian10' (v3.4.0) for provider: libvirt
    box: Downloading: https://vagrantcloud.com/generic/boxes/debian10/versions/3.4.0/providers/libvirt.box
Download redirected to host: vagrantcloud-files-production.s3-accelerate.amazonaws.com
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'generic/debian10' (v3.4.0) for 'libvirt'!

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

debian@dlp:~$
vagrant init generic/debian10

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.

# 仮想マシン起動

debian@dlp:~$
vagrant up

Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'generic/debian10' version '3.4.0' is up to date...
==> default: Uploading base box image as volume into Libvirt storage...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default:  -- Name:              debian_default
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              2
==> default:  -- Feature:           acpi
==> default:  -- Feature:           apic
==> default:  -- Feature:           pae
==> default:  -- Memory:            2048M
==> default:  -- Management MAC:
==> default:  -- Loader:
==> default:  -- Nvram:
==> default:  -- Base box:          generic/debian10
==> default:  -- Storage pool:      default
==> default:  -- Image:             /var/lib/libvirt/images/debian_default.img (128G)
==> default:  -- Volume Cache:      default
==> default:  -- Kernel:
==> default:  -- Initrd:
==> default:  -- Graphics Type:     vnc
==> default:  -- Graphics Port:     -1
==> default:  -- Graphics IP:       127.0.0.1
==> default:  -- Graphics Password: Not defined
==> default:  -- Video Type:        cirrus
==> default:  -- Video VRAM:        256
==> default:  -- Sound Type:
==> default:  -- Keymap:            en-us
==> default:  -- TPM Path:
==> default:  -- INPUT:             type=mouse, bus=ps2
==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    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...

# 仮想マシンの状態

debian@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 で接続

debian@dlp:~$
vagrant ssh


vagrant@debian10:~$ uname -a 
Linux debian10.localdomain 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux

vagrant@debian10:~$ exit 

# 仮想マシン停止

debian@dlp:~$
vagrant halt

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

debian@dlp:~$
vi Vagrantfile
# 例として CPU数とメモリー容量を変更

# 52行目から以下のようにコメント解除して値を変更

  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
関連コンテンツ