# Shrinking a Ganeti Instance Disk

Thanks to Phil Regnauld for the clues.  In this example, we use  rpki.dfw.rg.net as the instance name.  Of course you will want to change that.

## Preparation

Shutdown the VM

```
gnt-instance shutdown rpki.dfw.rg.net
```

We need to get the uuid of the volume to be reduced

```
# gnt-instance info rpki.dfw.rg.net | grep primary
    - primary: vm3.dfw.rg.net
          on primary: /dev/ganeti/a5ce213c-d455-4cee-a173-4c3c72d81e68.disk0_data (253:10)
          on primary: /dev/ganeti/a5ce213c-d455-4cee-a173-4c3c72d81e68.disk0_meta (253:12)
```

Oops!  See that disk0_meta?  This means there is a drbd secondary. We never figured out how to deal with that, so you have to convert the instance to plain before proceeding.

```
gnt-instance modify -t plain --no-wait-for-sync rpki.dfw.rg.net
```

## Tell Ganeti to Chill

First we need to stop ganeti and backup the config file on the master

```
service ganeti stop
rsync /var/lib/ganeti/config.data /var/lib/ganeti/config.data.ORIG
```

## Actually Shrink the Volume(s)

Then we can lvreduce the disk on the node where the instance lives.  Note that the size parameter may be either an abusolute new size or the amount to be reduced.  Here we do the latter, on the instance's primary node, of course.

```
lvreduce —-size -8GB /dev/ganeti/a5ce213c-d455-4cee-a173-4c3c72d81e68.disk0_data
```

## Tell Ganeti's Config About the Change

Now is the grotty hack; we have to change the size in the ganeti config.data.  Find the JSON for the file UUID of the disk.  In this case, the JSON looked like 

```
"params": {}, "uuid": "a70acc51-586b-4a83-9a8c-ff884ef0c5b4", "size": 45056}, {"dev_type": "plain", "logical_id": ["ganeti", "a5ce213c-d455-4cee-a173-4c3c72d81e68.disk0_meta"]
```

Note the size, 45056, which is 45056/1024 = 44G.  I wanted to reduce by 8G, so 45056-(8*1024) = 36864

```
"params": {}, "uuid": "a70acc51-586b-4a83-9a8c-ff884ef0c5b4", "size": 36864}, {"dev_type": "plain", "logical_id": ["ganeti", "a5ce213c-d455-4cee-a173-4c3c72d81e68.disk0_meta"]
```

Phil prefers to de-JSON the config to make it easier to see before hacking

```
python -mjson.tool < /var/lib/ganeti/config.data > /tmp/config
```

## Restart Ganeti

Restart Ganeti and redistribute the modified configuration

```
service ganeti start
gnt-cluster redist-conf
```

## Clean Up

If the instance was of type drbd, remember to convert it back from plain.

```
gnt-instance modify -t drbd --no-wait-for-sync -n vm2 rpki.dfw.rg.net
gnt-instance start rpki.dfw.rg.net
```

And Bob's your uncle.