Skip to main content

Изменения размера раздела

Complete Steps and Explanation

ssh to server, sudo -i to become root

Confirm there is a limited amount of disk space. In the output below, note the / (root) volume only has 3.9 GB disk space:

Next confirm in Linux that there is actually a lot more space available. As you will see from the output below, there is 24G on the /dev/sda3 volume. The other 1GB is used in the boot volume and the BIOS boot

The one set of instructions referred to starting this process using parted, so parted log is below. The instructions as per Stack read something like:

“First you need to run parted and use its resizepart command to expand the partition to use the whole disk, then run pvresize to tell LVM about the new space, then run lvresize to grow the logical volume, and finally resize2fs on the logical volume to grow the filesystem to use the new space. This can be done without a reboot.”

Please note however I diverted slightly from these steps. The first command I learnt / used in parted, was just used to print the partition information:

This was followed by me checking and re-checking information using fdisk and df -h to make sure I was understanding the current situation.

Then I finally started the procedure:

At this point I tried using lvresize but couldn’t get it to work. It appears there is both lvresize and lvextend. As per the “microhowto.info” article:

“The difference is that lvextend can only increase the size of a volume, whereas lvresize can increase or reduce it.”

The first attempt at specifying 24GB did not work. After I completed the procedure I found that you can also specify a flag 100%, but unfortunately, I didn’t get that information in time and just ended up specifying 23GB. If I have the time I might try and use the 100% flag. For reference, the flag is lvextend -l +100%FREE /dev/VGNAME/LVNAME

Below first attempt but insufficient space:

Second attempt reducing space to allocate:

After lvextend, one has to use resize2fs. This was kind of scary because it appeared I was going to work on a live disk, but it went quick.

TADA! The disk is now 23G big as seen by df-h output below:

И еще 

В Centos 7 файловая система по умолчанию- xfs .

поддержка файловой системы xfs только расширяется, а не уменьшается. Поэтому, если вы хотите изменить размер файловой системы, используйте xfs_growfs, а не resize2fs.

Примечание: Для использования файловой системы ext4