您的位置:首页 > 运维架构 > Linux

linux——(5)redhat逻辑卷管理(LVM)

2015-01-06 15:12 573 查看
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
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: