How to check booting status of VM using pyvmomi? - virtual-machine

I have created VM using pyvmomi module and made it to boot from ISO. Once the vm is powered on, the VM will be booting from ISO. How to check the status whether the VM is booted or not?

I check if the VM is running and if the status of the VMTools is 'toolsOk' (meaning they are installed and running).
from pyVmomi import vim
#...
# connect and get your vm
#...
vm_running = False
if (vm.runtime.powerstate == vim.VirtualMachinePowerState.poweredOn) and (vm.guest.toolsStatus == vim.vm.GuestInfo.ToolsStatus.toolsOk):
vm_running = True
#...
Further reading:
vmware documentation: vim.vm.GuestInfo
vmware documentation: vim.vm.GuestInfo.ToolsStatus.html
pyvmomi samples

Related

Python on M1 MBP trying to connect to USB devices - NoBackendError: No backend available

I am trying to connect with Python to my USB devices.
The final result should be a connection to my Blood Pressure Monitor but I am failing already to connect to ANY device.
My simple code - which I found here - is bellow. The Product- and Vendor ID I got from Apple Menu > About this Mac > System Information
import usb.core
import usb.util
# find our device
dev = usb.core.find(idVendor=0x0781, idProduct=0x55a4)
# was it found?
if dev is None:
raise ValueError('Device not found')
# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()
# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]
ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
# write the data
ep.write('test')
But I get always NoBackendError: No backend available from dev = usb.core.find(idVendor=0x0781, idProduct=0x55a4)
For the connection I installed pyusb in my Python env and with Homebrew libusb on my mac.
I have no clue how to get a connection or even a simple list via iteration with all my connected Product- and Vendor IDs.
This error is to be expected if pyusb cannot find the dynamic libraries of libusb.
Installing libusb with Homebrew is not sufficient. Homebrew puts the relevant files in /opt/homebrew/Cellar/libusb/1.0.24/lib and creates symbolic links in /opt/homebrew/lib. But pyusb is not aware of these paths.
You have two main options:
Add /opt/homebrew/lib to the environment variable DYLD_LIBRARY_PATH. For a permanent setup, add it to ~/.zshenv:
export DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
Create a symbolic link in your home directory. This takes advantage of the fact that ~/lib is a default fallback path for libraries:
ln -s /opt/homebrew/lib ~/lib

virtualbox Raw-mode is unavailable courtesy of Hyper-V windows 10

