linux : LV--PV--VG 创建

时间:2022-05-21 08:21:32

先看一下文档:

创建PV
[root@z1~]# pvcreate /dev/sdb1
[root@z1~]# pvcreate /dev/sdc1

查看PV [root@z1~]# pvdisplay

创建卷组VG
[root@z1~]# vgcreate myvg1 /dev/sdb1  /dev/sdc1

查看VG
[root@z1~]#vgdisplay

创建逻辑卷LV
[root@z1~]# lvcreate –l 40 –n mylv1 myvg1

查看LV

[root@z1~]# lvdisplay

LV格式化成ext3文件格式

[root@z1~]# mkfs.ext3 /dev/myvg1/mylv1
创建目录 [

root@z1~]# mkdir /mylv1mut
挂载
[root@z1~]# mount /dev/myvg1/mylv1  /mylv1mnt

对挂载的逻辑卷进行扩容
Ls –lh

查看容量

[root@z1~]# lvextend –L +50M /dev/myvg1/mylv1

 查看分区使用情况
 
 [root@z1~]# df –h
 
 对mylv1进行在线扩容
 
[root@z1~]# resize2fs /dev/myvg1/mylv1

对为挂载的逻辑卷进行扩容

[root@z1~]# lvextend –L +70M /dev/myvg1/mylv2

[root@z1~]# mount /dev/myvg1/mylv2 /mylv2mnt

 [root@z1~]# umount /mylv2mnt
 
 [root@z1~]# resize2fs /dev/myvg1/mylv2
 
 [root@z1~]# e2fsck –f /dev/myvg1/mylv2 (注意在mount 状态下fsck 会破坏文件系统)
 
 [root@z1~]# resize2fs /dev/myvg1/mylv2
 
 [root@z1~]# mount /dev/myvg1/mylv2  /mylv2mnt/
 
 [root@z1~]# df –h
 
 对VG进行扩容(一)
  [root@z1~]# partprobe
  [root@z1~]# pvcreate /dev/sdb2
  [root@z1~]# vgextend myvg1 /dev/sdb2
 
  对VG进行扩容(二)
 
  [root@z1~]# pvcreate /dev/sdb3
  [root@z1~]# pvcreate /dev/sdc2
[root@z1~]# vgcreate /dev/sdb3  /dev/sdc2

[root@z1~]# vgmerge myvg1 myvg2 

-------

 

下面开始操作:

关于在disk 上见pv,pg 的操作实践:

Step1:
现在 虚拟机关机的情况下增加两块 scsi 盘。

Step2; 建pv:

[root@aoracle ~]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created
[root@aoracle ~]# pvcreate /dev/sde
  Physical volume "/dev/sde" successfully created
 
好,下面查看一下:

[root@aoracle ~]# pvdisplay
  /dev/cdrom: open failed: No medium found
  "/dev/sdd" is a new physical volume of "2.00 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd
  VG Name              
  PV Size               2.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               b3d2fB-QeQQ-05UV-KLAF-2AB4-Gpfw-5kbsOu
  
  "/dev/sde" is a new physical volume of "2.00 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sde
  VG Name              
  PV Size               2.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               r0pBoP-a6rC-CGsb-UEZR-3bXN-fwj3-wsK2GA
 
Step3: 创建卷组vg: 并且查看:

[root@aoracle ~]# vgcreate myvg1 /dev/sdd /dev/sde
  Volume group "myvg1" successfully created
[root@aoracle ~]# vgdisplay
  --- Volume group ---
  VG Name               myvg1
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               3.99 GB
  PE Size               4.00 MB
  Total PE              1022
  Alloc PE / Size       0 / 0  
  Free  PE / Size       1022 / 3.99 GB
  VG UUID               Y4wahX-Q3IW-iagV-S2o0-x0b9-sOzW-AXu1u4

Step4:
创建 逻辑卷:

[root@aoracle ~]# lvcreate -l 40 -n mylv1 myvg1
  Logical volume "mylv1" created
[root@aoracle ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/myvg1/mylv1
  VG Name                myvg1
  LV UUID                k0rYqH-yZFf-BzOl-BtEc-30Z8-Q98S-G2Gz0i
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                160.00 MB
  Current LE             40
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
[root@aoracle ~]#

可以lvcreate --help 看到每个参数的意思:

lvcreate -s|--snapshot
        [-c|--chunksize]
        [-A|--autobackup {y|n}]
        [--addtag Tag]
        [--alloc AllocationPolicy]
        [-C|--contiguous {y|n}]
        [-d|--debug]
        [-h|-?|--help]
        [-i|--stripes Stripes [-I|--stripesize StripeSize]]
        {-l|--extents LogicalExtentsNumber[%{VG|LV|PVS|FREE}] |
         -L|--size LogicalVolumeSize[kKmMgGtTpPeE]}
        [-M|--persistent {y|n}] [--major major] [--minor minor]
        [-n|--name LogicalVolumeName]
        [-p|--permission {r|rw}]
        [-r|--readahead ReadAheadSectors|auto|none]
        [-t|--test]
        [-v|--verbose]
        [--version]
       
看上方的40*40 = 160 M size.

Step5:
 下面格式化成 ext3 的格式:

root@aoracle ~]# mkfs.ext3 /dev/myvg1/mylv1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
40960 inodes, 163840 blocks
8192 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
20 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@aoracle ~]#

Step6:

创建目录:
mkdir /IBM


mount;

[root@aoracle IBM]# mount /dev/myvg1/mylv1 /IBM

[root@aoracle IBM]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             16246460  10968556   4439312  72% /
tmpfs                   265656         0    265656   0% /dev/shm
/dev/sdb              15481840   3070332  11625076  21% /u01
/dev/sdc1             10317828   2659212   7134500  28% /u02
/dev/mapper/myvg1-mylv1
                        158667      5664    144811   4% /IBM

 ---------

 

下面进行 对文件系统的扩充:

1: extend the LV:

root@aoracle /]# lvextend -L +40M /dev/myvg1/mylv1
  Extending logical volume mylv1 to 200.00 MB
  Logical volume mylv1 successfully resized
[root@aoracle /]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             16246460   4242504  11165364  28% /
tmpfs                   265656         0    265656   0% /dev/shm
/dev/sdb              15481840   3070256  11625152  21% /u01
/dev/sdc1             10317828   2659212   7134500  28% /u02
/dev/mapper/myvg1-mylv1
                        158667      5664    144811   4% /IBM

 

发现文件系统 并没有变大,

umount 后进行 扩充:

[root@aoracle /]# umount /IBM

[root@aoracle /]# resize2fs /dev/myvg1/mylv1
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/myvg1/mylv1' first.

[root@aoracle /]# e2fsck -f /dev/myvg1/mylv1
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/myvg1/mylv1: 11/40960 files (9.1% non-contiguous), 10837/163840 blocks
[root@aoracle /]# resize2fs /dev/myvg1/mylv1
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/myvg1/mylv1 to 204800 (1k) blocks.
The filesystem on /dev/myvg1/mylv1 is now 204800 blocks long.


[root@aoracle /]# mount /dev/myvg1/mylv1 /IBM
[root@aoracle /]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             16246460   4242504  11165364  28% /
tmpfs                   265656         0    265656   0% /dev/shm
/dev/sdb              15481840   3070256  11625152  21% /u01
/dev/sdc1             10317828   2659212   7134500  28% /u02
/dev/mapper/myvg1-mylv1
                        198337      5664    182433   4% /IBM

扩充成功。