# Block LVM use existing LV incorrect size calculation

**URL:** <https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760>\
**Category:** Product Support\
**Created:** [May 22, 2015, 6:28am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760 "2015-05-22T06:28:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sejo](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sejo](https://forum.opennebula.io/u/sejo)\
**Post date:** [May 22, 2015, 6:28am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/1 "2015-05-22T06:28:32Z")

</div>

All,

I’ve been trying for days now with different settings to use my image (an LV of 20GB) as the base for creating a new image in a block LVM datastore.

Each time I create it with path /dev/\<vg\>/\<lv\> it works but it calculates the size as 1MB. This makes that creating new instances get a LV with size of 1MB and thus the dd fails.

I can’t seem to change the size.

I’m trying to convert an existing setup from ganeti to opennebula but not being able to create images from an existing LV makes this impossible.

Can someone explain what to do, or where this is calculated? As I’m about to give up on opennebula.

Jochen

Update: Opennebula 4.12, ubuntu 14.04 LTS

---

<div class="post-metadata">

**Author:** ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)\
**Post date:** [May 25, 2015, 8:50am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/2 "2015-05-25T08:50:38Z")

</div>

from the docs

```auto

Warning

As this datastore does is just a container for existing devices images does
not take any size from it. All devices registered will render size of 0 and
the overall devices datastore will show up with 1MB of available space

```

You may try to set the SIZE in the image when it is created for information  
purposes.

---

<div class="post-metadata">

**Author:** ![sejo](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sejo](https://forum.opennebula.io/u/sejo)\
**Post date:** [May 25, 2015, 8:58am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/3 "2015-05-25T08:58:14Z")

</div>

Hi,

I did try that, SIZE and value 20G also tried with 20480M but it fails to register it.

When the image is made it’s still reported as 1MB

---

<div class="post-metadata">

**Author:** ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)\
**Post date:** [May 25, 2015, 9:10am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/4 "2015-05-25T09:10:11Z")

</div>

SIZE is in megabytes (without M), what are the log messages? what  
datastore drivers are you using?

---

<div class="post-metadata">

