Categories
DevOps

How to prevent updating VirtualBox Guest Additions on the guest system

Prevent updating VirtualBox Guest Additions on the guest system when using Vagrant.

Create sample Vagrantfile.

$ cat Vagrantfile 
Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  config.vm.network "private_network", ip: "1.2.3.4"

  config.vm.provider :virtualbox

  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.cpus = 2
  end
end

VirtualBox Guest Additions will be updated every time the guest system is started as it is not running.

$ vagrant up                                                                                                                      
Bringing machine 'default' up with 'virtualbox' provider...                                                                       
==> default: Importing base box 'debian/bullseye64'...                                                                            
==> default: Matching MAC address for NAT networking...                                                                           
==> default: Checking if box 'debian/bullseye64' version '11.20210829.1' is up to date...                                         
==> default: Setting the name of the VM: vbguest_default_1632264024508_99808               
==> default: Fixed port collision for 22 => 2222. Now on port 2202.                                                               
==> default: Clearing any previously set network interfaces...                                                                    
==> default: Preparing network interfaces based on configuration...                                                               
    default: Adapter 1: nat                                                                                                       
    default: Adapter 2: hostonly                                                                                                  
==> default: Forwarding ports...                                                                                                  
    default: 22 (guest) => 2202 (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:2202                                                                                          
    default: SSH username: vagrant                                                                                                
    default: SSH auth method: private key                                                                                         
    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] A Virtualbox Guest Additions installation was found but no tools to rebuild or start them.
[...]
Installing Virtualbox Guest Additions 6.1.26 - guest version is 6.0.0                                                             
[...]
An error occurred during installation of VirtualBox Guest Additions 6.1.26. Some functionality may not work as intended.          
In most cases it is OK that the "Window System drivers" installation failed. 
[...]
Restarting VM to apply changes...                                                                                                 
==> default: Attempting graceful shutdown of VM...                                                                                
==> default: Booting VM...                                                                                                        
==> default: Waiting for machine to boot. This may take a few minutes...                                                          
==> default: Machine booted and ready!                                                                                            
==> default: Checking for guest additions in VM...                                                                                
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/milosz/Projects/vagrant/debian/vbguest

==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default: 
==> default: Vanilla Debian box. See https://app.vagrantup.com/debian for help and bug reports

Next time…

$ vagrant up  
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'debian/bullseye64' version '11.20210829.1' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2202.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2202 (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:2202
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
[default] GuestAdditions seems to be installed (6.1.26) correctly, but not running.
[...]

The solution is to install vagrant-vbguest plugin.

$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
Fetching vagrant-libvirt-0.5.3.gem
Successfully uninstalled vagrant-libvirt-0.5.3
Installed the plugin 'vagrant-vbguest (0.30.0)'!
$ vagrant plugin list
vagrant-libvirt (0.3.0, system)
vagrant-scp (0.1.0, global)
vagrant-vbguest (0.30.0, global)

Update Vagranfile to disable the update process.

$ cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  config.vm.network "private_network", ip: "1.2.3.4"

  config.vbguest.auto_update = false if Vagrant.has_plugin?("vagrant-vbguest")

  config.vm.provider :virtualbox

  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.cpus = 2
  end
end

Check it out.

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'debian/bullseye64' version '11.20210829.1' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2202.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2202 (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:2202
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/milosz/Projects/vagrant/debian/vbguest
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

==> default: Machine 'default' has a post `vagrant up` message. This is a message
==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
==> default: 
==> default: Vanilla Debian box. See https://app.vagrantup.com/debian for help and bug reports

As simple as that.