Skip to content

Copying a Virtual Machine

Simon Støvring edited this page Oct 2, 2023 · 8 revisions

When managing multiple host machines, you may want to copy a virtual machine from one host machine to the other. For example when to replicate your setup when setting up a new host machine or to update all host machines after installing new software on a virtual machine.

Fortunately, the process of coming virtual machines between host machines is quite easy with Tart and SSH by following the steps outlined in this article.

Let us assume that we have the host machines A and B and that we have made changes to the virtual machine on host machine A and want to copy those changes to host machine B.

ℹ️ Note

This article will refer to the machines using "a" and "b" rather than their IP addresses to make commands easier to read. You can refer to the runners like this by setting up aliases in your /etc/hosts file or you can reference the host machines using their IP addresses.

We start by connecting to host machine A using SSH.

ssh runner@a

Then we export the virtual machine from host machine A using the tart command. In this case our virtual machine is named "ci" and we export it to the desktop of host machine A.

tart export ci ~/Desktop/ci.aar

Tart exports the virtual machine as an Apple Archive that generally have the .aar file extension.

While still connected to host machine A, we can now use the scp command to securely copy the archive to host machine B.

⚠️ Important

At Shape we have asked MacStadium to place our machines in a private PVLAN to ensure that our machines can communicate with each other. By default, MacStadium machines are placed in a community VLAN that prevents machines from communicating with each other but MacStadium can move machines to a private VLAN free of charge upon request.

scp ~/Desktop/ci.aar runner@b:~/Desktop/ci.aar

After copying the archive to host machine B, we may want to remove it from host machine A again.

rm ~/Desktop/ci.aar

We will now connect to host machine B using VNC. We use VNC instead of SSH as we will need to interact with the Tartelet app which does not have a command line tool.

The following sections describe two ways of importing the image on host machine B:

  • The simple flow: The flow is straightforward but requires stopping the virtual machines leading to downtime.
  • The advanced flow: The flow is more elaborate but can be performed without stopping the virtual machines meaning there is no downtime.

Simple Flow for Importing the Virtual Machine

The following presents the simplest possible flow for importing the virtual machine that was copied from host machine A to host machine B, however, this flow requires stopping the virtual machines and as such causing some down time.

The first thing you should notice is that there is file named ci.aar on the desktop of host machine B.

Stop the virtual machines as described here. Make sure that no jobs are running before stopping the virtual machines.

Now open the Terminal app and run the following command to delete the virtual machine on host machine B. Remember to replace the name with the name of your virtual machine.

tart delete ci

Then import the virtual machine in ci.aar using the command below. Remember to replace the name of the virtual machine with the name of the virtual machine that Tartelet is configured to use.

tart import ~/Desktop/ci.aar ci

Finally, remove the archive from host machine B.

rm ~/Desktop/ci.aar

Advanced Flow for Importing the Virtual Machine

We can update the virtual machines without any downtime by following the instructions below.

Open the Terminal to import the image. Make sure to choose a name that does not collapse with the name of your existing image, e.g. if your current image is named "ci" then choose "ci-new".

tart import ~/Desktop/ci.aar ci-new

Now remove the old image named. Remember to replace the name with the name of your virtual machine. This is safe to do even if there are virtual machines running as they are operating on a cloned image.

tart delete ci

Then clone the newly imported image to rename it to match the name of the old image.

tart clone ci-new ci

Then remove the imported image.

tart delete ci-new

Finally, remove the archive from host machine B.

rm ~/Desktop/ci.aar