Change OS type after a machine is registered

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
petra
Posts: 4
Joined: 21. Jun 2018, 15:40

Change OS type after a machine is registered

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

Re: Change OS type after a machine is registered

Post 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).
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Change OS type after a machine is registered

Post 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.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply