Examples of commonly used commands for volume management and logical volume expansion methods

This article explains the related operations of volume management, mainly including: volume creation, volume expansion, volume view and other common commands, as well as how to expand the size of a logical volume in a practical case.


Logical volume creation process

First use the fdisk command to create a physical partition sdbx from the sdb disk (this step is omitted, see the example below), assuming there are sdb1 and sdb2, merge the two partitions into a logical volume.

  1. pvcreate /dev/sdb1 /dev/sdb2 creates a physical volume (or pvcreate /dev/sdb{1,2})
  2. vgcreate vg1 /dev/sdb1 /dev/sdb2 Create volume group
  3. lvcreate -n lv_name -L 15G vg1 creates a logical volume
    (if lvcreate -n lv_name -L 15G vg1 /dev/sdb2 specifies the use of sdb2)
  4. mkfs.ext4 /dev/vg1/lv_name Format the logical volume file system as ext4
  5. mount /dev/vg1/lv_name /mnt (mount /dev/[volume group name]/[logical volume name] /mnt/)

Volume view

  • lvscan or lvdisplay to view the logical volume (the logical volume path is usually: /dev/[volume group name]/[logical volume name])
  • vgdisplay or vgscan view volume group
  • pvdisplay or pvscan to view the created physical volume
  • pvs View the current system logical volume group and physical, logical relationship and capacity

Volume deletion

  • lvremove /dev/…
  • Vgremove /dev/…
  • Pvremove /dev/…

Basic steps and actual cases of volume expansion

  1. pvcreate /dev/sda3 creates the physical volume to be expanded
  2. vgextend vg1 /dev/sda3 increase to volume group capacity
  3. lvextend -L +10G /dev/vg1/lv_name Extend the logical volume size 10G
  4. Reloading the size of the logical volume takes effect
    resize2fs + path (note: xfs file system is not applicable)
    xfs_growfs + mount path (note: used by xfs file system)

This article takes a virtual machine as an example: explain how to expand the size of the root partition of a hard disk.

Case study

The following is the situation of the root partition of my virtual machine. The root partition has been used up, but I don’t see it, it’s 100%. The root partition is under the logical volume. I can expand the logical volume to increase the space of the root partition.
Insert picture description here

1. First, create and add a hard disk in the virtual machine. As follows, in the process, just click the next step, and choose the size of the hard disk to be created in the middle.
Insert picture description here
The 30G hard disk is created, let’s enter the system and have a look

lsblk
lsscsi
fdisk
这些命令都可以查看

Insert picture description here

Let's start the logical volume expansion operation:

2. First check the information of the logical volume to be expanded (lvdisplay): the volume group name is cl, and the logical volume name is root
(windowed: here you can see that there are two logical volumes in a volume group, and the other is not us Concerned)

lvdisplay

Insert picture description here

You can also see the basic information of the volume group where the logical volume is located under the dev path ( /dev/[volume group]/[volume name] )
Insert picture description here

3. Start another knowledge point: fdisk command to create a physical partition, do as follows (finally save with w), here only create a partition sdb1 for sdb
(if you don’t understand, you can get help through m)
Insert picture description here

You can see that it is created. Insert picture description here
4. Add /dev/sdb1 to the volume group (cl) capacity, and execute the following command.

vgextend cl  /dev/sdb1

Insert picture description here
Note that it may fail as follows, because the root partition is full and some large files need to be deleted to expand
Insert picture description here

5. Expand root's logical volume size by 25G (expanded by 25G, 30G will fail, the size difference will be lost)

lvextend -L +25G /dev/cl/root  

Insert picture description here

Check the volume group, the previous size has been expanded
Insert picture description here

But the actual partition size under df has not changed.
Insert picture description here
6. The logical volume needs to be reloaded.

You can see the partition mount type XFS in mount
Insert picture description here

Execute xfs_growfs / to reload the size of the mounted partition (xfs_growfs is used by the xfs file system, which can be seen in mount)

xfs_growfs /

Insert picture description here

We see the next logical volume group for those physical partitions, respectively sda2 and sdb1 (sdb1 which has been done under cl-root logical volume, this is exactly what we extend out to the root partition)
Insert picture description here
to get


Guess you like

Origin blog.csdn.net/ludaoyi88/article/details/113276170