Linux LVM management and creation steps

Reprinted from https://blog.csdn.net/alone_map/article/details/51850381

LVM: Logical partition management, which can reduce the space used by hardware devices based on dynamic expansion.

Concepts: pv, VG, lv
pv (physical volume, composed of pp basic units): physical disk
VG (volume group, composed of pv basic units): a collection of one or more physical disks (capacity)
lv (logical volume, composed of lp basic unit composition): the used partition (space) divided under VG
fs: file system An attribute device file of the file system hardware device
: hardware file, such as a hard disk, a U disk, a (hard disk) partition, etc. When you format them, you choose to format them into that file system attribute (fat32, NTFS, etc. in windows, ext2, ext3, etc. in linux, jfs, jfs2, etc. in unix) Linux is to directly convert hardware devices The file is displayed under dev, and it can be used by mounting it to a certain place (a directory), that is, assigning the hardware device (such as the capacity of a disk or a partition of the disk) to one or more directories for use. The directory under the / partition is due to the directory structure of linux and unix, and has no direct relationship with the hierarchical relationship. For example, if you have 2 fast SCSI hard disks, it is sda under dev (the main partition is sda1-sda3, and the expansion partition at the beginning of sda5, sda4 is a collection of extended partitions such as sda5, sda6, etc., similar to windows) and sdb (same as sda partition). You allocate (mount) the space of sda to the / directory, and allocate (mount) the space of sdb to / oracle (oracle directory under the / directory) This directory, although the directory structure of oracle is /oracle, in the "/" directory, but the space is indeed the sdb space and the sda ​​space used by the "/" directory. Affects the "/" directory. In turn, "/" is broken and does not affect the /oracle directory. LVM management is based on Unix and is commonly used on IBM's small computer AIX. Can dynamically manage hardware device space
 


 

The whole idea: In a Unix or Linux system, there is a hardware device called PV, and the PV space is collected in one to form a VG, and multiple lv partitions are divided in the VG (like C, D, and C in Windows). E and other partitions) are mounted to multiple directories for use (lv and directories are in a one-to-one correspondence), and the capacity of these lvs can be dynamically adjusted in the VG. As long as there is space in the vg, all the lvs under the vg can be used. Expand the capacity at will until the capacity of the vg is full, and the capacity of the vg is full. You can add pv to the vg to increase the capacity of the vg. In
Unix: df -g is used to view lv
In linux: df -h is used to view lv Steps: 1 .Create pv—2. Create vg—3. Add pv to vg—4. Create lv in vg—5. Format the lv partition—6. Mount the lv partition to a directory using Create PV  [root@z1 ~]# pvcreate /dev/sdb1 Create pv /dev/sdb1 Make the first primary partition of the second SCSI hard disk into pv [root@z1~]# pvcreate /dev/sdc1 . . . Make the first primary partition of the third hard disk of SCSI into pv (the linux operating system should be in the first hard disk) View PV [root@z1~]# pvdisplay Create volume group VG [root@z1~]# vgcreate datavg /dev/sdb1 /dev/sdc1 Create a volume group named datavg, add two PVs /dev/sdb1 and /dev/sdc1 to this volume group to view VG [root@z1~]#vgdisplayCreate logical volume LV
 

 










[root@z1~]# lvcreate –L 40G –n lv1 datavg   在datavg中创建一个大小40G,名为lv1的逻辑卷
查看LV
[root@z1~]# lvdisplay
LV格式化成ext3文件格式
[root@z1~]# mkfs .ext3 /dev/datavg/lv1       将lv1格式化成ext3文件系统类型
[root@z1~]# partprobe                        在不重新启动机器的情况下系统能够识别这些分区
 
创建目录
[root@z1~]# mkdir /oracle
挂载
[root@z1~]# mount /dev/datavg/lv1  /oracle       将lv1挂载到/oralce目录
 
查看容量 Ls –lh
 
对挂载的逻辑卷进行扩容
[root@z1~]# lvextend –L +50M /dev/rootvg/lv1     将lv扩容50M(datavg有50M空间的前提下) 
查看分区使用情况 [root@z1~]# df –h
查看磁盘使用情况 fdisk -l
 
对lv1进行在线(动态)扩容
[root@z1~]#resize2fs /dev/datavg/lv1         
#resize2fs是ext2文件系统大小的调整工具,ext3只是多了journal的ext2,也可以用。
 
对为挂载的逻辑卷进行扩容
[root@z1~]#lvextend –L +70M /dev/datavg/lv1       给lv1增加70M(70从datavg中来) 
[root@z1~]#e2fsck –f /dev/datavg/lv1              强制检查ext2、ext3、ext4等文件系统的正确性(清理磁盘碎片,让数据不分散,这个在缩小LV的时候至关重要)
[root@z1~]#lvdipaly
  
对VG进行扩容(一) 
[root@z1~]# pvcreate /dev/sdb2                     创建pv /dev/sdb2
[root@z1~]# vgextend datavg /dev/sdb2              将/dev/sdb2这个pv加入卷组datavg
对VG进行扩容(二)
[root@z1~]# pvcreate /dev/sdb2                     创建pv /dev/sdb2
[root@z1~]# pvcreate /dev/sdc3                     创建pv /dev/sdb3
[root@z1~]# vgcreate datavg /dev/sdb2              创建datavg(里面是/dev/sdb2)
[root@z1~]# vgcreate rootvg /dev/sdc3              创建rootvg(里面是/dev/sdb3)
[root@z1~]# vgmerge rootvg datavg                  将rootvg与datavg整合到rootvg
  卸载卷的方法:
  卸载物理卷:pvremove PVDEVICE
  卸载卷组:vgremove VGNAME
  卸载逻辑卷:lvremove LVDEVICE
  卸载的顺序:先逻辑—卷组—物理卷
  卸载前别忘了备份

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325988819&siteId=291194637