issues:
Failed to open a session for the virtual machine ubuntu.
Raw-mode is unavailable courtesy of Hyper-V. (VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT).
Result Code: E_FAIL (0x80004005)
Component: ConsoleWrap
Interface: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}
UPDATES:
Solution is given below.
You may need to disable the hypervisor.
So, follow the next steps:
1) Open command prompt as Administrator
2) Run bcdedit to check hypervisor status:
bcdedit
3) Check hypervisor launch type:
4) If is set to auto then disable it:
bcdedit /set hypervisorlaunchtype off
5) Reboot host machine and launch VirtualBox again
Disabling Device Guard or Credential Guard fixed for me:
click Start > Run, type gpedit.msc, and click Ok. The Local Group Policy Editor opens.
Go to Local Computer Policy > Computer Configuration > Administrative Templates > System > Device Guard > Turn on Virtualization Based Security.
Select Disabled.
Go to Control Panel > Uninstall a Program > Turn Windows features on or off to turn off Hyper-V.
Select. Do not restart.
Delete the related EFI variables by launching a command prompt on the host machine using an Administrator account and run these commands:
mountvol X: /s
copy %WINDIR%\System32\SecConfig.efi X:\EFI\Microsoft\Boot\SecConfig.efi /Y
bcdedit /create {0cb3b571-2f2e-4343-a879-d86a476d7215} /d "DebugTool" /application osloader
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} path "\EFI\Microsoft\Boot\SecConfig.efi"
bcdedit /set {bootmgr} bootsequence {0cb3b571-2f2e-4343-a879-d86a476d7215}
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} loadoptions DISABLE-LSA-ISO,DISABLE-VBS
bcdedit /set {0cb3b571-2f2e-4343-a879-d86a476d7215} device partition=X:
mountvol X: /d
Note: Ensure X is an unused drive, else change to another drive.
Restart the host.
Accept the prompt on the boot screen to disable Device Guard or Credential Guard.
Source: https://kb.vmware.com/s/article/2146361
disabled Hyper-V (Control Panel\Programs\Programs and Features\ Hyper-V)
modify BCD (bcdedit /set hypervisorlaunchtype off)
If core isolation is enabled, turn it off (Windows Defender Security Center> Device Security> Core Quarantine)
If you cannot modify it, you can change the value of HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ DeviceGuard \ Scenarios \ HypervisorEnforcedCode Integrity \ Enabled in the registry to 0
1) Run below command in powershell with admin mode:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
2) run below command in command prompt with admin mode:
bcdedit /set hypervisorlaunchtype off
3) disabled Hyper-V: Control Panel\Programs\Programs and Features\
4) VMBox memory made it to: 3155 MB (VMbox->settings->system)
VM box Acceleration is deactivated. How do activate this? and fix above error?
Restart your system.
To check the status of Hyper-v in Windows 10,
right click <"start"> → Run → OptionalFeatures.exe, → look for the "Hyper-V" option.
The box should be empty, not checked or shaded.
Make sure to fully power down and reboot the host after changing the Hyper-v setting.
PS
Docker known for activating this "Hyper-V" without asking for user opinion and then Oracle VirtualBox does not want to work.
Finally I can fix the issue now.
At first, we need to identify or understand the problem which mostly people not really findout, my VM is came with guest OS of Ubuntu 64-bits but after import, we check on that VM it shows only 32-bits OS.
When we start the VM, we got error as:
Failed to open a session for the virtual machine ERPNext-Develop-20180331192506.
Raw-mode is unavailable courtesy of Hyper-V. (VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT).
Result Code: E_FAIL (0x80004005)
Component: ConsoleWrap
Interface: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}
I did try above solutions, somehow not really work or I might miss something.
Then I notice the point above (32-bits OS) so I think the problem might be with this one.
With some posts around the Internet, it could explain that Windows 10 also comes with the Hyper-V which is conflict with Oracle VM VirtualBox.
So solution I did...
1. Disable Virtualization Based Security in group policy
Start Run application and start: gpedit.msc
Go to Computer configuration > Administrative Template > Device Guard
Disable Microsoft Hyper-V
Start Run application and start: OptionalFeatures.exe
Untick: Hyper-V
Restart the PC
Then we can use the VM, it's started. Among the two steps above, I believe that step 2 is really solved.
Anyway, please try it and let's know if it helps.
I wanted learn how to use vagrant with virtualbox, when I got the error message 'Raw-mode is unavailable courtesy of Hyper-V'.
To fix this issue, I think I made all of the suggested changes above (thank you guys), and some more.
Let me summarize:
( cmd: optionalfeatures )
Turn off 'Hyper-V'
Turn off 'Containers'
Turn off 'Windows Subsystem for Linux'
cmd: bcdedit /set hypervisorlaunchtype off
( cmd: gpedit.msc )
Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Device Guard ->
Disable 'Turn On Virtualization Based Security'
Settings -> Update & Security -> Windows Security -> Device Security -> Core isolation details -> Memory integrity -> Off
You need to disable the windows Hyper-V feature and bcd. Then Virtual Box will run in latest Windows 10 versions (Jan-Mar 2018). Windows 10 Hyper-V is having clash on VirtualBox features.
I have resolved this by following steps-
bcdedit /set hypervisorlaunchtype off
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
Restart your windows
Detailed discussion on this are available at -
https://forums.virtualbox.org/viewtopic.php?f=6&t=87237
Alternatively you can install linux (Ubuntu) in Windows 10 from the latest bash command - https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10
For me the combination of the following three was the solution:
1.
control panel > turn windows features on or offf > Hyper-V : deselect
2.
admin cmd > bcdedit > hypervisorlaunchtype:Auto
disabling:
bcdedit /set hypervisorlaunchtype off
3.
gpedit.msc > 'Computer configuration > Administrative Template > System > Device Guard' > Turn On Virtualization Based Security :
Change from 'Not configured' to 'Disabled'
REBOOT
note: after the reboot the VirtualBox worked, but Docker Desktop's VirtualBox started complaining about missing Hyper-V !
It seems that this might have been the root of all my evil...
Extra info: https://forums.docker.com/t/running-docker-and-virtualbox-on-the-same-machine/23578/13
You have to disable Memory Integrity.
Go to Device Security, then Core Isolation, disable Memory Integrity and reboot.
It seems that Memory Integrity virtualizes some processes (in this case, VMware) and we get that error.
You can also disable Memory Integrity from Registry Editor if your control panel was saying 'This is managed by your administrator'.
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceGuard\Scenarios\HypervisorEnforcedCodeIntegrity
Double click on Enabled and change its value from 1 to 0 to disable it.
Helpful source: https://forums.virtualbox.org/viewtopic.php?t=86977#p420584
In my case, was the Docker that cause problems:
After Windows 10 update in July of 2018 I suddenly experienced this issue with Virtual Box losing 64-Bit OS options resulting in the error.
virtualbox Raw-mode is unavailable courtesy of Hyper-V windows 10
Existing Laravel Homestead Boxes rendered un-bootable as a result event though HYPER-V is Disabled / Not Installed...
The FIX! (That worked for me) Drum Roll....
Install Hyper-V... Reboot, Uninstall it again... Reboot... The end
As in the docs, if you are on windows you can use hyperv drivers.
Docker for Windows - You can use docker-machine create with the hyperv
driver to create additional local machines.
Run CMD in administrator mode
1.bcdedit
2.bcdedit /set hypervisorlaunchtype off
3.Reboot system
This worked for me!!
The latest version of virtual box 6.0 supports HyperV !
https://docs.oracle.com/en/virtualization/virtualbox/6.0/admin/hyperv-support.html
Mi helped:
windows defender settings >> device security >> core insulation (details) >> Memory integrity >> Disable (OFF)
SYSTEM RESTART !
Mi helped: windows defender settings >> device security >> core insulation (details) >> Memory integrity >> Disable (OFF) SYSTEM RESTART !
this solution is better for me
This would be the easiest way.
1) go and download the Device Guard and Credential Guard hardware readiness tool here- https://www.microsoft.com/en-us/download/details.aspx?id=53337
2) Find the folder path of "DG_Readiness_Tool_v3.5.ps1" of downloaded content and run the below command after enable Powershell "unrestricted".
"./DG_Readiness_Tool_v3.5.ps1 -Disable -AutoReboot"
3) When rebooting the machine press F3 to confirm to disable the features
In my case, the problem was with the specific box I was trying to use ubuntu/xenial64, I just had to switch to centos/7 and all those errors disappeared.
Hope this helps someone.
I have exactly the same question and have done the same things as you with no success.
I found an entries in my log of
HM: HMR3Init: Falling back to raw-mode: VT-x is not available
VMSetError: F:\tinderbox\win-5.2\src\VBox\VMM\VMMR3\VM.cpp(361) int __cdecl
VMR3Create(unsigned int,const struct VMM2USERMETHODS *,void (__cdecl *)(struct UVM *,void *,int,const char *,unsigned int,const char *,const char *,char *),void *,int (__cdecl *)(struct UVM *,struct VM *,void *),void *,struct VM **,struct UVM **); rc=VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT
00:00:05.088846
VMSetError: Raw-mode is unavailable courtesy of Hyper-V. 00:00:05.089946
ERROR [COM]: aRC=E_FAIL (0x80004005) aIID={872da645-4a9b-1727-bee2-5585105b9eed} aComponent={ConsoleWrap} aText={Raw-mode is unavailable courtesy of Hyper-V. (VERR_SUPDRV_NO_RAW_MODE_HYPER_V_ROOT)}, preserve=false aResultDetail=0 00:00:05.090271 Console: Machine state changed to 'PoweredOff'
My chip says it has VT-x and is on in the Bios but the log says not
HM: HMR3Init: Falling back to raw-mode: VT-x is not available
I have a 6 month old Lenovo Yoga with 2.7-GHz Intel Core i7-7500U
I have tried the following, but it didn't work for me.
From this thread https://forums.virtualbox.org/viewtopic.php?t=77120#p383348 I tried disabling Device Guard but Windows wouldn't shut down so I reenabled it.
I used this path ....
On the host operating system, click Start > Run, type gpedit.msc, and click Ok. The Local group Policy Editor opens.
Go to Local Computer Policy > Computer Configuration > Administrative Templates > System > Device Guard > Turn on Virtualization Based Security. Select Disabled.
i had same problem guys
virtual box was running smoothly on my windows machine but when new update came virtual started giving me this error and believe me guys just a little S%$& thing fixed it
in my case this problem fixed just by installing windows extension pack that's it

