Linux中的创建LVM-PV-VG-LV

 Linux中的创建PV-VG-LV

操作系统为Linux5.5

   LVM是逻辑盘卷管理(Logical Volume Manager)的简称,他是磁盘管理的另一种工具,就目前基本上所有操作系统均支持,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性。通过LVM系统管理员可以轻松管理磁盘分区,如:将若干个磁盘分区连接为一个整块的卷组(volume group),形成一个存储池。管理员可以在卷组上随意创建逻辑卷组(logical volumes),并进一步在逻辑卷组上创建文件系统。管理员通过LVM可以方便的调整存储卷组的大小,并且可以对磁盘存储按照组的方式进行命名、管理和分配,例如按照使用用途进行定义:“DBdata”和“DBSoft”,而不是使用物理磁盘名“sda”和“sdb”或”hda”和”hdb”。而且当系统添加了新的磁盘,通过LVM管理员就不必将磁盘的文件移动到新的磁盘上以充分利用新的存储空间,而是直接扩展文件系统跨越磁盘即可,架构可以参考如下图:

(1)给/dev/sdb分区,分成两个区

[root@ENMOEDU ~]# fdisk -l

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

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory   only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-2610, default 1): 

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +3G

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (367-2610, default 367): 

Using default value 367

Last cylinder or +size or +sizeM or +sizeK (367-2610, default 2610): 

Using default value 2610

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@ENMOEDU ~]# fdisk -l

/dev/sdb1               1         366     2939863+  83  Linux

/dev/sdb2             367        2610    18024930   83  Linux

(2)将/dev/sdb1设置成LVM;

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

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): t

Partition number (1-4): 1

          

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

Changed system type of partition 1 to 8e (Linux LVM)

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

(3)创建物理卷PV

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

(4)创建VG存储池

[root@ENMOEDU ~]# vgcreate VolGroup01  /dev/sdb1

[root@ENMOEDU ~]# vgdisplay

  --- Volume group ---

  VG Name               VolGroup01

  System ID             

  Format                lvm2

  Metadata Areas        1

  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                1

  Act PV                1

  VG Size               2.80 GB

  PE Size               4.00 MB

  Total PE              717

  Alloc PE / Size       0 / 0   

  Free  PE / Size       717 / 2.80 GB

  VG UUID               fhg0w0-2J1E-tduQ-r6HR-OCiQ-Jkkx-egbcq0

 

(5)增大VG存储池
[root@ENMOEDU ~]#vgextend VolGroup01 /dev/adb2

(6)分配LV逻辑卷

[root@ENMOEDU ~]# lvcreate -L 500M -n LogVol07 VolGroup01 (-n 命名name)

  Logical volume "LogVol07" created

[root@ENMOEDU ~]# lvdisplay

  --- Logical volume ---

  LV Name                /dev/VolGroup01/LogVol07

  VG Name                VolGroup01

  LV UUID                UAKz2h-jhTv-8oF0-R71E-NhSB-jFfp-wdvqnl

  LV Write Access        read/write

  LV Status              available

  # open                 0

  LV Size                500.00 MB

  Current LE             125

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:7

(7)格式化分区

[root@ENMOEDU ~]# mkfs.ext3 /dev/VolGroup01/LogVol07

(8)添加/u02挂载点

[root@ENMOEDU ~]# mkdir /u02

[root@ENMOEDU ~]# vi /etc/fstab

/*添加下面的命令*/

/dev/VolGroup01/LogVol07 /u02           ext3    defaults        1 2

[root@ENMOEDU ~]# mount -a

[root@ENMOEDU ~]# mount

 

(9)删除LV中的/dev/mapper/VolGroup01-LogVol07

Umount对象;

[root@ENMOEDU ~]# umount /u02

删除对象LV;

[root@ENMOEDU ~]# lvremove /dev/mapper/VolGroup01-LogVol07

Do you really want to remove active logical volume LogVol07?[y/n]

: y

  Logical volume "LogVol07" successfully removed

查看删除成功;

[root@ENMOEDU ~]# lvdisplay

总结:通过梳理可知,首先会把磁盘或者硬盘分区,把其中一个区设置成LVM逻辑盘卷管理,也就是设计成逻辑盘,在LVM上创建PV物理卷,在PV上创建VG卷组,也就是存储池,在VG上创建LV,分配逻辑卷组,获取需要的存储资源,LV分区创建完毕,接着就是格式化,添加挂载点,可以把LV挂载到自己实际操作的目录下。

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值