get disk uuid on a running vm

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

get disk uuid on a running vm

Post by jcdole »

I have a configuration bash script that run on a usb disk on the guest for configuring a new installed OS.
The script has access to parameters in a config file :
DISK UUID : given by VB when creating the VM
MAC ADRESS : set when creating the VM
SWAP DISK UUID : given during OS installation

I would like this script to get the disk uuid, the mac address and the swap uuid to verify that the script will apply to the expected machine.
I could not find a way to read the disk uuid from the guest.

Any help is welcome.
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: get disk uuid on a running vm

Post by jcdole »

Hello.
Is there any body here ?
Any help is welcome
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: get disk uuid on a running vm

Post by scottgus1 »

Looks like we missed this one, but I don't personally know how to solve it.
jcdole wrote:a configuration bash script
This sounds like the sort of thing that would run in a physical Linux PC, too. If you can get the solution for how you'd read a physical PC's UUIDs, MAC address, etc, then the same solution should work in a VM.
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: get disk uuid on a running vm

Post by fth0 »

In general, there are two different types of disk UUIDs, the VirtualBox virtual disk image UUIDs and the Linux filesystem UUIDs:

VirtualBox uses UUIDs to differentiate between different virtual disk images (e.g. VDI files, base images, snapshots). If you clone a virtual disk image or a whole VM, the cloned virtual disk image either gets new UUID(s) or not, depending on the dialog settings or commands used. If you want to use two virtual disk images in the same VirtualBox installation, these UUIDs must be different.

Linux filesystems use UUIDs to differentiate between different partitions of disk drives. VirtualBox doesn't know where and how those UUIDs are handled by the Linux OS (e.g. references in /etc/fstab), and doesn't change those UUIDs when cloning a virtual disk file.

Your "SWAP DISK UUID" is probably meant to be a Linux filesystem UUID and only known inside the guest OS.

Your "DISK UUID" is probably meant to be a VirtualBox virtual disk image UUID and only known inside the host OS. Inside the guest OS, you may be interested in the Volume Serial Number of the virtual hard disk, which is derived from its UUID. See /dev/disk/by-id or sudo hdparm -I /dev/sda<n> | grep Serial as possible starting points.
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: get disk uuid on a running vm

Post by jcdole »

Thank you for your answer.

On a vm the part uuid return by blkid is the same as the uuid of the vdi file.
Is this normal, a coincidence, or there was a problem at some point :

Code: Select all

VBoxManage showhdinfo ./*.vdi
UUID:           289e455f-4c8a-4eca-88b5-2756e1d2cfe3
Parent UUID:    base
State:          locked write
Type:           normal (base)
Location:       /virtual_LINUX_1/LEAP_15.3_VM_1_INITIAL/VDI/LEAP_15.3_VM_1_INITIAL.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       81920 MBytes
Size on disk:   7983 MBytes
Encryption:     disabled
Property:       AllocationBlockSize=1048576
In use by VMs:  LEAP_15.3_VM_1_INITIAL (UUID: 7e10741c-1d16-4bc7-b4f7-27718ec660b7)
compared to :

Code: Select all

blkid /dev/sda3
/dev/sda3: LABEL="LNX_SLASH_VM" UUID="289e455f-4c8a-4eca-88b5-2756e1d2cfe3" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="cc1b900c-ad36-4465-baa2-13c7a09fb11c"

Any comment is welcome.
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: get disk uuid on a running vm

Post by fth0 »

Good questions. Please provide the output of the whole ls -lR /dev/disk tree from inside the guest, and the output of sudo hdparm -I /dev/sda3. Are you sure that you didn't set the UUID yourself (for example by using your script)?
Post Reply