📜 ⬆️ ⬇️

Add disk space for a Linux – server in the Azure Pack Infrastructure cloud, and at the same time, we are working with LVM

This article will look at the process of increasing disk space on a Linux – server in the Azure Pack Infrastructure cloud from InfoboxCloud . This is a standard procedure performed using LVM, which is in any Linux – image in our cloud.

This instruction is useful not only to increase the size of a single disk, but also to create a common space of connected virtual disks, which allows you to overcome the maximum size of a virtual disk (for a VHD - 2048 GB) and create a single large space for data.


If you do not want to understand this, just email us a ticket to technical support and we will do everything for you.
')

What is LVM?


LVM is a logical disk management system for Linux, a high-level view of the storage subsystem on a server (higher than disks and partitions). This technology gives system administrators the flexibility to allocate disk space for applications and users, including the ability to resize a logical volume.

When Linux is installed on the server - one of the tasks of choice is how to partition the disk. With LVM, the disk is included in the volume group (volume group) and logical volumes are created for example for the root of the disk /. In the future, you can change the size of logical volumes.

LVM device


By itself, the high-level abstraction of LVM includes logical volumes (LV) and physical volumes (PV).

Physical volume (PV, physical volume) - a virtual disk of the server or a regular hard disk (or it can be a RAID).

A logical volume (LV, logical volume) is the equivalent of a partition. It is represented by the OS as a standard block device and may contain a file system.

A volume group (VG, volume group) is a logical union of volumes.

Physical block (PE, physical extent) - pieces of data on a physical volume, within a volume group have an identical logical block size (LE, logical extent) , the size of which, in turn, is constant within the volume group.


View LVM view with physical and logical volumes.


A view of LVM with physical and logical blocks, which is the same for the entire volume group.

Example: Let's imagine that we have a volume group VG1 and it has a physical block size of 4 MB. Within the volume group 2 are hard disks / dev / hda1 and / dev / hdb1. These disks will become physical partitions PV1 and PV2. Since the physical block size is 4 mb - the same size will be logical blocks. The disks have a different size and the first includes 99 blocks, and the second 248 blocks. Now we will create a logical volume. It can be any size between 1 and 347 blocks (248 + 99 blocks). When a logical volume is created, a connection is established between the logical and physical blocks, for example, logical block 1 can be connected to physical block 51 of PV1, and the data written to the first 4 megabytes of the logical volume will actually be written to 51y block PV1.

There are 2 types of communication between physical and logical blocks:


Nepshots LVM

LVM snapshots allow an administrator to create a new block device that stores a copy of a logical volume frozen at a specific point in time. This feature can be used for batch processing, creating backups or experiments where you do not want to hurt live data on the system.

In LVM2, used in modern versions of Linux, snapshots are available for reading and writing by default. When creating a snapshot, an exception table is created, which is used to save information about which block has been changed. If a block is changed on the source volume from which the snapshot was created, it is first copied to the snapshot, marked as copied in the exception table, then the new data is written to the original volume. If data is written to a snapshot, the block is marked as used in the exception table and never copied from the source volume.

Increasing the Linux server partition


Creating a server for testing

If you do not have access to the Azure Pack Infrastructure, fill out an application for a free trial version on the main page https://infoboxcloud.ru .

Create a network with Internet access, a server with Linux (for example, with Ubuntu 16.04) and forward its port 22 to an external ip, as shown in this article . Connect to the server via SSH .

On all servers with Linux in the Azure Pack Infrastructure is already pre-installed LVM.

Creating a checkpoint

Before increasing the disk volume, creating a control point is highly recommended. If something goes wrong, you can restore the server to this state. If there is not enough space in your subscription, email us a ticket in the service control panel > Support Center> Write a ticket.

Click on the name of your server and go to the “Checkpoints” section.


Click the Create button to create a control point.


Specify the name of the control point and, if necessary, the description and click the tick “Done”. A checkpoint will be created. Now you can perform further operations safely.

Increasing disk partition in Azure Pack Infrastructure control panel

Log in to the control panel , select your server on which you want to increase the partition and click the Stop button. Wait for the server to stop.


Now click on the server name and go to the "Configure" section. Click on the name of the disk you want to enlarge.


The "Expand" button will appear - click it.


Specify the desired disk size (only zoom is available) and click the "Finish" checkbox. The size of the virtual disk will be increased. However, this is not enough - it is necessary to increase the LV partition on the virtual machine, read about it below.

Create a new physical partition on disk (PV)

First, on the appeared free space, you need to create a new physical partition (PV), which can then be connected to LVM. To do this, you can use the command:

cfdisk 


Select the free disk space (Free Space, marked in green) using the arrows on the keyboard and then press Enter, which will launch the New command.


The size of the partition being created will be requested. By default - the maximum, for all added space, just press Enter.


Now the arrows on the keyboard with the new section marked, select Type .


Press Enter to select the partition type.


Select type 8e Linux LVM and press Enter.

Now select the item Write and press Enter to save the changes to the disk.


Permission to apply changes will be requested. Type yes and press Enter.


A message will appear indicating that the partition table has changed successfully.


Remember the device path, in this case / dev / sda3 . The device path will be required later when adding a partition to the volume group (VG).

To exit the partitioning program, select Quit and press Enter.



Reboot the server with the command:

 reboot 

and connect to it over ssh again.

Add the created physical partition to the volume group (VG)

To find out the name of the created volume group, use the command:

 vgdisplay 



where in the VG name parameter will be the name of the volume group, in this case - ubuntu-vg .

To add a physical partition to a volume group, use the command:

 vgextend ubuntu-vg /dev/sda3 

where ubuntu-vg is the name of the volume group, and / dev / sda3 is the path to the device to the new partition.



Using the command:

 pvdisplay 

You can see the list of disks connected to the volume group.


Increase the size of the logical partition LVM root and file system partition to the maximum available

Using the command

 lvdisplay 

You can see the list of LVM logical partitions.


We see that 2 partitions are created: / dev / ubuntu-vg / swap_1 and / dev / ubuntu-vg / root . Using the command:

 vgdisplay 

We see the parameters of the volume group.


We see that now available space for the expansion of volumes LVM (Free PE / Size) in the amount of 75 GB.

We need to increase the partition / dev / ubuntu-vg / root to the maximum available, and at the same time increase the size of the file system.

To do this, run the command:

 lvextend -r -l +100%FREE /dev/ubuntu-vg/root 


Now run the command:

 df -h 

in order to see the new size of the system partition.


We successfully added disk space for the Linux – server in the Azure Pack Infrastructure cloud, and at the same time we learned how to use LVM.

If you have any questions about using Azure Pack Infrastructure, we will be happy to help and advise! You can email us through your account https://support.infobox.ru > Support Center> Write a ticket.

If you can not leave comments on Habré, write to us in the InfoboxCloud Community .

Successful work!

Source: https://habr.com/ru/post/313356/


All Articles