Change OS type after a machine is registered

Discussion about using the VirtualBox API, Tutorials, Samples.

Change OS type after a machine is registered

Postby petra » 21. Jun 2018, 16:04

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   Expand viewCollapse view
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   Expand viewCollapse view
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?
petra
 
Posts: 4
Joined: 21. Jun 2018, 15:40

Re: Change OS type after a machine is registered

Postby petra » 24. Jun 2018, 09:04

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).
petra
 
Posts: 4
Joined: 21. Jun 2018, 15:40

Re: Change OS type after a machine is registered

Postby noteirak » 23. Oct 2018, 21:58

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.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 3 guests