containerlab icon indicating copy to clipboard operation
containerlab copied to clipboard

Add generic-vm persistence

Open evilhamsterman opened this issue 10 months ago • 3 comments

Sometime you may need a VM for something that you want to persist even if the lab is (re)deployed. It looks like a qcow2 snapshot is created and used to start the vm, but it is not saved to a location that is persistent. There is a /config folder that is even mounted to store persistence data, like a startup config for an NOS, but the original and snapshot disk are just saved to the / so when the container is deleted so is the data. Then when you deploy again your vm is wiped.

evilhamsterman avatar Jun 05 '25 04:06 evilhamsterman

Yes, that is how it is today, indeed. Maybe having the disk image moved to the /clab-image directory with the bind mount with the src clab-<labName>/<nodeName>/image is a sound idea

hellt avatar Jun 06 '25 11:06 hellt

That would actually be quite helpful, then instead of everyone having to build large containers with the image built in, you could provide smaller containers and just mount in the image. My example is I'm trying to setup a bunch of VMs with an application installed to test it's integration in a lab environment. It has to be a VM due to some low level hardware stuff it has to manage that is just problematic in a container.

evilhamsterman avatar Jun 09 '25 17:06 evilhamsterman

A way to specify the source image would be nice too, some global variable or something, then you could snapshot the image into the node folder. I'm thinking a lab layout could be like

bgp-test.clab.yaml
fedora.qcow2
ubuntu.qcow2
test.clab
├── node1
│   └── image
├── node2
│   └── image
├── node3
│   └── image
└── rtr1

the topology could be

name: test

topology:
  nodes:
    node1:
      kind: generic_vm
      image: ubuntu.qcow2
    node2:
      kind: generic_vm
      image: ubuntu.qcow2
    node3:
      kind: generic_vm
      image: fedora.qcow2

    rtr1:
      kind: arista_ceos
      image: registry.local/ceos:latest

  links:
    - endpoints: ["node1:eth0", "rtr1:eth0"]
    - endpoints: ["node2:eth0", "rtr1:eth1"]

kind: generic_vm could pull in the generic_vm container, then create a qcow2 snapshot of the listed image for the node. That would save a lot of space and make it much easier to distribute labs with Generic VMs.

evilhamsterman avatar Jun 09 '25 17:06 evilhamsterman