How to attach physical disk to VM using sunstone?

tl;dr solution in post below.


I am at my wits end after hours of trying to attach a physical disk to a vm.

I simply want to add for example /dev/sdb from my node to my VM. Nothing more.

Using virt-manager I can simply add a new disk as “raw”, linking to my device and boot.

How can this be achieved using OpenNebula Sunstone? Looking through the section in the docs did not help either.

I created a RDM datastore which obviously can’t be attached to the VM. Is there a way to add an image that links to the RDM linking to the physical device?

Thanks in advance!

EDIT:

Adding:

<disk type='block' device='disk'><driver name='qemu' type='raw' cache='none'/><source dev='/dev/sdb'/><target dev='vdc' bus='virtio'/></disk>

as KVM RAW to the template is not respected by OpenNebula / ignored / overwritten.

EDIT 2 (Solution!):

To add a physical disk to a VM using OpenNebula, update your template and add:

<devices><disk type='block' device='disk'><driver name='qemu' type='raw' cache='none'/><source dev='/dev/YOUR_LOCAL_DEVICE'/><target dev='vdc' bus='virtio'/></disk></devices>

to the kvm field.

Mind the surrounding <devices></devices> as libvirt will else wise not know to which section it should add this!

5 steps “How to add a physical disk to a VM in OpenNebula” explained with images:



Now deploy your template. Mind that deploying it multiple times may result in data corruption as multiple VM’s will access the same device! This is more of a solution for a single VM with persistent storage.

1 Like

Hi Bent

I have been thinking about similar idea but I am so impressed by your approach. However, I am new to opennebula but wish to know some few things if you don’t mind:
is “your_local_storge” a disk on front-end? lets say my a disk on my centos7?
it is possible to install the OS on this disk if I manage to add it (i.e will it behave like any primary disk"

thank you.

Hi @Maddoxi,

Please note that @Bent_Haase post is a few years old. Probably you may want to take a loot at Raw Device Mapping (RDM) Datastore — OpenNebula 6.2.1 documentation. This will allow you to use existing devices in the HV node as VM disks:

The RDM Datastore is an Image Datastore that enables raw access to block devices on Nodes.

Once the device is attached to the VM you will be able to use it as any other disk.

1 Like