2

Hoping I can get some help here. I am using the virt-clone command to get an image of VyOS (open source linux router). The clone works fine but when I copy the image to another KVM host and install it the NIC card number changes. ports eth0 and eth1 turn into eth2 & eth3 on the new instance. Is there a way to keep this from happening?

on the original server I run:

vyos@vyos:~$ show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             -                                 u/u
eth1             -                                 u/u
lo               127.0.0.1/8                       u/u
                 ::1/128
vyos@vyos:~$

I then shutdown and clone:

virt-clone --original vyos --name vyos_clone --file vyos_clone

I copy the new cloned file to a different kvm host and run:

virt-install -n vyos --description "Vyos Server" --ram 1024 --vcpus 1 --os-type=linux --disk /VMs/vyos_clone,device=disk,bus=virtio,size=15,sparse=true,format=raw --graphics none --network=default,model=virtio --network=network:HUB1,model=virtio --import --noautoconsole --autostart

I start the servie with virsh start vyos

but when I view the interfaces the numbering has changed:

vyos@vyos:~$ show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth2             -                                 u/u
eth3             -                                 u/u
lo               127.0.0.1/8                       u/u
                 ::1/128
vyos@vyos:~$

Is there a way I can force the new VM/Domain to use eth0 and eth1 instead of eth2 & eth3?

I need these to stay the same so that I can write some scripts.

****** Update

I tried running the sysprep and it looks like it does not recognize the vyos's operating system:

> # virt-sysprep -a /VMs/vyos_clone [   0.0] Examining the guest ... virt-sysprep: error: no operating systems were found in the guest
> image
> 
> If reporting bugs, run virt-sysprep with debugging enabled and include
> the complete output:
> 
>   virt-sysprep -v -x [...]

I also tried editing the xml using virsh edit and taking out the mac addresses and restarting the domain but that did not fix the issue.

Thanks for your help C

2 Answers2

2

The reason you're running in to this issue is that you have not cleared the various populated values from that VM image that need to be cleared prior to use after cloning, such as interface MAC addresses in config files -- which explains your NIC naming issue.

Cloning only makes a copy of the disk, and will generate a new VM definition. Definitions are in XML format, and can be found in /etc/libvirt/qemu/$VM_NAME.xml by default. Images may be in a variety of formats (including raw block devices rather than files at all), but when using image files they're stored in /var/lib/libvirt/images/ by default.

You need to first sysprep that image to correct the behavior you're seeing, which will remove populated values for things like persistent net rules and NIC configurations (and a few more things, but these are most important in the context of this question).

This is done for libvirt VMs using the virt-sysprep command against its root disk image, typically either after cloning a single image, or potentially before cloning (in the case of creating a "template" VM image).

WARNING: Only use virt-sysprep on inactive (destroyed or shutdown) VM images. This tool will mount the guest filesystems and make changes, which is dangerous and prone to spectacular failure when performed on a running VM)

In this case, I'll detail the sysprep process you would use after cloning the image rather than making a template or something else. Let me know if you need help using it in a different way. The following will perform the default "typical" actions you would need to do in order to successfully use a root image as if it had never been booted:

Clone your image

[...]

Perform this command against the cloned root image (before or after copying, doesn't matter):

virt-sysprep -a /var/lib/libvirt/images/$ROOT_VM_DISK.qcow2

Then you can use that image on an instance as if it had never been booted before. Your important changes will still be preserved.

The output dumped to stdout will detail what was done, and whether it succeeded. I'm not completely confident that a VyOS image will succeed using defaults. If you have trouble with it and you're stuck, post your results and I can help pick apart what's going on there.

Spooler
  • 7,046
  • 18
  • 29
  • 1
    I don't know if `virt-sysprep` can handle VyOS, as I've never seen it, but this is the right general approach. – Michael Hampton Dec 15 '18 at 05:18
  • Yeah not looking good: virt-sysprep: error: no operating systems were found in the guest image If reporting bugs, run virt-sysprep with debugging enabled and include the complete output: virt-sysprep -v -x [...] – Cade Nelson Dec 18 '18 at 21:37
1

I was able to accomplish what I was looking for by installing Vyos into a VM with no network adapters. I then cloned that VM and used the qcow2 files for my install. When I installed using this qcow2 file I would add 2 new NIC cards. Now every time I spin up a Vyos it is always Eth0 and Eth1 and my scrips run fine.

More of a work around than a fix.