Strongly welcome! Suppose there is some abstract server with centos 7 and libvirt + libguestfs (virt-(builder,install,sysprep,customize и иже с ними)) on board. I'm trying to knock out a new virtual machine.

 # virt-builder centos-7.6 \ --format qcow2 \ --size 10G \ --hostname test-1.local \ --timezone Asia/Kolkata \ -o /images/test-1.qcow2 # virt-install --import --name test-1 \ --memory 1024 --vcpus 1 --cpu host \ --disk /images/test-1.qcow2,format=qcow2,bus=virtio \ --network bridge=br121 \ --os-type=linux \ --os-variant=centos7.0 \ --graphics spice \ --noautoconsole 

Everything is great, the pre-installed image is downloaded, builds, the disk expands and a new machine is created. Everything seems to be fine, but there are a few questions that I just can’t solve with libguestfs:

  1. How to set a static IP ( WITHOUT dhcp , just the address from the pool 192.168.0.0/24) address using (any of) the libguestfs utilities?
  2. Is it possible, and if so how to change the disk layout?

UPD Partially answering the first question, I found this method --upload /root/ifcfg-eth0:/etc/sysconfig/network-scripts/ifcfg-eth0 (Where /root/ifcfg-eth0 is an interface that is pre-configured as needed), in principle option working, but maybe somehow "better" you can do it? Maybe there are some built-in methods out of the box?

    1 answer 1

    Editing network

     sudo virsh net-edit default <network> <name>default</name> <uuid>2cf9a1fe-2da2-4e7d-92a7-5785163ab1c4</uuid> <forward mode='nat'/> <bridge name='virbr0' stp='on' delay='0'/> <mac address='52:54:00:d9:f7:22'/> <ip address='192.168.122.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.122.2' end='192.168.122.254'/> </dhcp> </ip> </network> 

    There you can configure the subnet, and the static address is set by entries

      <host mac="52:54:00:6f:78:f3" ip="192.168.122.222"/> 

    You can add a binding command

     virsh net-update default add-last ip-dhcp-host \ '<host mac="52:54:00:6f:78:f3" ip="192.168.122.222"/>' \ --live --config --parent-index 0 

    Specify the MAC address in the received in the virtual.

    Here is more

    Libwirth distributes addresses through dnsmasq. There is no point in editing these configs - they will be overwritten.

     /usr/bin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper 
    • This is all great and I am grateful for the advice, but there is one small problem - I do n’t have dhcp and I don’t need it from the word at all :) This bridge - --network bridge=br121 exists on the hypervisor host and contains a network 192.168.0.0/24 , so I need to assign a static address from this network at the build stage of the machine :) I will add this to the topic so that there is no chance again :) - who know
    • You can already upload the file and this is the normal way if there is no dhchp) - eri