**Author:** ![sejo](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sejo](https://forum.opennebula.io/u/sejo)\
**Post date:** [May 26, 2015, 6:28pm UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/5 "2015-05-26T18:28:55Z")

</div>

I’m using the BLOCK LVM datastore, with the virtio drivers for kvm. When creating the image and setting SIZE 20480 as custom attributes, it still creates the image with 1MB size.

LOGS:

==\> /var/log/one/oned.log \<==  
Tue May 26 20:25:52 2015 [Z0][ReM][D]: Req:2528 UID:0 ImageAllocate invoked , "NAME=“ubuntu sejo lt…”, 100  
Tue May 26 20:25:52 2015 [Z0][ImM][I]: Copying /dev/data/9104e29c-54d5-4b87-8585-2dd430696724.disk0 to repository for image 15  
Tue May 26 20:25:52 2015 [Z0][ReM][D]: Req:2528 UID:0 ImageAllocate result SUCCESS, 15  
Tue May 26 20:25:52 2015 [Z0][ReM][D]: Req:6160 UID:0 ImageInfo invoked , 15  
Tue May 26 20:25:52 2015 [Z0][ReM][D]: Req:6160 UID:0 ImageInfo result SUCCESS, “15\<U…”

==\> /var/log/one/sunstone.log \<==  
Tue May 26 20:25:52 2015 [I]: 81.247.140.53 - - [26/May/2015 20:25:52] “POST /image HTTP/1.1” 201 - 0.0774  
Tue May 26 20:25:52 2015 [I]: 81.247.140.53 - - [26/May/2015 20:25:52] “GET /support/request?timeout=false&csrftoken=d98cecfcf62ac74e39c567044d4a7517 HTTP/1.1” 500 - 0.0010

==\> /var/log/one/oned.log \<==  
Tue May 26 20:25:53 2015 [Z0][ImM][I]: Image (15) copied and ready to use.  
Tue May 26 20:25:53 2015 [Z0][InM][D]: Monitoring datastore SeJoITLVM (100)  
Tue May 26 20:25:53 2015 [Z0][ImM][D]: Datastore SeJoITLVM (100) successfully monitored.  
Tue May 26 20:25:55 2015 [Z0][ReM][D]: Req:6480 UID:0 ImageInfo invoked , 15  
Tue May 26 20:25:55 2015 [Z0][ReM][D]: Req:6480 UID:0 ImageInfo result SUCCESS, “15\<U…”

---

<div class="post-metadata">

**Author:** ![sejo](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sejo](https://forum.opennebula.io/u/sejo)\
**Post date:** [May 26, 2015, 6:30pm UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/6 "2015-05-26T18:30:06Z")

</div>

output onedatastore show:

oneadmin@duvel:~$ onedatastore show 100  
DATASTORE 100 INFORMATION  
ID : 100  
NAME : SeJoITLVM  
USER : oneadmin  
GROUP : oneadmin  
CLUSTER : SeJoIT  
TYPE : IMAGE  
DS\_MAD : lvm  
TM\_MAD : lvm  
BASE PATH : /var/lib/one//datastores/100  
DISK\_TYPE : BLOCK  
STATE : READY

DATASTORE CAPACITY  
TOTAL: : 4.8T  
FREE: : 4.7T  
USED: : 41.9G  
LIMIT: : -

PERMISSIONS  
OWNER : um-  
GROUP : u–  
OTHER : —

DATASTORE TEMPLATE  
BASE\_PATH="/var/lib/one//datastores/"  
BRIDGE\_LIST="duvel"  
CLONE\_TARGET="SELF"  
DISK\_TYPE="BLOCK"  
DS\_MAD="lvm"  
HOST="duvel"  
LN\_TARGET="NONE"  
TM\_MAD="lvm"  
TYPE="IMAGE\_DS"  
VG\_NAME=“data”

IMAGES  
15

---

<div class="post-metadata">

**Author:** ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)\
**Post date:** [May 26, 2015, 7:48pm UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/7 "2015-05-26T19:48:06Z")

</div>

The problem could be in the `stat` action we call on image registering. The driver is meant to register images into LVM and it’s using `stat` command to get the image size. This is the call sequence:

> <https://github.com/OpenNebula/one/blob/master/src/datastore_mad/remotes/common/stat#L57>

> <https://github.com/OpenNebula/one/blob/master/src/datastore_mad/remotes/libfs.sh#L183>

> <https://github.com/OpenNebula/one/blob/master/src/datastore_mad/remotes/libfs.sh#L130>

Maybe you can change the `stat` action from LVM datastore to one that retrieves the LV size. Do it in `/var/lib/one/remotes/datastore/lvm/stat`. Something like:

```bash
SIZE=$(lvdisplay $SRC | grep 'LV Size' | awk '{print $3}' | sed 's/\..*$//')

```

---

<div class="post-metadata">

**Author:** ![sejo](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sejo](https://forum.opennebula.io/u/sejo)\
**Post date:** [May 26, 2015, 8:11pm UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/8 "2015-05-26T20:11:01Z")

</div>

That gives me [ImageAllocate] Cannot parse SIZE in the browser when trying to create it.

---

<div class="post-metadata">

**Author:** ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)\
**Post date:** [May 27, 2015, 5:11pm UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/9 "2015-05-27T17:11:19Z")

</div>

Can you check the error in `/var/log/one/oned.log`. It may give more info.

Also check that the LV is visible in the frontend.

---

<div class="post-metadata">

**Author:** ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)\
**Post date:** [May 27, 2015, 5:12pm UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/10 "2015-05-27T17:12:46Z")

</div>

Still, as I said before, the drivers are meant to have files as origin. These steps are just hacks that can give you more problems than help unless you know what they’re doing.

---

<div class="post-metadata">

**Author:** ![sejo](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sejo](https://forum.opennebula.io/u/sejo)\
**Post date:** [May 28, 2015, 6:19am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/11 "2015-05-28T06:19:13Z")

</div>

log:  
Thu May 28 08:18:40 2015 [Z0][ReM][D]: Req:4976 UID:0 ImageAllocate invoked , "NAME=“ubuntu lts sej…”, 100  
Thu May 28 08:18:40 2015 [Z0][ReM][E]: Req:4976 UID:0 ImageAllocate result FAILURE [ImageAllocate] Cannot parse SIZE

What do you mean disks directly to lvm are a hack? if so opennebula is not an option for me.

Jochen

---

<div class="post-metadata">

**Author:** ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)\
**Post date:** [May 28, 2015, 9:40am UTC](https://forum.opennebula.io/t/block-lvm-use-existing-lv-incorrect-size-calculation/760/12 "2015-05-28T09:40:59Z")

</div>

Doesn’t give much information unfortunately.

What I mean is a hack is the changes I’ve sent you. The driver was not designed to import LVs. Only images. This is the workflow it was designed for:

- Import raw **file** image
- The driver gets the size of the file and creates a LV of that size
- The driver dd’s the file into the LV
- Now the LV can be used for VMs or cloned in case it is not persistent

You are trying to import a LV, that’s the problem.

There are different solutions to use your LVs:

- Create a file image with dd and import that file

- Modify the drivers so it can import LVs directly. The changes I’ve sent you are a good start but I have not tested them

- If the images are persistent (used by only one VM) you can use the [devices datastore](http://docs.opennebula.org/4.12/administration/storage/dev_ds.html)

- Create an empty [datablock image](http://docs.opennebula.org/4.12/user/references/img_template.html#template-examples) in the datastore with the same size, get its LV name (use `oneimage show` and search for `SOURCE`) and rename the LV you want to import to it
