Important! Before making changes, be sure to make a backup (backup) of all server data. Any manipulations with partitions carry the risk of data loss.
- It is necessary to disable the GEOM security settings to work with partitions on the mounted device:
# sysctl kern.geom.debugflags=16
- There are a few more steps to follow to expand an existing partition.
2.1. We select a team:
# df -h
It will show which devices and their slices (a slice is a hard disk partition inside freeBSD) are connected and where. In our case, there is one slice - vtbd0p2
2.2. Let's look at the partition table of the entire vtbd0 disk:
# gpart show vtbd0
2.3. Attention! After changing the disk size (inside the hypervisor, for example), the GPT table will have the CORRUPT status.
Let's fix this:
# gpart recover vtbd0
2.4. Now we type the command:
# gpart show vtbd0
It will show us the correct slice table on disk, without the CORRUPT warning.
In our example, there is a swap. It needs to be disabled and removed as it is the last one on the disk. And to expand our slice to the end of the disk, the slice itself must be the last one.
2.5. Team
# swapinfo
will show the swap slice.
2.6. Team:
# swapoff /dev/vtbd0p3
will disable swap.
2.7. Then delete the swap slice:
# gpart delete -i 3 vtbd0
2.8. Make sure the slice is removed:
# gpart show vtbd0
2.9. Let's change the size of our slice from 5GB to 10GB (maximum):
# gpart resize -i 2 -a 4k vtbd0
2.10. Let's check:
# gpart show vtbd0
3.
After the slice is expanded to the maximum (in our example from 5GB to 10GB), you need to stretch the filesystem to the entire slice:
# growfs -y /dev/vtbd0p2
Now we type the command:
# df -h
It will show our slice is already the correct, expanded, size.
Ready.