Linux LVM logical volume does not occupy the full disk partition [Expand LVM logical volume]

In the past, install linux according to the traditional partition method, choose custom, you can divide the disk into sda1, sda2...

These are called partitions in linux, partition, and then mount /, /home, /varetc. to each partition

But with the promotion of LVM technology, if you install ubuntu with the default method of formatting the entire disk, after the installation is complete, you will find that the disk space is not full. The original disk with more than 500 G now only takes up more than 200 /G. . A large part of the reason for this consequence is that the original system was reinstalled. (Not sure, at least that's how I experienced it)

As shown below:

df -h

insert image description here

lsblk

insert image description here
As shown in the figure above, you can see lsblkthat the actual disk space (physical) is more than 446G, but only 200G is mounted.

let's use again

fdisk -l

Check the partition. This command prints a lot, including various messy partitions. Find the sda ​​block as shown below:

insert image description here
We found that there is nothing wrong with the original partition. Note that sda1, 2, and 3 are partitions, which are equivalent to disks c, d, and e under Windows. After calculation, we found that sda1, 2, and 3 in the figure do correspond to the real hard disk capacity, that is, There is nothing wrong with the hard disk, and it was indeed completely read by ubuntu.

Then the problem can be narrowed down, and it is determined that there are fewer mounts. So, why are there fewer mounts? (Note that the mount is based on the partition, on the upper layer of the partition)

It turns out that it is not directly mounted on the physical partition, but mounted /on the logical partition LVM file system, and what is shown here /dev/mapper/ubuntu--vg-ubuntu--lvis a logical partition file (the logical partition exists in the form of a file)! It itself is only 200G, so of course the most mounted on it /is 200G.

To expand, /we expand this LVM file. It is very simple. Execute the following command to let it occupy the remaining space of the disk, and dry our disk!

sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

If you don't want to fry dry:

sudo lvextend -L 50G /dev/mapper/ubuntu--vg-ubuntu--lv

The above expansion is 50G. Of course, the expansion size cannot be greater than the actual remaining size of the disk.

How to view the difference between LVM and actual disk size, use the following command:

lvdisplay

The display is as shown in the figure:
insert image description here
here you can see the logical disk information, but not the physical one, you can use the following command to see it:

vgdisplay

insert image description here
It shows 246G for Free and 200G for alloc! Finally found the source of the confusion, no wonder I used a disk size smaller than my actual disk size, it turned out to be LVM.

Finally, we found that after the expansion, the above command still shows 200G alloc, because there is no recalculation! Also enter the following command to recalculate:

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Now enter again vgdisplay, the capacity is full, and you're done!

Thanks:

https://blog.csdn.net/qq_40137850/article/details/110630758

Guess you like

Origin blog.csdn.net/u014466109/article/details/111591521