# Expanding a Linux Disk on a VM

If a VM is getting a bit tight for disk space, you can expand the size of a drive.  This example is the more difficult one of expanding the primary drive.  The example uses the instance name rpki.dfw.rg.net, which should be replaced by your own, of course.

## Tell Ganeti to Grow the Disk

**Unless you want the glow-disk to take a very long time, turn off drbd for the instance and turn it back on at the end of all this.**

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

First you need to make the Ganeti disk allocation larger.

```
gnt-instance grow-disk rpki.dfw.rg.net 0 8G
```

grows the priimary drive by 8G.

This allocates more disk in Ganeti and creates a larger partition. But it does not tell Linux that the disk is bigger.

Also, like many gnt-instance modify commands, it will not take effect until the next Ganeti start, not reboot within the VM, but a real Ganeti instance reboot or shutdown/start.

## Increasing the Linux Partition Size

You can not grow the primary partion while running it.  So stop the instance

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

You will need the VNC console, so get the port number

```
gnt-instance list -o name,pnode,network_port rpki.dfw.rg.net
  console connection: vnc to vm3.dfw.rg.net:11014 (display 5114)
```

11014 in this example

You will also need the cluster VNC password, which is in `/etc/ganeti/vnc-cluster-password`

Boot from an appropriate CD ROM.  Note that you need a desktop ISO,  not a server

```
gnt-instance start -H boot_order=cdrom,cdrom_image_path=/ISOs/ubuntu-18.04.2-desktop-amd64.iso rpki.dfw.rg.net
```

And then start VNC to the console.

- Choose Try Ubuntu
- Choose the File Drawer
- Choose the Computer Device (which may be in Other Locations)
- Click on the Search Magnifying Glass
- Type 'gparted'
- There will be a 'gparted' icon, click it to run gparted
- [ there must be an easier way to do this ]

To expand the /dev/vda1 ext4 partition, you have to get the swap and extended partitions out of the way.

- Right click swap and turn Swapoff
- Right click the swap partition again and delete it
- Right click the exttended partition and delete it
- Click Edit in the menu bar and Apply All Operations
- Confirm, and when it's done, say thank you

You now should have the /dev/vda1 ext4 partition and a big unused partition.  Now you can grow the /dev/vda1.  But remember to leave room to create a new swap partition.

N.B. If you have a disk with LVM2 partitions, gparted will automatically activate them. This will prevent you from resizing the partition with  grow/resize. You can turn the LogicalVolumes off with 'vgchange -a n'.

Now

- Right click /dev/vda1 and select Resize/Move
- You can drag the bar or crank numbers in
- Be sure to leave room for a swap partition
- Click Resize/Move
- Right click the unallocated partition and select New
- Create as: Primary Partition
- File system: linux-swap
- Add the all the remaining unallocated disk space (unless you had other plans)
- Click Edit in the menu bar and Apply All Operations
- Confirm, and when it's done, say thank you

You should now have /dev/vda1 with an increased size and /dev/vda2 as a linux-swap partition.

Quit gparted and shut-down the linux desktop system.

You should now be able to start the VM

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

and find that it has been resized.  It may take a while to restart.  Likely this is trying to find the old swap partition by the UUID in `/etc/fstab`.

You will need to fix the sawp partition in `/etc/fstab`
```
blkid
```
to get it and edit `/etc/fstab`

On older gparteds, once it has booted, you will need to ssh in as root and

```
resize2fs
```

---

2023.12.19