Alternative way to get Linux image for Vagrant

Vagrant box downloads are extremely slow and there are no other trusted sources (links, torrents, magnets) available. But there's an alternative way to download your Linux image from faster source and use it with your Vagrant. Instead of downloading the Vagrant box, download the Oracle Virtualbox "ova" image file then convert it to Vagrant box image.

Steps:

  1. Download the Oracle Virtualbox "ova" Linux image file. In this article, CentOS 8 "ova" Linux image file downloaded from https://www.linuxvmimages.com/images/centos-8 will be used as an example.

  2. Extract the downloaded zip file.

  3. Import the virtual appliance by executing the following command:

          
    vboxmanage import CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com.ova --vsys 0 --eula accept
          
        

    Note: the --vsys 0 --eula accept arguments are to avoid the error "vboxmanage.exe: error: Cannot import until the license agreement listed above is accepted."

    The output of the above command:

          
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Interpreting E:\Users\arpeggio\Downloads\CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com.ova...
    OK.
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Disks:
      vmdisk2       107374182400    -1      http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized       CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com-disk001.vmdk        -1      -1
    
    Virtual system 0:
     0: Suggested OS type: "RedHat_64"
        (change with "--vsys 0 --ostype "; use "list ostypes" to list all possible values)
     1: Suggested VM name "CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com"
        (change with "--vsys 0 --vmname ")
     2: Suggested VM group "/LinuxVMImages"
        (change with "--vsys 0 --group ")
     3: Suggested VM settings file name "C:\Users\webfoobar\VirtualBox VMs/LinuxVMImages\CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com\CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com.vbox"
        (change with "--vsys 0 --settingsfile ")
     4: Suggested VM base folder "C:\Users\webfoobar\VirtualBox VMs"
        (change with "--vsys 0 --basefolder ")
     5: Product (ignored): CentOS 8 Minimal VirtualBox Image
     6: Vendor (ignored): CentOS Community
     7: Version (ignored): 8.0.1905
     8: ProductUrl (ignored): https://linuxvmimages.com/images/centos-8/
     9: VendorUrl (ignored): https://centos.org
    10: Description "CentOS 8 Minimal VirtualBox Image"
        (change with "--vsys 0 --description ")
    11: End-user license agreement (accepted)
    12: Number of CPUs: 1
        (change with "--vsys 0 --cpus ")
    13: Guest memory: 2048 MB
        (change with "--vsys 0 --memory ")
    14: Sound card (appliance expects "", can change on import)
        (disable with "--vsys 0 --unit 14 --ignore")
    15: USB controller
        (disable with "--vsys 0 --unit 15 --ignore")
    16: Network adapter: orig Bridged, config 3, extra slot=0;type=Bridged
    17: CD-ROM
        (disable with "--vsys 0 --unit 17 --ignore")
    18: IDE controller, type PIIX4
        (disable with "--vsys 0 --unit 18 --ignore")
    19: IDE controller, type PIIX4
        (disable with "--vsys 0 --unit 19 --ignore")
    20: SATA controller, type AHCI
        (disable with "--vsys 0 --unit 20 --ignore")
    21: Hard disk image: source image=CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com-disk001.vmdk, target path=CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com-disk001.vmdk, controller=20;channel=0
        (change target path with "--vsys 0 --unit 21 --disk path";
        disable with "--vsys 0 --unit 21 --ignore")
    Successfully imported the appliance.
          
        
  4. Show the list of VMs to get the VM ID that you want to convert by executing the following command:

          
    vboxmanage list vms
          
        

    The output of the above command:

          
    "CentOS_8_Minimal_VirtualBox_Image_LinuxVMImages.com" {47d49743-180f-41e9-948a-145d6761dd82}
          
        

    Note: the 47d49743-180f-41e9-948a-145d6761dd82 is the VM ID.

  5. Convert the "ova" virtual appliance file to Vagrant box image by executing the following command:

          
    vagrant package --base 47d49743-180f-41e9-948a-145d6761dd82 --output centos8.box
          
        

    Note: use the VM ID as value to the --base argument.

    The output of the above command:

          
    ==> 47d49743-180f-41e9-948a-145d6761dd82: Exporting VM...
    ==> 47d49743-180f-41e9-948a-145d6761dd82: Compressing package to: C:/Users/webfoobar/vmboxes/centos8/centos8.box
          
        
  6. If the VirtualBox Guest Additions are not installed, install it by executing the following command:

          
    vagrant plugin install vagrant-vbguest
          
        

    The output of the above command:

          
    Installing the 'vagrant-vbguest' plugin. This can take a few minutes...
    Installed the plugin 'vagrant-vbguest (0.24.0)'!
          
        
  7. Add the created Vagrant box to the list of local Vagrant boxes by executing the following command:

          
    vagrant box add webfoobar centos8.box
          
        

    The output of the above command:

          
    ==> box: Box file was not detected as metadata. Adding it directly...
    ==> box: Adding box 'webfoobar' (v0) for provider:
        box: Unpacking necessary files from: file://C:/Users/webfoobar/vmboxes/centos8/centos8.box
        box:
    ==> box: Successfully added box 'webfoobar' (v0) for 'virtualbox'!
          
        
  8. Initialize the box by executing the following command:

          
    vagrant init webfoobar
          
        

    The output of the above command:

          
    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.
          
        
  9. Replace the content of the Vagrantfile with the following:

          
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    
    # All Vagrant configuration is done below. The "2" in Vagrant.configure
    # configures the configuration version (we support older styles for
    # backwards compatibility). Please don't change it unless you know what
    # you're doing.
    Vagrant.configure("2") do |config|
      # The most common configuration options are documented and commented below.
      # For a complete reference, please see the online documentation at
      # https://docs.vagrantup.com.
    
      # Every Vagrant development environment requires a box. You can search for
      # boxes at https://vagrantcloud.com/search.
      config.vm.box = "webfoobar"
      config.vm.hostname = "webfoobarvagrant"
      config.ssh.username = "centos"
      config.ssh.password = "centos"
      config.ssh.insert_key = "false"
      config.vm.boot_timeout = 888
      config.vm.network "forwarded_port", guest: 80, host: 2345
      config.vm.network "private_network", ip: "192.168.88.22"
    end
          
        
  10. Run the converted Vagrant box by executing the following command

          
    vagrant up
          
        

    The output of the above command:

          
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Clearing any previously set forwarded ports...
    ==> 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: 80 (guest) => 2345 (host) (adapter 1)
        default: 22 (guest) => 2222 (host) (adapter 1)
    ==> 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: centos
        default: SSH auth method: password
        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.14
        default: VirtualBox Version: 6.1
    ==> default: Setting hostname...
    The following SSH command responded with a non-zero exit status.
    Vagrant assumes that this means the command failed!
    
    # Update sysconfig
    sed -i 's/\(HOSTNAME=\).*/\1webfoobarvagrant/' /etc/sysconfig/network
    # Update DNS
    sed -i 's/\(DHCP_HOSTNAME=\).*/\1"webfoobarvagrant"/' /etc/sysconfig/network-scripts/ifcfg-*
    # Set the hostname - use hostnamectl if available
    echo 'webfoobarvagrant' > /etc/hostname
    grep -w 'webfoobarvagrant' /etc/hosts || {
      sed -i'' '1i 127.0.0.1\twebfoobarvagrant\twebfoobarvagrant' /etc/hosts
    }
    
    
    Stdout from the command:
    
    
    
    Stderr from the command:
    
    
          
        
  11. The box is running. You can SSH it using centos as username as well as password.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.