How to extend the disk volume partition available for a Virtual Server (Linux)

To use the disk of our virtual servers after upgrading, the partition of the logic disk volume needs to be extended. This operation cannot be performed automatically and depends on the operating system installed on the server.

To extend the partition of the disk volume, after identifying the Operating System, run the following commands (divided according to operating system) and after checking with the command “vgscan” the name of the volume group. If other than “vg01” replace.

Note: Please note that this process might be potentially harmful and it is advisable to backup your data before proceeding.

Register.it will take no responsibility for the process performed by the user and for possible loss of data. The process described below is to be considered purely as an example. For further details, please consult the official documentation of your Linux distribution.

Before proceeding it is important to understand partition type in use (if GPT or MBR). To determine the type of partition, run this command:

parted / dev / sda print

For the type of GPT partition will appear:

^575337176ECF336F42C8CA7FFA4B24573153E07A60260B8951^pimgpsh_fullsize_distr

 

 

 

 

 

For the type of MBR partition will appear Partition Table: mbr

Then, if it has been upgraded, a message appears:

Warning: Not all of the space available to / dev / sda Appears to be used, you can fix the GPT to use all of the space (an extra 2097152 blocks) or continue with the current setting?

Fix / Ignore?

Confirm the suggested solution (Fix).

If partition is GPT follow the steps below:

Run the following command (valid for all Operating Systems):

export vgname = $ (vgscan | grep "Found volume" | cut -d -f 6 "" | sed -e 's / \ "// g")
export disk_max = $ (parted -s / dev / sda unit mb print free | grep -Ei 'libre | Free | Livre | free' | awk '{print $ 2/1000}' | cut -d "M" -f1 | awk 'END {print}')
export disk_min = $ (parted -s / dev / sda unit mb print free | grep -Ei 'libre | Free | Livre | free' | awk '{print $ 1/1000}' | cut -d "M" -f1 | awk 'END {print}')
parted -s / dev / sda mkpart primary disk_min $ $ disk_max
export partition_number = $ (parted -s / dev / sda unit mb print | sort -nk1 | tail -n1 | awk '{print $ 1}')
vgextend $ vgname / dev / sda $ partition_number
lvextend -l + 100% FREE / dev / $ vgname / root

To make resize the file system

CentOS 7 (xfs filesystems):
xfs_growfs / dev / $ vgname / root
For all other Operating Systems (ext4 filesystem):
resize2fs / dev / $ vgname / root

If partition is MBR follow the steps below:

This procedure applies to the first resize. For the next, it is not possible to resize the primary partition active, contact Customer service.

DEBIAN/UBUNTU

#Adding a secondary partition to the primary disk (Debian/Ubuntu)
export disk_max=$(parted -s /dev/sda unit mb print free | grep Free | awk ‘{print $2/1000}’ | cut -d “M” -f1 | awk ‘END{print}’)
export disk_min=$(parted -s /dev/sda unit mb print free | grep Free | awk ‘{print $1/1000}’ | cut -d “M” -f1 | awk ‘END{print}’)
parted /dev/sda unit GB mkpart primary $disk_min $disk_max
export last_partition=$(parted -s /dev/sda print | grep -v “^$” | awk ‘END{print $1}’)
vgextend vg01 /dev/sda$last_partition
lvextend -l +100%FREE /dev/vg01/root
resize2fs /dev/vg01/root

CentOS 6

#Adding a secondary partition to the primary disk (CentOs 6)
export disk_max=$(parted -s /dev/sda unit mb print free | grep Free | awk ‘{print $2/1000}’ | cut -d “M” -f1 | awk ‘END{print}’)
export disk_min=$(parted -s /dev/sda unit mb print free | grep Free | awk ‘{print $1/1000}’ | cut -d “M” -f1 | awk ‘END{print}’)
parted /dev/sda unit GB mkpart primary $disk_min $disk_max
reboot
export last_partition=$(parted -s /dev/sda print | grep -v “^$” | awk ‘END{print $1}’)
vgextend vg01 /dev/sda$last_partition
lvextend -l +100%FREE /dev/vg01/lv_root
resize2fs /dev/vg01/lv_root

CentOS 7

#Adding a secondary partition to the primary disk ( CentOs 7)
export disk_max=$(parted -s /dev/sda unit mb print free | grep Free | awk ‘{print $2/1000}’ | cut -d “M” -f1 | awk ‘END{print}’)
export disk_min=$(parted -s /dev/sda unit mb print free | grep Free | awk ‘{print $1/1000}’ | cut -d “M” -f1 | awk ‘END{print}’)
parted /dev/sda unit GB mkpart primary $disk_min $disk_max
export last_partition=$(parted -s /dev/sda print | grep -v “^$” | awk ‘END{print $1}’)
vgextend vg01 /dev/sda$last_partition
lvextend -l +100%FREE /dev/vg01/root
xfs_growfs /dev/vg01/root