How to get an identier of the machine which a VM is running on.

Discussions about using Linux guests in VirtualBox.
Post Reply
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

How to get an identier of the machine which a VM is running on.

Post by jcdole »

Hello.
I have a system configuration script that I run on any Linux VM.
The script knows on which vm it is running ( by reading a specific file on the vm or reading the uuid of the swap file, .....).
A vm (*.vdi) can be installed on any Linux guests (real hardware computer).
My problem is that my script for some actions needs to know on which real computer it is running.

For testing my program, by reading the result of

Code: Select all

cat /proc/cpuinfo | uniq 
I can build an identifier based on the cpu model name (model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz).
Then the value of the identifier tell which is the host.
This is possible because I test using three different brand of laptop.But this is not relevant in real life where there are too many equivalent computers.

On the guest, Is there a way to identify the hardware on which the guest is running?

Any help is welcome.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to get an identier of the machine which a VM is running on.

Post by scottgus1 »

The only physical piece of hardware from the host PC that is seen by the guest is the host CPU. All the other hardware is simulated. Thus reading hardware to identify the host PC will fail when two host PCs use the same CPU, unless there is a serial number within the CPU guts that can be read.

Aside from the above, a guest cannot identify anything about the host PC it is running on. You could manually set information with 'vboxmanage guestproperty get/set' (in the guest use 'vboxcontrol guestproperty get/set'; Guest Additions are required).
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

Re: How to get an identier of the machine which a VM is running on.

Post by jcdole »

Your tips should only works if this can be done when you click on the start button and before the vm boot up.
it's not exactly realistic, then?
Or write my one virtualbox GUI?
it's not exactly realistic, then?

I think you have the technical means to give discriminant information:
The serial number of the computer
Either the serial number of the motherboard
Either the serial number of the processor
Either the mac address of an ethernet device
Either the mac address of a wifi device

This is more interesting than to know that the motherboard is manufactured by virtualbox.

And if you fear information collisions with the real computer, you can add 'vb' for example.

Anyway you already know that, is not it.

Have a good day.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to get an identier of the machine which a VM is running on.

Post by scottgus1 »

I'm not quite certain what you are saying, unfortunately.

Do you believe there is a way to find out things about the physical PC inside the guest OS?

I ran CPU-Z inside a Windows guest (I am not skilled enough in Linux) and found that CPU-Z reported the guest CPU correctly as the physical CPU, as expected. The motherboard was reported as originating with Virtualbox, not the physical Biostar T-55 motherbord in the physical host PC. Chipset and network card fit the virtualized hardware provided by Virtualbox, not the physical hardware, as expected.

Virtualbox could be reprogrammed to read available host hardware info and report it to the guest OS through 'extradata' info (see the manual), but that reprogram would probably have to be done by a user. If the paying Oracle customers haven't asked for that by now it probably won't be asked for. And only the paying customers get to guide development. We free Virtualbox users have no say in development, aside from posting enhancement requests on the Bugtracker.

BTW, if "you" as in
jcdole wrote:I think you have the technical means to give discriminant information:
means me, as in 'scottgus1', then, no, I have absolutely no idea how to reprogram such a change. If 'you' means the developers, they do have the skills, but they have said they only have time & funding to do what the paying customers want.
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

Re: How to get an identier of the machine which a VM is running on.

Post by jcdole »

Do you believe there is a way to find out things about the physical PC inside the guest OS?
Of course yes.
Because the virtualbox vm is just 4 or 5 drivers which talk to the hardware. ( 'just' does not mean that they are not valuable softwares ).
And without talking to the hardware, I could not imagine how to run a virtual machine.

Anyway i think that the fake guest motherboard should contains some unique uuid like the mac address the network card have.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to get an identier of the machine which a VM is running on.

Post by scottgus1 »

jcdole wrote:i think that the fake guest motherboard should contains some unique uuid
It does. That's one of the things activated OS's use to know they're still on the activated 'hardware'. But that 'fake' guest motherboard UUID is not in any way related to the physical PC's motherboard or identifier. Copy that guest to a new host PC and the motherboard UUID will remain the same.
scottgus1 wrote:Do you believe there is a way to find out things about the physical PC inside the guest OS?
jcdole wrote:Of course yes.
If that's "I believe it could if programmed to", then yes it could, if someone set about to do it.

