Page 1 of 1

Change OS type after a machine is registered

Posted: 21. Jun 2018, 16:04
by petra
Hello,
I'm using the python API implementation to create a VM and later manipulate it.
After the machine is created using the followinw:

Code: Select all

vbox = virtualbox.VirtualBox()
machine = vbox.create_machine('', 'some_name', [], 'Windows7', '')
session = virtualbox.Session()
vbox.register_machine(machine)
machine.lock_machine(session, LockType.write)
session.machine.add_storage_controller('something', StorageBus.sata)
session.machine.save_settings()
session.unlock_machine()
machine.launch_vm_process(session, 'gui', '')
Then I run it, turn it off and then would like to change its OS type to Windows81_64.
I run the following:

Code: Select all

machine.lock_machine(session, LockType.write)
session.machine.os_type_id='Windows81_64'
session.machine.save_settings()
session.unlock_machine()
machine.laumch_vm_process(session, 'gui', '')
After the code run I can see on VirtualBox GUI that the VM now has OS type of "Windows81_64", but it is only in the GUI. The machine itself loads with Windows 7 32 bits (and crushes, since I use a VDI file with Windows 8.1 64 bits). I can fix it only by changing the OS type from the GUI, and then start the machine again (from GUI or using API).

What am I doing wrong?

Re: Change OS type after a machine is registered

Posted: 24. Jun 2018, 09:04
by petra
Update:
I also tried to clone the machine (using Link option), but the newly created machine also requires changing the OS type from VirtualBox GUI in order to load with the new OS (Windows 8.1 64-bit instead of Windows 7 32-bit).

Re: Change OS type after a machine is registered

Posted: 23. Oct 2018, 21:58
by noteirak
The problem is that you use the old machine object to start the VM. After saving the machine object, get it again and then use that new one (with the right OS settings) to start it.