Question: I want to attach an actual drive to a VirtualBox VM, so I [followed the instructions here](https://www.virtualbox.org/manual/ch09.html#rawdisk), which says to do this:

```
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sdX

```

That creates a virtual hard drive (`file.vmdk`) which can be attached to the VM, and it is a sort of wrapper for the actual drive. And that works.

However based on which drives I have connected at any one time, the `sdX` device name changes, and the wrong physical drive is then shown to the VM.

So I want to specify the UUID name instead. How can I do that?

Answer: 
You can use the `lsblk` command like this:

```
sudo lsblk /dev/sdaX -no UUID

```

To get the partition uuid but you can also use the device file system.

```
ls -l /dev/disk/by-uuid

```

To confirm which UUID you want to use. That file will refer to which ever /dev/sdX matches the UUID.

Then use that in the xboxmanage command.
Usually, partitions have a UUID, but not the whole drive. It should have a unique ID, though. You can easily create a vmdk by pointing the command to the latter:

```
VBoxManage internalcommands createrawvmdk -filename <image_name>.vmdk -rawdisk /dev/disk/by-id/<ID_of_the_drive>

```

Or open an existing vmdk file with a text editor and replace `/dev/sdX` by hand.