Ubuntu 22.04
Sponsored Link

Vagrant : Install2022/09/01

 
Install Vagrant that is wrapper tool for Virtualization software like Libvirt or VirtualBox and others.
Vagrant supports many Virtualization software like VirtualBox or Libvirt and others,
this example is based on the Libvirt installed environment.
[1] Install Vagrant.
root@dlp:~#
apt -y install vagrant-libvirt
[2] Basic usage of Vagrant. It's possible to use it by any common user.
# download and add virtual machine images
# for downloadable image, refer to the official site below
# ⇒ https://app.vagrantup.com/boxes/search

ubuntu@dlp:~$
vagrant box add generic/ubuntu2004 --provider libvirt

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

# initialize ([Vagrantfile] is created on the current path)

ubuntu@dlp:~$
vagrant init generic/ubuntu2004

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.

# start virtual machine

ubuntu@dlp:~$
vagrant up

Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'generic/ubuntu2004' version '4.1.10' 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:              ubuntu_default
==> default:  -- Description:       Source: /home/ubuntu/Vagrantfile
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              2
==> default:  -- Feature:           acpi
==> default:  -- Feature:           apic
==> default:  -- Feature:           pae
==> default:  -- Clock offset:      utc
==> default:  -- Memory:            2048M
==> default:  -- Management MAC:
==> default:  -- Loader:
==> default:  -- Nvram:
==> default:  -- Base box:          generic/ubuntu2004
==> default:  -- Storage pool:      default
==> default:  -- Image():     /var/lib/libvirt/images/ubuntu_default.img, 128G
==> default:  -- Disk driver opts:  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:  -- Video 3D accel:    false
==> default:  -- Sound Type:
==> default:  -- Keymap:            en-us
==> default:  -- TPM Backend:       passthrough
==> 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 machine to boot. This may take a few minutes...
    default: SSH address: 192.168.121.97:22
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection refused. 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!

# show state of virtual machine

ubuntu@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`.

# connect to virtual machine with SSH

ubuntu@dlp:~$
vagrant ssh


vagrant@ubuntu2004:~$ uname -a 
Linux ubuntu2004.localdomain 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

vagrant@ubuntu2004:~$ exit 

# stop virtual machine

ubuntu@dlp:~$
vagrant halt

==> default: Attempting graceful shutdown of VM...
# if you'd like to change settings of virtual machine, edit Vagrantfile

ubuntu@dlp:~$
vi Vagrantfile
# for example to change CPU and Memory settings
# uncomment line 52 like follows and add or change values

  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
Matched Content