Vagrant linked clones

72 views
Skip to first unread message

Dennis Chang

unread,
Apr 15, 2020, 12:52:21 PM4/15/20
to Vagrant
Hi all,

I'm not sure how linked clones work. So please correct my misunderstanding.

I have a Vagrantfile
```
$setup = <<-SETUP
  echo "Running as $(id)"
  yum update -y
  yum install -y java-1.8.0-openjdk-devel
SETUP

Vagrant.configure("2") do |config|

  config.vm.define "master-01" do |master|
    master.vm.box = "centos/7"
    master.vm.provider "virtualbox" do |v|
      v.cpus = 1
      v.memory = 1024
      v.linked_clone = true
    end
    master.vm.provision "shell", inline: $setup
  end

  config.vm.define "clone-01" do |clone|
    clone.vm.box = "centos/7"
    clone.vm.provider "virtualbox" do |v|
      v.cpus = 2
      v.memory = 2048
      v.linked_clone = true
    end
    master.vm.provision "shell", inline: <<-INLINE
      # download and start application (depends on Java)
    INLINE
  end
```

So ideally, I only run yum update only once (I noticed that the VM snapshot blows up to 1.5 GB) because it takes time. But in my example, when I spinup clone-01, clone-01 doesn't have Java already installed and it fails (to startup).

So my question is, how *should* I define a Vagrantfile for multi-machines where one machine is a linked clone of another where I only need to run yum update -y once?.
Can you tell me what I'm doing wrong here?

Thanks,

Dennis Chang

unread,
Apr 15, 2020, 6:11:48 PM4/15/20
to Vagrant
and I see that a master VM is created that never gets started.
Vagrant uses VirtualBox linked clones to create new VMs.
So if I want to update the master,  I have to update the base box it is based on.

dragon788

unread,
Apr 16, 2020, 8:00:22 AM4/16/20
to Vagrant
If you don't want to maintain a whole Packer pipeline you can also run updates against the base box and then use `vagrant package` to export the updated version and use that new version in your cluster (after doing a `vagrant box add --name my-centos/7 path/to/exported.box`).

Dennis Chang

unread,
Apr 16, 2020, 11:36:30 PM4/16/20
to Vagrant
I did go that route yesterday and re-packaged a base box to a new box.
Today I used packer to create the base box instead. Either way works.
Thanks for the suggestion.
Reply all
Reply to author
Forward
0 new messages