vmware error after removing disk

Environment: vmware VMware® Workstation 12 Pro (12.1.1 build-3770994) , running on Windows 7 Professional, 64-bit 6.1.7601, Service Pack 1.
A VM RHEL 7 with SCSI boot (virtual) disk is running on VMWare.
After previously adding and removing a secondary SATA virtual disk (.vmdk) the Red Hat VM is not booting with error message:
File not found: this file is required to power on this virtual machine...
There is a clean way to solve this, the disk has been added and removed from the virtual machine settings, section hardware?
I found the solution:
The Rhel VM has a snapshot, and the snapshot's configuration had a reference to the removed disk.
So I edited the file vmsd of the VM (RHEL7_dev_64-bit.vmsd)
changing the config from this:
snapshot0.numDisks = "2"
snapshot0.disk0.fileName = "RHEL7_dev_64-bit-disk.vmdk"
snapshot0.disk0.node = "scsi0:0"
snapshot0.disk1.fileName = "Ubuntu 64-bit-s001.vmdk"
snapshot0.disk1.node = "sata0:0"
to this:
snapshot0.numDisks = "1"
snapshot0.disk0.fileName = "RHEL7_dev_64-bit-disk.vmdk"
snapshot0.disk0.node = "scsi0:0"

reboot VM (run on vbox) into specific (compiled) kernel from shell