If you know of a way this capability exists now, please let us know. The manual does not relate any ways that I know of where Virtualbox shows the guest OS what the host's physical hardware is.

If this capability does not exist now and you want it to, then unless you personally are willing to reprogram Virtualbox, or to pay someone to do it, this capability is not going to be available unless paying Oracle customers want it too. It is hard to have to accept this situation, but the sooner we wrap our minds about where the river is flowing to, the sooner we can enjoy the swim.

If your particular use case requires this capability, you will have to either reprogram Virtualbox as mentioned above, or set up a host script that gathers the information you want the guest OS to see, feeds that data through 'extradata' or 'guestproperty', then a guest script reads these and operates appropriately.
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

Re: How to get an identier of the machine which a VM is running on.

Post by jcdole »

Thank you for your answer.
scottgus1 wrote:
jcdole wrote:
i think that the fake guest motherboard should contains some unique uuid
It does. That's one of the things activated OS's use to know they're still on the activated 'hardware'. But that 'fake' guest motherboard UUID is not in any way related to the physical PC's motherboard or identifier. Copy that guest to a new host PC and the motherboard UUID will remain the same.
How to get that identifier ?
Is it the one return by :

Code: Select all

15-3-VM-1-INITIAL:~ # dmidecode -t1
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: innotek GmbH
        Product Name: VirtualBox
        Version: 1.2
        Serial Number: 0
        UUID: 1c74107e-161d-c74b-b4f7-27718ec660b7
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Virtual Machine
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to get an identier of the machine which a VM is running on.

Post by scottgus1 »

(Edit: Yes, that's the 'machine UUID' foir the VM in Virtualbox, though the endian-ness of the UUID may be an issue. See further on)

In a Windows VM, one can run this command in an Admin command prompt:

wmic path win32_computersystemproduct get uuid

Compare the returned UUID with the "Machine UUID" in the VM's .vbox file. They should be the same UUID (they were in a test on my Windows 7 VM).

Linux probably has some similar method.

Run the same command on the host, and the UUID will be extremely likely to be different, based on the chances of UUIDs duplicating.

I'm not entirely sure what 'dmidecode' draws from. I ran a 'dmidecode -t1' in the Windows VM and got a different UUID which did not appear in the VM's .vbox file. See below, endian-ness strikes again....
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to get an identier of the machine which a VM is running on.

Post by fth0 »

scottgus1 wrote:I ran a 'dmidecode -t1' in the Windows VM and got a different UUID which did not appear in the VM's .vbox file.
dmidecode -t1 and dmidecode -s system-uuid return the VirtualBox Machine UUID. Note that depending on when the VM was created in the past, the first 3 parts of the UUID must be corrected for endianness (see System UUID for the gory details). ;)
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to get an identier of the machine which a VM is running on.

Post by scottgus1 »

You are correct, fth0! I see the edian-ness issue in the UUIDs, which threw me off before:

From the test Windows 7 VM:
dmidecode -t1:
AFA8ED47-9E0E-5146-BB41-307DF1D6C19C

dmidecode -s system-uuid:
AFA8ED47-9E0E-5146-BB41-307DF1D6C19C

wmic path win32_computersystemproduct get uuid
47EDA8AF-0E9E-4651-BB41-307DF1D6C19C

.vbox file machine uuid:
47eda8af-0e9e-4651-bb41-307df1d6c19c

The UUIDs are the same, accounting for endian-ness and case.

@jcdole, please note, though, that none of these are from the host hardware. The UUID returned by the wmic command and dmidecode on the Windows 10 host is "203F7481-50C5-11CB-8E4A-8ECEB34E2B29".
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

Re: How to get an identier of the machine which a VM is running on.

Post by jcdole »

And the answer to get an unique code for a vm is ? ? ?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to get an identier of the machine which a VM is running on.

Post by scottgus1 »

jcdole wrote:And the answer to get an unique code for a vm is ? ? ?
Are you referring to this question:
jcdole wrote:The script knows on which vm it is running ....
My problem is that my script for some actions needs to know on which real computer it is running.
If so, the answer has been presented above.

The summary:

You can't.

Virtualbox does not have methods to tell the VM OS what host it is running on. You must make your own program to get that data. How to do so can be found by careful reading of the answers to your posts above.
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

Re: How to get an identier of the machine which a VM is running on.

Post by jcdole »

OK, Noted.
Thank you very much
Post Reply