Ubuntu 21.04
Sponsored Link

Vagrant : インストール2021/05/21

 
VirtualBox 等の仮想化ソフトウェアのラッパーツール Vagrant をインストールします。
主要な仮想化ソフトウェアには概ね対応していますが、当例では Vagrant デフォルトの VirtualBox インストール済みを前提とします。
[1] Vagrant をインストールしておきます。
root@dlp:~#
apt -y install vagrant
[2] Vagrant の基本操作です。
# 仮想マシンイメージをダウンロードして追加

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

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

root@dlp:~#
vagrant box add ubuntu/hirsute64

==> box: Loading metadata for box 'ubuntu/hirsute64'
    box: URL: https://vagrantcloud.com/ubuntu/hirsute64
==> box: Adding box 'ubuntu/hirsute64' (v20210514.0.0) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/ubuntu/boxes/hirsute64/versions/20210514.0.0/providers/virtualbox.box
Download redirected to host: cloud-images.ubuntu.com
==> box: Successfully added box 'ubuntu/hirsute64' (v20210514.0.0) for 'virtualbox'!

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

root@dlp:~#
vagrant init ubuntu/hirsute64

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.

# 仮想マシン起動

root@dlp:~#
vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/hirsute64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/hirsute64' version '20210514.0.0' is up to date...
==> default: Setting the name of the VM: root_default_1621567216486_2955
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:

  https://www.virtualbox.org/manual/ch04.html#sharedfolders

This option can be disabled globally with an environment variable:

  VAGRANT_DISABLE_VBOXSYMLINKCREATE=1

or on a per folder basis within the Vagrantfile:

  config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection reset. Retrying...
    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...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 6.0.0 r127566
    default: VirtualBox Version: 6.1
==> default: Mounting shared folders...
    default: /vagrant => /root

# 仮想マシンの状態

root@dlp:~#
vagrant status

Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

# 仮想マシンへ SSH で接続

root@dlp:~#
vagrant ssh

Welcome to Ubuntu 21.04 (GNU/Linux 5.11.0-17-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Fri May 21 03:22:14 UTC 2021

  System load:  0.28              Processes:               108
  Usage of /:   3.3% of 38.71GB   Users logged in:         0
  Memory usage: 18%               IPv4 address for enp0s3: 10.0.2.15
  Swap usage:   0%

vagrant@ubuntu-hirsute:~$ exit 

# 仮想マシン停止

root@dlp:~#
vagrant halt

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

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