Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Knowledge summary and operation instructions of LVM logical volume management

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Steps for lvm

1: create a disk or partition as a pv physical volume

2: create a volume group vg, add pv to the existing volume group vg or add pv to the newly created volume group

3: create a lv and allocate space in the volume group vg, or extend the space to the existing lv in vg:

4: the newly created lv must be formatted before the path can be mounted. If you already have a lv and have already mounted the path, you do not need to format it after expanding the space.

Important knowledge points

1. The server expands the space to the disk, but the expanded space does not automatically expand on the partition / dev/sdb1 that has already been divided, but only extends / dev/sdb. At this time, you need to recreate the partition / dev/sdb2 to use the extended disk, and add / dev/sdb2 to the corresponding lv of / dev/sdb1.

2. If the disk partition is created as a pv physical volume, the disk partition type must be linux lvm, that is, the partition format must be changed from linux to linux lvm through 8e. There is no such requirement for disk creation as a pv physical volume.

3. Partprobe can refresh the changes of the system partition table.

4. If you are adding new space, you should first use pvscan to see which disks or partitions have joined pv, and then use vgscan to see which pv has been used.

5. If you need to expand the lv space and make the expanded space visible to the corresponding mount directory of lv, you must use resize2fs, such as lvextend-L 9G / dev/vg_1/lv_1-- resizefs.

6. Create a new lv and allocate space, which must be less than or equal to the available space seen in the vgdisplay, so the new lv is unused space, which explains why the new lv must be formatted to mount the directory.

Some view commands of LVM: pvscan, pvdisplay, vgscan, vgdisplay, lvscan, lvdisplay

Pv is a physical volume, created by pvcreate / sda/sda1

Vg is a volume group, and the creation method is vgcreate volume group name / sda/sda1

Lv is a logical volume, which is created by lvcreate-n logical volume name-l 2G volume group name

The command to view the disk partition corresponding to the VG of LVM is to add a disk to pvscan and create a new VG.

1. Add a disk / dev/sdb to the server, which cannot be seen with a size of 10g fdisk-l. You can see it after executing the following

[root@FRSPGSQLDEV2 ~] # ls / sys/class/scsi_host/

Host0 host1 host2

[root@FRSPGSQLDEV2 ~] # echo "- -" > / sys/class/scsi_host/host0/scan

[root@FRSPGSQLDEV2 ~] # echo "- -" > / sys/class/scsi_host/host1/scan

[root@FRSPGSQLDEV2 ~] # echo "- -" > / sys/class/scsi_host/host2/scan

2. Divide the disk into LVM partitions. After creating the partition, use 8e to change the partition format from linux to linux lvm.

[root@FRSPGSQLDEV2 ~] # fdisk / dev/sdb

Command (m for help): n

Select (default p): P

Partition number (1-4, default 1):

First sector (2048-20971519, default 2048):

Command (m for help): t

Hex code (type L to list all codes): 8e

Command (m for help): P

Command (m for help): W

3. Create the partition as a physical volume PV

[root@FRSPGSQLDEV2 ~] # pvcreate / dev/sdb1

4. Create the physical volume PV as volume group VG, named vg_1, and there is no directory / dev/vg_1 at this time.

[root@FRSPGSQLDEV2 ~] # vgcreate vg_1 / dev/sdb1

5. Create a lv named lv_1 from the VG named vg_1, and divide the 3GB. After the creation is successful, you can see / dev/vg_1/lv_1. There is no parent directory called / dev/vg_1 before.

[root@FRSPGSQLDEV2] # lvcreate-n lv_1-L 3G vg_1

6. Format the lv and mount the lv to the directory / data

[root@FRSPGSQLDEV2 ~] # mkfs.ext4 / dev/vg_1/lv_1

[root@FRSPGSQLDEV2 ~] # mount / dev/vg_1/lv_1 / data

7. Through vgdisplay and lvdisplay, we can see that vg_1 still has 7G space, lv1 only allocates 3G, and continue to expand lv1 to 9G

[root@FRSPGSQLDEV2] # lvextend-L 9G / dev/vg_1/lv_1

[root@FRSPGSQLDEV2 ~] # resize2fs / dev/vg_1/lv_1

-- if only the first command is executed above, the space in the / data directory will not show the new space. You need to execute resize2fs.

The above two commands can be merged into lvextend-L 9G / dev/vg_1/lv_1-- add space to the resizefs disk and add space to the existing VG.

1. The disk / dev/sdb increases 10g of space to 20g. At this time, the new 10G cannot be appended to / dev/sdb1, and the partition / dev/sdb2 can only be recreated.

[root@FRSPGSQLDEV2 ~] # fdisk / dev/sdb

Command (m for help): n

Select (default p): P

Partition number (2-4, default 2):

First sector (20971520-41943039, default 20971520):

Command (m for help): t

Hex code (type L to list all codes): 8e

Command (m for help): P

Command (m for help): W

Select (default p): P

2. Create the partition as a physical volume PV

[root@FRSPGSQLDEV2 ~] # partprobe

[root@FRSPGSQLDEV2 ~] # pvcreate / dev/sdb2

3. Extend the physical volume PV to the volume group VG named vg_1

[root@FRSPGSQLDEV2 ~] # vgextend vg_1 / dev/sdb2

4. Through vgdisplay and lvdisplay, we can see that vg_1 still has 11G space, lv1 only allocates 9G, and continue to expand lv1 to 19G.

[root@FRSPGSQLDEV2] # lvextend-L 19G / dev/vg_1/lv_1-- resizefs

Add a new disk, add space to the existing VG, and create a new lv

1. Add a disk / dev/sdc with a space of 10g to create a physical volume

[root@FRSPGSQLDEV2 ~] # pvcreate / dev/sdc

2. Extend the physical volume PV to the volume group VG named vg_1

[root@FRSPGSQLDEV2 ~] # vgextend vg_1 / dev/sdc

3. Through vgdisplay and lvdisplay, we can see that vg_1 still has 11G space, lv1 only allocates 19G, and further expand lv1 to 25G, so that vg_1 only has 5G left.

[root@FRSPGSQLDEV2] # lvextend-L 25G / dev/vg_1/lv_1-- resizefs

4. The remaining 5G of vg_1 continues to create a new lv2.

[root@FRSPGSQLDEV2] # lvcreate-n lv_2-L 3G vg_1

5. Format the lv2 and mount the lv to the directory / data2

[root@FRSPGSQLDEV2 ~] # mkfs.ext4 / dev/vg_1/lv_2

[root@FRSPGSQLDEV2 ~] # mount / dev/vg_1/lv_2 / data2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report