Skip to content

How to clone a VM via CLI

This tutorial will show you how to make a clone of an existing Virtual Machine.

  • Switch over to where you have installed the STACKIT CLI
  • First use the cli to Authenticate to the API and set the project ID
$ stackit auth login
Successfully logged into STACKIT CLI.
$ stackit config set --project-id xxx
$ PROJECTID=xxx
  • List your servers. In the list you should be able to find the server you want to clone.
stackit server list
  • To get more detailed information of the server you want to clone, use the describe command.
Terminal window
stackit server describe 8ce0f20c-8234-4732-a023-6d8034c342fe

Server

Attached Network Interfaces

  • now you need to get detailed information of the drive you want to clone and create a duplicate (e.g. minimum is the same amount of storage etc.)
    stackit volume describe
Terminal window
stackit volume describe b4c68c72-6130-443e-8cb2-d5db753280d6
  • Create a new volume which uses the old volume as its source, this creates a clone.
Terminal window
stackit volume create --availability-zone eu01-1 --source-type volume --source-id b4c68c72-6130-443e-8cb2-d5db753280d6 --name clone-volume
  • After the creation is complete you can check it with the describe command
    stackit volume describe
Terminal window
stackit volume describe e431ec98-1b92-4006-9a8c-9e4b4174fe54
stackit server create --machine-type g1.1 --boot-volume-source-type volume --boot-volume-source-id ee546eb0-4d5f-49c4-a8fb-98472e79060e --name cloned-server
stackit server list

(Optional) Transferring fixed IP addresses

Section titled “(Optional) Transferring fixed IP addresses”

To begin the IP transfer, you can start with listing your VMs and Network Interfaces. Note down the network-interface ID.

Terminal window
stackit server describe <Server-ID>

Server

Attached Network Interfaces

Terminal window
stackit network-interface describe 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 --network-id $NETWORKID

Now you can remove the network-interface from the server.

Terminal window
stackit curl -X DELETE https://iaas.api.eu01.stackit.cloud/v1/projects/$PROJECTID/servers/$SERVERID/nics/314e22c3-fa5c-45d2-96a2-c628ec5af6a8

To check if the nic was removed successfully you can use the network-interfaces list command and confirm that status column is set to DOWN.

Terminal window
stackit network-interface list --network-id $NETWORKID

Now you can attach the nic to the 2nd server.

Terminal window
stackit curl -X PUT https://iaas.api.eu01.stackit.cloud/v1/projects/$PROJECTID/servers/$server/nics/$nic

Again you can use the list and describe command to check if the transfer was successful.

Terminal window
stackit server describe <Server-ID>

Server

Attached Network Interfaces

To transfer the public IP to the another VM, you can start with listing your public IPs.

Terminal window
stackit public-ip list

The next step is to detach the public IP from the old VM.

Terminal window
stackit server public-ip detach <PublicIP-ID> --server-id <Server-ID>

Now the public IP can be attached to your new VM.

Terminal window
stackit server public-ip attach <PublicIP-ID> --server-id <Server2-ID>

If you want to see that everything went well you can again list your public IPs see that the IP moved to the other VM.

Terminal window
stackit public-ip list