LVM
LVM(Logicl Volume Manager),逻辑卷管理器,通过使用逻辑卷管理器对硬盘存储设备进行管理,可以实现硬盘空间的动态划分和调整。
LVM(Logicl Volume Manager),逻辑卷管理器,通过使用逻辑卷管理器对硬盘存储设备进行管理,可以实现硬盘空间的动态划分和调整。
PE(Physical Extent)物理区域 物理区域是物理卷中可用于分配的最小存储单元,物理区域的大小可根据实际情况在建立物理卷时指定。物理区域大小一旦确定将不能更改,同一卷组中 的所有物理卷的物理区域大小需要一致。
LE(Logical Extent)逻辑区域 逻辑区域是逻辑卷中可用于分配的最小存储单元,逻辑区域的大小取决于逻辑卷所在卷组中的物理区域的大小。
pv------>vg------>lv
PV(Physical Volume)物理卷 物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘(也即使为一个硬盘如sdb,sdc,sdd,sde ;也可以为一个硬盘里 面的一个分区如sdb1,sdc1,sdc2)。
PV(Physical Volume)物理卷 物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘(也即使为一个硬盘如sdb,sdc,sdd,sde ;也可以为一个硬盘里 面的一个分区如sdb1,sdc1,sdc2)。
1 对物理磁盘进行分区操作,并把标卷属性设置成8e(假如有4块磁盘,依次进行分区并设置成LVM分区格式)
[root@weblogic-primary ~]# fdisk /dev/sde
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.
[root@weblogic-primary ~]# fdisk /dev/sde
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.
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-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +2048M
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +2048M
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Selected partition 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!
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Syncing disks.
2 创建物理卷
[root@weblogic-primary ~]# pvcreate /dev/sd[bcde]1 --创建4个物理卷
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdd1" successfully created
Physical volume "/dev/sde1" successfully created
[root@weblogic-primary ~]# pvcreate /dev/sd[bcde]1 --创建4个物理卷
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdd1" successfully created
Physical volume "/dev/sde1" successfully created
3 查看物理卷
[root@weblogic-primary ~]# pvs --查看pv的数量
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 -- 1.92G 1.92G
/dev/sdc1 lvm2 -- 1.92G 1.92G
/dev/sdd1 lvm2 -- 1.92G 1.92G
/dev/sde1 lvm2 -- 1.92G 1.92G
[root@weblogic-primary ~]# pvscan
PV /dev/sdb1 lvm2 [1.92 GB]
PV /dev/sdc1 lvm2 [1.92 GB]
PV /dev/sdd1 lvm2 [1.92 GB]
PV /dev/sde1 lvm2 [1.92 GB]
Total: 4 [7.66 GB] / in use: 0 [0 ] / in no VG: 4 [7.66 GB]
[root@weblogic-primary ~]# pvdisplay --查看详细信息
[root@weblogic-primary ~]# pvs --查看pv的数量
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 -- 1.92G 1.92G
/dev/sdc1 lvm2 -- 1.92G 1.92G
/dev/sdd1 lvm2 -- 1.92G 1.92G
/dev/sde1 lvm2 -- 1.92G 1.92G
[root@weblogic-primary ~]# pvscan
PV /dev/sdb1 lvm2 [1.92 GB]
PV /dev/sdc1 lvm2 [1.92 GB]
PV /dev/sdd1 lvm2 [1.92 GB]
PV /dev/sde1 lvm2 [1.92 GB]
Total: 4 [7.66 GB] / in use: 0 [0 ] / in no VG: 4 [7.66 GB]
[root@weblogic-primary ~]# pvdisplay --查看详细信息
4 修改物理卷
VG(Volumne Group)卷组 卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可动态添加物理卷到卷组中
1 创建卷组
[root@weblogic-primary ~]# vgcreate vg_data /dev/sd[bc]1 --创建一个卷组名称为vg_data的卷组,物理卷成员是sdb1和sdc1
1 创建卷组
[root@weblogic-primary ~]# vgcreate vg_data /dev/sd[bc]1 --创建一个卷组名称为vg_data的卷组,物理卷成员是sdb1和sdc1
2 查看眷组
[root@weblogic-primary ~]# vgs --查看VG数量和使用情况
VG #PV #LV #SN Attr VSize VFree
vg_data 2 0 0 wz--n- 3.83G 3.83G
[root@weblogic-primary ~]# vgdisplay --详细列出PV的信息
--- Volume group ---
VG Name vg_data
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.83 GB
PE Size 4.00 MB
Total PE 980
Alloc PE / Size 0 / 0
Free PE / Size 980 / 3.83 GB
VG UUID s261r1-NWLN-jB5f-CgfB-1ebx-zlWS-32uCmE
[root@weblogic-primary ~]# vgs --查看VG数量和使用情况
VG #PV #LV #SN Attr VSize VFree
vg_data 2 0 0 wz--n- 3.83G 3.83G
[root@weblogic-primary ~]# vgdisplay --详细列出PV的信息
--- Volume group ---
VG Name vg_data
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.83 GB
PE Size 4.00 MB
Total PE 980
Alloc PE / Size 0 / 0
Free PE / Size 980 / 3.83 GB
VG UUID s261r1-NWLN-jB5f-CgfB-1ebx-zlWS-32uCmE
3 备份卷组
[root@weblogic-primary ~]# vgcfgbackup -f vg_data_bak vg_data --备份一个名为vg_data的卷组成vg_data_bak到当前目录下
Volume group "vg_data" successfully backed up.
[root@weblogic-primary ~]# vgcfgbackup -f vg_data_bak vg_data --备份一个名为vg_data的卷组成vg_data_bak到当前目录下
Volume group "vg_data" successfully backed up.
4 恢复备份的卷组
[root@weblogic-primary ~]# vgcfgrestore -f vg_data_bak vg_data --恢复一个名为vg_data_bak的VG备份到当前名为vg_data
/dev/cdrom: open failed: Read-only file system
Restored volume group vg_data
[root@weblogic-primary ~]# vgcfgrestore -f vg_data_bak vg_data --恢复一个名为vg_data_bak的VG备份到当前名为vg_data
/dev/cdrom: open failed: Read-only file system
Restored volume group vg_data
5 激活当前恢复的卷组
[root@weblogic-primary ~]# vgchange -ay --激活所有的卷组
0 logical volume(s) in volume group "vg_data" now active
[root@weblogic-primary ~]# vgchange -ay --激活所有的卷组
0 logical volume(s) in volume group "vg_data" now active
6 添加lv到卷组vg_data中
a 对物理磁盘进行分区操作,并
[root@weblogic-primary ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (251-522, default 251):
Using default value 251
Last cylinder or +size or +sizeM or +sizeK (251-522, default 522): +2048M
[root@weblogic-primary ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (251-522, default 251):
Using default value 251
Last cylinder or +size or +sizeM or +sizeK (251-522, default 522): +2048M
Command (m for help): w
The partition table has been altered!
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
b 把标卷属性设置成8e
[root@weblogic-primary ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 1044.
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)
Syncing disks.
b 把标卷属性设置成8e
[root@weblogic-primary ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 1044.
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): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Syncing disks.
c 创建物理卷
[root@weblogic-primary ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@weblogic-primary ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
d 添加物理卷到卷组
[root@weblogic-primary ~]# vgextend vg_data /dev/sdb2
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "vg_data" successfully extended
e 查看卷组情况
[root@weblogic-primary ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg_data lvm2 a- 1.91G 1.91G
/dev/sdb2 vg_data lvm2 a- 1.91G 1.91G
/dev/sdc1 vg_data lvm2 a- 1.91G 1.91G
/dev/sdd1 lvm2 -- 1.92G 1.92G
/dev/sde1 lvm2 -- 1.92G 1.92G
[root@weblogic-primary ~]# vgextend vg_data /dev/sdb2
/dev/cdrom: open failed: Read-only file system
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "vg_data" successfully extended
e 查看卷组情况
[root@weblogic-primary ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg_data lvm2 a- 1.91G 1.91G
/dev/sdb2 vg_data lvm2 a- 1.91G 1.91G
/dev/sdc1 vg_data lvm2 a- 1.91G 1.91G
/dev/sdd1 lvm2 -- 1.92G 1.92G
/dev/sde1 lvm2 -- 1.92G 1.92G
LV(Logical Volume)逻辑卷 逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立后可以动态地扩展和缩小空间。
系统中的多个逻辑卷可以属于同一个卷组,也可以属于不同的多个卷组。
一个逻辑卷管理系统工程中可以只有一个卷组,也可以拥有多个卷组。
1 创建逻辑卷
[root@weblogic-primary ~]# lvcreate -L 1024M -n lv_archive_3 vg_arc --创建逻辑卷lv_archive_3到卷组vg_arc中(-L表示创建逻辑卷lv_archive_3的大小,-n表示创建逻辑卷的名称 ,vg_arc卷组名称)
[root@weblogic-primary ~]# lvcreate -L 1024M -n lv_archive_3 vg_arc --创建逻辑卷lv_archive_3到卷组vg_arc中(-L表示创建逻辑卷lv_archive_3的大小,-n表示创建逻辑卷的名称 ,vg_arc卷组名称)
2 扩张逻辑卷的容量
a 查看当前的逻辑卷的容量
[root@weblogic-primary ~]# lvscan
ACTIVE '/dev/vg_data/lv_data_1' [1.00 GB] inherit
a 查看当前的逻辑卷的容量
[root@weblogic-primary ~]# lvscan
ACTIVE '/dev/vg_data/lv_data_1' [1.00 GB] inherit
b 增加容量
[root@weblogic-primary ~]# lvextend -L +512M /dev/vg_data/lv_data_1
/dev/cdrom: open failed: Read-only file system
Extending logical volume lv_data_1 to 1.50 GB
Logical volume lv_data_1 successfully resized
[root@weblogic-primary ~]# lvextend -L +512M /dev/vg_data/lv_data_1
/dev/cdrom: open failed: Read-only file system
Extending logical volume lv_data_1 to 1.50 GB
Logical volume lv_data_1 successfully resized
3 查看逻辑卷
[root@weblogic-primary ~]# lvdisplay --查看所有的逻辑卷
[root@weblogic-primary ~]# lvdisplay vg_arc --查看卷组vg_arc有哪些逻辑卷
[root@weblogic-primary ~]# lvscan --查看被激活的所有逻辑卷
4 删除逻辑卷
5 分区格式化
[root@weblogic-primary ~]# mkfs.ext3 /dev/vg_arc/lv_archive_1
[root@weblogic-primary ~]# mkfs -j /dev/vg_arc/lv_archive_2
[root@weblogic-primary ~]# mkfs.ext3 /dev/vg_arc/lv_archive_1
[root@weblogic-primary ~]# mkfs -j /dev/vg_arc/lv_archive_2
6 挂载新分区
[root@weblogic-primary home]# mkdir archive_1
[root@weblogic-primary home]# mkdir archive_2
[root@weblogic-primary home]# mount /dev/vg_arc/lv_archive_1 /home/archive_1
[root@weblogic-primary home]# mount /dev/vg_arc/lv_archive_2 /home/archive_2
[root@weblogic-primary home]# mkdir archive_1
[root@weblogic-primary home]# mkdir archive_2
[root@weblogic-primary home]# mount /dev/vg_arc/lv_archive_1 /home/archive_1
[root@weblogic-primary home]# mount /dev/vg_arc/lv_archive_2 /home/archive_2
7 永久写入启动项
vi /etc/fstab
vi /etc/fstab
8 查看挂载情况
[root@weblogic-primary ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 37G 13G 22G 38% /
/dev/sda1 190M 12M 169M 7% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/mapper/vg_arc-lv_archive_1
1008M 34M 924M 4% /home/archive_1
/dev/mapper/vg_arc-lv_archive_2
516M 17M 474M 4% /home/archive_2
[root@weblogic-primary ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 37G 13G 22G 38% /
/dev/sda1 190M 12M 169M 7% /boot
tmpfs 506M 0 506M 0% /dev/shm
/dev/mapper/vg_arc-lv_archive_1
1008M 34M 924M 4% /home/archive_1
/dev/mapper/vg_arc-lv_archive_2
516M 17M 474M 4% /home/archive_2
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20976446/viewspace-697416/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/20976446/viewspace-697416/