Before proceeding
The operations described may affect the system and data, potentially causing malfunctions or data loss:
- always back up your data or the entire server externally before performing any operation;
- if available, create a snapshot of the server from the management panel before making changes to the system;
- for unmanaged services, you are responsible for managing the operating system and software;
- if in doubt, consult a trusted system administrator or check the latest official documentation for the operating system or software in use.
Preliminary information and warnings
The following instructions apply to the main Linux distributions:
- method A: Ubuntu 20.04/22.04, Debian 11/12, AlmaLinux/Rocky 8/9;
- method B: CentOS 7.
The commands may vary depending on:
- the partitioning type (LVM is recommended in corporate templates);
- the file system used (e.g. ext4 or xfs);
- the logical volume name (e.g. /dev/mapper/ubuntu--vg-ubuntu--lv or /dev/mapper/cl-root).
Important warnings:
- always check the correct device names (e.g. /dev/sda2 vs /dev/nvme0n1p2);
- do not delete or recreate the wrong partitions: check with lsblk, fdisk -l, pvdisplay, lvdisplay before making any changes;
- if the root partition is encrypted/LUKS or you have a custom layout, follow the vendor-specific documentation.
Method A - LVM (without reboot)
Connect to your Cloud Server via
SSH as the root user and follow these steps:
- To view the available disk space and the structure of the mounted partitions, use the command:
df -h
- to modify the partition table, run the command:
cfdisk
- 2.1. in cfdisk, to extend the partition that precedes the free space (usually the last one), select it and enter:
resize
or, if available:
maximize
- 2.2. to confirm the partition extension, enter the following command twice:
write
- to view the name and status of the physical volume (PV_NAME), enter:
pvdisplay
- to notify the system that the physical volume has more space available, enter:
pvresize PV_NAME
- to identify the path of the logical volume (LV) to extend, run:
lvdisplay
note the LV_PATH and the root partition size;
- to extend the root logical volume (LV) and the associated file system at the same time, enter:
lvextend -l +100%FREE -r LV_PATH
use the root LV_PATH obtained from the lvdisplay command in step 5, without quotation marks or other changes;
- press Enter and, if the operation is successful, the following message will be displayed:
lv root successfully resized.
Method B - CentOS 7 (parted + fdisk, requires reboot)
Connect to your Cloud Server via
SSH as the root user and follow these steps:
- to view the status of the mounted partitions and the available disk space, use the command:
df -h
- to check for unallocated free space on the disk, open the parted tool by entering:
parted
- 2.1. to display the list of partitions and free space, enter:
print free
- 2.2. to exit parted, enter:
q
- to modify the partition table, use the fdisk command:
fdisk /dev/sda
- 3.1. to display the partition table, enter:
p
- 3.2. to delete the existing LVM partition, enter:
d
when prompted, accept the suggested number (e.g. 2 or 3);
- 3.3. to create the new partition, enter:
n
accept the default values for:
- the starting sector (e.g. 1026048)
- the ending sector (e.g. 41943039)
- 3.4. to check the updated partition table, enter:
p
- 3.5. to set the new partition type to Linux LVM, enter:
t
then enter:
2
then:
8e
- 3.6. to write the changes and exit fdisk, enter:
w
- reboot the server to apply the changes using the command:
reboot
- after the reboot, reconnect via SSH as the root user;
- to resize the physical volume to include the newly added space, enter:
pvresize /dev/sda2
replace sda2 with sda3 or sdaN according to your configuration;
note the LV_PATH value (/dev/vg/lv_root);
- to resize the logical volume according to the new partition, use:
lvresize /dev/vg/lv_root /dev/sda2
replace the values according to your system configuration;
- to check again for unallocated free space on the disk, open the parted tool by entering:
parted
- 8.1. to display the list of partitions and free space, enter:
print free
- 8.2. to exit parted, enter:
q
- to check the status of the mounted partitions and the available disk space again, use the command:
df -h
- to extend the root logical volume and the file system, enter:
lvextend -l +100%FREE -r /dev/vg/lv_root
use the correct LV_PATH value (see step 7);
- to confirm that the operation was successful, enter:
df -h
if everything is correct, you will see the new percentage of free space available on the root partition.