Im running ubuntu 14.04 with vbox . In this machine I compiled and run kernel 3.14 which I choose from the grub menu when ubuntu load on vbox.
The host also run on ubuntu 14.04.
I wanted to ask - is there a way to load the guest ubuntu into specific kernel with a command on shell?
I can start running a vm on vbox trough command line with this command :
VBoxManage startvm ubuservloc --type headless
but its not quite exactly what I need.
I don't know of any way to directly communicate from the host to the guest's GRUB, but there are several indirect ways you could go:
mount the /boot filesystem from the host and drop a file there that is read by the guest's grub.cfg.
VBoxManage controlvm keyboardputscancode to type a hotkey which is assigned to the correct kernel in GRUB (shortly after starting the VM)
Configure GRUB to listen to a (virtual) serial port and select the kernel by writing to that file
In case a second reboot is acceptable (first boot into default kernel and then reboot into desired kernel) there are also several ways (you can use the grub-set-default command from guest to choose your desired kernel and issue a reboot). Some I can think of here:
VBoxManage guestcontrol run to call a shell script from host in the guest (after guest additions have been loaded)
VBoxManage guestproperty to set a property from host and VBoxControl guestproperty to read it from an init script and decide from there
Just SSH into the guest and reboot from there :D
Obviously, if you always want to boot that kernel, why not make it default? And in case always you want to alternately boot two different kernels, you can also set the default for next boot to another one direclty from grub.cfg.

Error VT-x not available for Vagrant machine inside Virtualbox

I have an Ubuntu Virtual machine that is configured to have VT-x enabled, 6 Processors, and 25 GB RAM.
Inside that virtual machine I am trying to start a vagrant machine with the following configuration:
master.vm.box = "precise32"
master.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cpuexecutioncap", "80"]
vb.memory = 10000
vb.customize ["modifyvm", :id, "--cpus", "2"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
When I start the Vagrant I get the error VT-x not enabled.
I tried both 32 bit and 64 bit versions of Vagrant but still no luck.
Any idea how can I run Vagrant machine inside the Virtualbox?
You can only use one virtual CPU without VT-x. Thus, the error message stating that VT-x isn't enabled is caused by the following line:
vb.customize ["modifyvm", :id, "--cpus", "2"]
Replacing it with the following works (Vagrant has a shorthand for setting the CPU count):
vb.cpus = 1
NOTE: You can only run 32-bit VMs inside another VM.
Vagrant in nested Virtual Box
First of all you can run definitely Vagrant inside a nested Virtual Box.
VT-X Support (related to VirtualBox)
Currently VirtualBox is not supporting nesting VT-X. There is currently a feature request pending(see.: https://www.virtualbox.org/ticket/4032) but as of now it is not expected to be in a new version of VirtualBox
Consequences from missing VT-X in nested VirtualBox
There are currently two consequences from nesting without VT-X:
You cannot use multiple CPUs but you can use a single virtual cpu using vb.cpus = 1
You cannot run a 64-Bit VM within a nested VirtualBox.
UPDATED: As pointed out below, you can use nested VirtualBox + vagrant provided that only 1 virtual CPU is assigned to the nested VM, plus nested VM guest is 32-bit OS.
You can not use the first VM as Virtual Box one. That's sure. But what you can do is, make the first VM ( Ubuntu) based on VMware Player 7, then you can set up Vagrant on that. Tested and confirmed on my own. VMplayer version 7 and Virtual Box version 5.0.20. Thanks to the comment from Rudolf in the same page
If you run vagrant + VirtualBox within a VirtualBox virtual machine and you face networking problems :
Don't forget to set the right virtual network adapter
I had to set the Adapter type to Paravirtualized Network (virtio-net)
in Settings -> Network -> Advanced to make it work
VirtualBox inside VirtualBox wont work. Try VMPlayer and then inside install VirtualBox and vagrant. Its works for me.
If you're using packer and running into this error please make sure you have enough CPU's to actually stand up the image.
I had stated to build the image with two CPUs but was only running a 2 core VM myself. Changed it down to 1 cpu and build ran without any errors.