The only network between QEMU and Green

Hi, here is my problem:

I have 5 networks:

RED = 192.168.111.x/24
GREEN = 10.168.x.x/16
BLU = 10.10.x.x/16
ORANGE = 172.16.3.x/24
OpenVpn = 10.175.91.0/24
https://fireinfo.ipfire.org/profile/732fef80c785b15598d2a3c2afb59b5bfa5c7885

I installed the QEMU addon with Windows 7 emulated.
Windows 7 IP address under emulator (assigned by QEMU) is 10.0.2.15
I would like QEMU to assign Windows 7 an IP belonging to my GREEN network (example 10.168.1.111). In other words, I would like QEMU’s network and GREEN to be the same network.
I did many tests and even IpFire got damaged. I had to reinstall the whole system. Luckily I had exported the Configuration Backup.
Some advice?
Thank you in advance.

You have to switch the green zone from native to bride in zone config wiki.ipfire.org - Zone Configuration

and switch the network mode of qemu from user to tap mode and add the virtual device to the bridge after the machine was started. After this you should get a dhcp from green.
I use the libvirt addon and virtmanager on a client to manage vm’s becasue this is much easier then use the qemu commandline options.

2 Likes

If you do not want to use virtmanager, this is how I do it from the command line (not in IPFire but on a headless dedicated machine). Adapt to your needs vm name, disk size, cpu number, memory, guest OS. In extra args I enable the console, therefore I can access the guest from the host with virsh console vm_name.

Be careful, do not copy and paste, as there could be invisible characters created by my editor. Never copy/paste, always type the commands yourself, after you have understood what they do. No guarantee that these commands or links still work. You have the responsibility of your machine, not me. Use it only as the starting point for further research.

INSTALL VM

In bash ctrl-x/ctrl-e will allow you to open the editor and paste the whole text, as you close, it will be executed in the shell.

virt-install \
--connect qemu:///system \
--name vm_name \
--memory=3072 --vcpus=2 \
--disk path=/media/virtualM/vm_name.img,size=280 \
--location=https://debian.ethz.ch/debian/dists/stable/main/installer-amd64/ \
--network=bridge:br0 \
--nographics \
--os-type=linux \
--os-variant debianwheezy \
--accelerate \
--extra-args="console=tty0 console=ttyS0,115200n8" \
--debug

VIRSH CHEATSHEET

https://computingforgeeks.com/virsh-commands-cheatsheet/

  • list the active virtual machines: virsh list
  • list all the virtual machines: virsh list --all
  • Info concerning the virtual machine named VM_name: virsh dominfo vm_name
  • find image file: virsh domblklist
  • Set a virtual machine named vm_name to start automatically on reboot: virsh autostart vm_name
  • Start a virtual machine named vm_name: virsh start vm_name
  • Shut down a virtual machine named vm_name: virsh shutdown vm_name
  • Force shutdown of a virtual machine named vm_name: virsh destroy vm_name
  • Reboot a virtual machine named vm_name: virsh reboot vm_name
  • Destroy a virtual machine named vm_name: virsh undefine vm_name
  • Recreate a virtual machine named vm_name, xml file and the image in place: virsh define /etc/libvirt/qemu/vm_name.xml
  • Edit the xml file of a virtual machine named vm_name In the xml file, pay attention to the driver type (raw or qcow2): virsh edit vm_name
  • Autostart a virtual machine: virsh autostart vm_name
  • Connect to the console of the virtual machine vm_name: virsh console vm_name
  • To allow the console a decent size edit “.profile” and add stty rows 48 cols 120

INCREASE RAM SIZE

virsh shutdown vm_name
virsh setmaxmem vm_name 8G --config
virsh setmem vm_name 8G --config
virsh start vm_name

BACKUP LIVE IMAGE

Live means that you create a temporary image that is in use while you backup the base machine. After backup, you merge back the temporary image and then delete it. If you shut down the virtual machine during the backup, all this is unnecessary.

https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit

Briefly:

  • Create snapshot:
    virsh snapshot-create-as --domain vm_name vm_name_snap --no-metadata --diskspec vda,file=/var/lib/libvirt/images/overlay_vm_name.qcow2 --disk-only --atomic

If --no-metadata is not used, delete the snapshot xml file with:
virsh snapshot-delete --domain vm_name --metadata vm_name_snap

  • Check snapshot in use:
    virsh domblklist vm_name

  • backup the vm_name.img

  • Merge changes back to base:
    virsh blockcommit vm_name vda --active --verbose --pivot

  • Delete snapshot:
    rm /var/lib/libvirt/images/overlay_vm_name.qcow2

Recovering xml file:

  • first destroy the VM
    virsh undefine VM --remove-all-storage
  • recover from backup both vm_name.xml and vm_name.img
  • edit vm_name.xml to be sure it points to vm_name.img
    virsh define /path/to/your/xml/file.xml
    virsh list --all
    virsh start vm_name

RESIZE PARTITION INSIDE THE VIRTUAL MACHINE

Briefely:
cd /media/your_vm_folder/
virsh shutdown vm_name
virt-filesystems --long --parts --blkdevs -h -a vm_name.img qcow: qemu-img create -f qcow2 -o preallocation=metadata new_vm_name.img 320G img: truncate -s 320G new_vm_name.img
virt-resize --expand /dev/sda1 vm_name.img new_vm_name.img
ls -ls
mv vm_name.img bkp_vm_name.img
mv new_vm_name.img vm_name.img
virsh start vm_name
virsh list
virsh console vm_name
ls -la
rm bkp_vm_name.img

If MBR partition, resize is up to 2 TB. Otherwise it has to be converted to GPT first, then extended.

These are the steps:

truncate -s 1700G new_vm_name.img
virt-resize --no-extra-partition vm_name.img new_vm_name.img
virsh edit vm_name
change the image file to point to new_vm_name.img
virsh start vm_name
virsh console vm_name
once inside convert to GPT partition from MBR:

  • fdisk -l see what is the device (/dev/vda)
  • gdisk /dev/vda
  • create a new partition in the first MB of the disk (sectors 34-2047), hit n
  • assign BIOS Boot code (ef02)
  • save with w
  • partprobe /dev/vda
  • grub-install /dev/vda
  • reboot

now extend partition to occupy the whole space.

fdisk /dev/vda
delete part 1
recreate part 1 form 2048 to end
assign type Linux filesystem
chek
write
df -hT
resize2fs /dev/vda1
df -hT

See:

FURTHER INFORMATION

https://jamielinux.com/docs/libvirt-networking-handbook/bridged-network.html
http://wiki.libvirt.org/page/Networking#Altering_the_interface_config
https://help.ubuntu.com/community/KVM/Virsh

https://www.centos.org/docs/5/html/5.2/Virtualization/index.html
https://www.redhat.com/archives/libvirt-users/2015-September/msg00037.html
https://www.cyberciti.biz/faq/howto-linux-delete-a-running-vm-guest-on-kvm/

https://www.cyberciti.biz/faq/how-to-clone-existing-kvm-virtual-machine-images-on-linux/

4 Likes

Works!!!
I have chosen to adopt this procedure. With hard work and a long time I succeeded!!!
But now I would like to start the machine directly from the IpFire shell, with a command like:

qemu -vnc :1 -smp 1 -hda /mnt/harddisk/macchine_qemu/windows7.img -m 1024 -usbdevice tablet -k it

It can be done? How can I formulate the syntax?
Thank you all for your precious help!!!