# \[SOLVED\] Resize disk, custom image with partitions

**URL:** <https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175>\
**Category:** Product Support\
**Created:** [July 18, 2018, 2:01pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175 "2018-07-18T14:01:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [July 18, 2018, 2:01pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/1 "2018-07-18T14:01:30Z")

</div>

Hi,  
I have a custom centos7 image that I created using lvm with different partitions for /var /tmp /home /opt / etc.  
Now I would like to run specific commands following a resize request from sunstone (or the cli) to resize the proper and fix some GPT issues after a disk resize. However I can’t find where this process is documented or if it is possible to achieve this.

Your help is appreciated !  
Thank you

* * *

**Versions of the related components and OS (frontend, hypervisors, VMs):**  
5.4.13

---

<div class="post-metadata">

**Author:** ![honesta](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@honesta](https://forum.opennebula.io/u/honesta)\
**Post date:** [July 18, 2018, 7:32pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/2 "2018-07-18T19:32:26Z")

</div>

Storage is managed by the OS on both the OpenNebula host and the nodes… So far I only attached SYSTEM with NFS shares, and the way that works is you export the NFS as usual - then OpenNebula ‘mounts’ the storage. So far I was only able to attach in Filesystem shared mode. I had a hard time making it happen until I realized that the “host bridge list” works only with one host - the ‘list’ must stand for multiple interfaces? In any case, you must prep your shares in the Linux OS before you can attach and use them.

I have /var/lib/one/datastores NFS exported on the OpenNebula control node. I am not sure what I did, if any on the compute nodes.

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [July 23, 2018, 6:19pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/3 "2018-07-23T18:19:52Z")

</div>

Hi, in my case i’m using ceph as shared block storage. The volume is already resized by onebula, however I need to run some gpart command into the VM to fix the GPT once resized. Is there some kind of hook that I can call after a volume resize ?

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [August 21, 2018, 12:35pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/4 "2018-08-21T12:35:02Z")

</div>

Bump, Is there some kind of hook that I can call after a volume resize ?

---

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [August 21, 2018, 2:19pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/5 "2018-08-21T14:19:29Z")

</div>

I am using an udev rule, probably in your case you should alter the default [contextualization](http://docs.opennebula.org/5.6/operation/vm_setup/kvm.html) script if it does not work for you

> [@Quick question about the XML-RPC API](https://forum.opennebula.io/t/quick-question-about-the-xml-rpc-api/5417/3):
>
> Not ideal, but for basic resizing on linux VMs the following snippet dropped as /etc/udev/rules.d/90-diskresize.rules works for me: SUBSYSTEM!="block", GOTO="oneend" ACTION=="change", GOTO="onediskresize" GOTO="oneend" LABEL="onediskresize" ENV{PATH}="/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin" PROGRAM!="/etc/one-context.d/loc-05-grow-rootfs", GOTO="oneend" LABEL="oneend" It is a little bit weird but crafted this way works on the udev implementations I hit. Best Regards, An…

Hope this helps,

Best Regards,  
Anton Todorov

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [August 27, 2018, 11:05am UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/6 "2018-08-27T11:05:03Z")

</div>

That works for me !  
Thx

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [August 30, 2018, 7:29pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/7 "2018-08-30T19:29:52Z")

</div>

Actually it kind of work. I just noticed the udev daemon loops on trying to resize the partition running my script over and over again. Any Idea what is causing this ?  
I tested the script manually and it works fine exiting 0.

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [August 30, 2018, 7:53pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/8 "2018-08-30T19:53:31Z")

</div>

I think it’s because the action _change_ is triggered again by my script running a parted on /dev/sda executing resizepart …

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [August 31, 2018, 11:12am UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/9 "2018-08-31T11:12:32Z")

</div>

FYI, here is what is my final resize script. Note that sda3 is the physical volume for lvm in all my VMs

```
#!/bin/bash
assignedSpace=0
freeSpace=0
for i in 1 2 3; do
   let assignedSpace+=$(cat /sys/block/sda/sda$i/size)
done
let freeSpace=$(cat /sys/block/sda/size)-$assignedSpace
if [$freeSpace -gt 8192]; then
    cat <<EOF | parted ---pretend-input-tty /dev/sda > /dev/null 2>&1
p
f
f
resizepart 3 100%
q
EOF
    pvresize /dev/sda3 > /dev/null
fi
```

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [September 21, 2018, 12:56pm UTC](https://forum.opennebula.io/t/solved-resize-disk-custom-image-with-partitions/6175/10 "2018-09-21T12:56:51Z")

</div>

After running into some issues with the script being called multiple times by udev which ended up running the script in parallel, I added a file lock to prevent this behaviour.

```
#!/bin/bash
(
flock -x 9
assignedSpace=0
freeSpace=0    
for i in 1 2 3; do
  let assignedSpace+=$(cat /sys/block/sda/sda$i/size)
done
let freeSpace=$(cat /sys/block/sda/size)-$assignedSpace
if [$freeSpace -gt 8192]; then
  cat <<EOF | parted ---pretend-input-tty /dev/sda > /dev/null 2>&1
p
f
f
resizepart 3 100%
q
EOF
  pvresize /dev/sda3 > /dev/null
fi
) 9>/var/lock/pv_resize.lock
```
