# 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
```

Make sure the VM is not DRBD mirrored.  If it is, then

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


## Shrink the partition(s)

Use a gparted bootable iso or a Linux live bootable iso to run
`gparted` to shrink the partitions.


## Backup the instance

Make sure the destination node has sufficient space.  If not, on the
destination node, you can

```
lvextend -L +128G /dev/mapper/ganeti-var
resize2fs /dev/mapper/ganeti-var
```

Then

```
gnt-backup export -n vm3 rpki.dfw.rg.net
```

## Restore into Smaller Space

```
gnt-backup import -n vm0 --src-node=vm3 --disk 0:size=21G -t plain rpki.dfw.rg.net
```

## And you should be good to go


# SKIP THE REST OF THIS!!!  The above is the hack you want

## 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.

---

2020.10.03