Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Snapshot feature keeps reference to iso_path that should not exist when importing snapshot from a remote server #762

Open
fabionitto opened this issue Jan 31, 2023 · 2 comments
Assignees

Comments

@fabionitto
Copy link

When trying to snapshot export vm-0 and then importing the snapshot to another machine, the install.json and cfg.template files keeps the reference to the iso_path used to install the guest OS.

it's desirable that the vm snapshot importing feature removes cd-rom mounting on vm-0.cfg, so that vm import works without the need to copy the iso file to the machine.

At this point, when trying to import minimal snapshot to a freshly installed drakvuf-sandbox machine, the vm-0 is not created because the file referenced in iso_path doesn't exists; Check output below:

root@debian:/home/automation/drakvuf-ansible# cat /var/log/xen/qemu-dm-vm-0.log
qemu-system-i386: -drive if=none,readonly=on,id=ide-5632,file=/home/automation/pt_windows_7_professional_with_sp1_x64_dvd_u_676950.iso,format=raw: Could not open '/home/automation/pt_windows_7_professional_with_sp1_x64_dvd_u_676950.iso': No such file or directory

...

@BonusPlay
Copy link
Collaborator

Interesting, draksetup postinstall does eject all CDs. Did you forget to run it before exporting a snapshot? Maybe it doesn't save the config file after ejecting.

@fabionitto
Copy link
Author

fabionitto commented Feb 2, 2023

no... I exported after executing draksetup postinstall and testing the analysis.
I think that for snapshots the actual vm-0.cfg doesn't matter, because export feature saves 3 files: install.json, disk.img and cfg.template

cfg.template originates vm-0.cfg during snapshot import, and it has {{DISKS}} at disk configuration.
install.json is saved with iso_path config
and method generate_vm_conf always considers iso_path from install.json:

def generate_vm_conf(install_info: InstallInfo, vm_id: int):
    with open(os.path.join(ETC_DIR, "scripts", "cfg.template"), "r") as f:
        template = f.read()

    storage_backend = get_storage_backend(install_info)

    disks = []
    disks.append(storage_backend.get_vm_disk_path(vm_id))

    install_iso_path = os.path.abspath(install_info.iso_path)
    disks.append(f"file:{install_iso_path},{FIRST_CDROM_DRIVE}:cdrom,r")

    if install_info.enable_unattended:
        unattended_iso_path = os.path.join(LIB_DIR, "volumes", "unattended.iso")
        disks.append(f"file:{unattended_iso_path},{SECOND_CDROM_DRIVE}:cdrom,r")

    disks = ", ".join(['"{}"'.format(disk) for disk in disks])

    template = template.replace("{{ VM_ID }}", str(vm_id))
    template = template.replace("{{ DISKS }}", disks)
    template = template.replace("{{ VNC_PORT }}", str(6400 + vm_id))
    template = template.replace("{{ VCPUS }}", str(install_info.vcpus))
    template = template.replace("{{ MEMORY }}", str(install_info.memory))

Should generate_vm_conf be modified to consider when is generating conf from snapshots?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants