How to clone a VM via CLI
This tutorial will show you how to make a clone of an existing Virtual Machine.
Prepare the clone
Section titled “Prepare the clone”- 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 loginSuccessfully 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| ID | NAME | STATUS | AVAILABILITY ZONES |
|---|---|---|---|
| 8ce0f20c-8234-4732-a023-6d8034c342fe | my-server | ACTIVE | eu01-1 |
- To get more detailed information of the server you want to clone, use the describe command.
stackit server describe 8ce0f20c-8234-4732-a023-6d8034c342feServer
| FIELD | VALUE |
|---|---|
| ID | 8ce0f20c-8234-4732-a023-6d8034c342fe |
| NAME | my-server |
| STATE | ACTIVE |
| AVAILABILITY ZONE | eu01-1 |
| BOOT VOLUME | b4c68c72-6130-443e-8cb2-d5db753280d6 |
| POWER STATUS | RUNNING |
| MACHINE TYPE | g1.1 |
| LABELS | stackit_project_id: 7af69b99-cf67-4ad8-8026-e332489a6d03 |
| VOLUMES | b4c68c72-6130-443e-8cb2-d5db753280d6 |
Attached Network Interfaces
| ID | NETWORK ID | NETWORK NAME | PUBLIC IP |
|---|---|---|---|
| 78153ab0-766c-4fc2-8cd2-37c207a6f13a | b30d582c-063f-4712-bd85-5d3ef929bb71 | default | xxx |
- 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
stackit volume describe b4c68c72-6130-443e-8cb2-d5db753280d6| FIELD | VALUE |
|---|---|
| ID | b4c68c72-6130-443e-8cb2-d5db753280d6 |
| NAME | |
| STATE | ATTACHED |
| VOLUME SIZE (GB) | 20 |
| PERFORMANCE CLASS | storage_premium_perf1 |
| AVAILABILITY ZONE | eu01-1 |
| SOURCE | 260b040a-fee8-4002-845c-79abac2b801c |
| SERVER | 8ce0f20c-8234-4732-a023-6d8034c342fe |
| LABELS | attached_mode: rw |
Clone the Boot Volume
Section titled “Clone the Boot Volume”- Create a new volume which uses the old volume as its source, this creates a clone.
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
stackit volume describe e431ec98-1b92-4006-9a8c-9e4b4174fe54| FIELD | VALUE |
|---|---|
| ID | e431ec98-1b92-4006-9a8c-9e4b4174fe54 |
| NAME | clone-volume |
| STATE | AVAILABLE |
| VOLUME SIZE (GB) | 20 |
| PERFORMANCE CLASS | storage_premium_perf1 |
| AVAILABILITY ZONE | eu01-1 |
| SOURCE | b4c68c72-6130-443e-8cb2-d5db753280d6 |
Create a new VM using the cloned drive
Section titled “Create a new VM using the cloned drive”stackit server create --machine-type g1.1 --boot-volume-source-type volume --boot-volume-source-id ee546eb0-4d5f-49c4-a8fb-98472e79060e --name cloned-serverstackit server list| ID | NAME | STATUS | AVAILABILITY ZONES |
|---|---|---|---|
| 5ae38747-1feb-4ff1-b480-2210561fed74 | cloned-server | ACTIVE | eu01-1 |
| 8ce0f20c-8234-4732-a023-6d8034c342fe | my-server | ACTIVE | eu01-1 |
(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.
stackit server describe <Server-ID>Server
| FIELD | VALUE |
|---|---|
| ID | [Server-ID] |
| NAME | nic-transfer |
| STATE | ACTIVE |
| AVAILABILITY ZONE | eu01-m |
| BOOT VOLUME | 08c27697-8679-4dce-8895-4300d8f6469c |
| POWER STATUS | RUNNING |
| MACHINE TYPE | g1.1 |
| VOLUMES | 08c27697-8679-4dce-8895-4300d8f6469c |
Attached Network Interfaces
| ID | NETWORK ID | NETWORK NAME | PUBLIC IP |
|---|---|---|---|
| 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 | [Network-ID] | default |
stackit network-interface describe 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 --network-id $NETWORKID| FIELD | VALUE |
|---|---|
| ID | 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 |
| NETWORK ID | [Network-ID] |
| IPV4 | 10.1.0.128 |
| MAC | fa:16:3f:74:7e:c5 |
| NIC SECURITY | true |
| STATUS | ACTIVE |
| TYPE | server |
| SECURITY GROUPS | 78286e55-33d2-43fa-b56d-fd5607ac7277 |
Now you can remove the network-interface from the server.
stackit curl -X DELETE https://iaas.api.eu01.stackit.cloud/v1/projects/$PROJECTID/servers/$SERVERID/nics/314e22c3-fa5c-45d2-96a2-c628ec5af6a8To check if the nic was removed successfully you can use the network-interfaces list command and confirm that status column is set to DOWN.
stackit network-interface list --network-id $NETWORKID| ID | NAME | NIC SECURITY | STATUS | TYPE |
|---|---|---|---|---|
| 77ead02b-1f58-4e27-97c4-b0b866b21e30 | false | ACTIVE | gateway | |
| 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 | true | DOWN | server | |
| 05e90efb-16b5-4427-8625-64db4f9c450e | false | DOWN | metadata | |
| 3d203603-fed2-4d71-9b58-e2cc379e7305 | true | ACTIVE | server |
Now you can attach the nic to the 2nd server.
stackit curl -X PUT https://iaas.api.eu01.stackit.cloud/v1/projects/$PROJECTID/servers/$server/nics/$nicAgain you can use the list and describe command to check if the transfer was successful.
stackit server describe <Server-ID>Server
| FIELD | VALUE |
|---|---|
| ID | [Server-ID] |
| NAME | nic-transfer-target |
| STATE | ACTIVE |
| AVAILABILITY ZONE | eu01-1 |
| BOOT VOLUME | ee546eb0-4d5f-49c4-a8fb-98472e79060e |
| POWER STATUS | RUNNING |
| MACHINE TYPE | g1.1 |
| VOLUMES | ee546eb0-4d5f-49c4-a8fb-98472e79060e |
Attached Network Interfaces
| ID | NETWORK ID | NETWORK NAME | PUBLIC IP |
|---|---|---|---|
| 314e22c3-fa5c-45d2-96a2-c628ec5af6a8 | [Network-ID] | default |
(Optional) Transfering Public IPs
Section titled “(Optional) Transfering Public IPs”To transfer the public IP to the another VM, you can start with listing your public IPs.
stackit public-ip listThe next step is to detach the public IP from the old VM.
stackit server public-ip detach <PublicIP-ID> --server-id <Server-ID>Now the public IP can be attached to your new VM.
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.
stackit public-ip list| ID | IP ADDRESS | USED BY |
|---|---|---|
| 28d04b49-b1ed-44ae-b58b-b2b9d2e1219d | xx.xx.xx.xx | [Server2-ID] |