linux 系统基础知识 - 卷管理二

 四、逻辑卷的创建及管理:

1)lvcreate创建逻辑卷命令:
格式1:lvcreate -L 512M -n data vg0
-L 512M:设置逻辑卷的大小为512M.
-n data:设置逻辑卷的名字为data ;表示法:/dev/卷组名/data
vg0 :设置是有那个卷组生成的逻辑卷.
——————————————————————————————————
[root@station1 ~]# lvcreate -L 1000M -n data vg0
Logical volume "data" created
//创建一个容量为1000MB的逻辑卷data
——————————————————————————————————
格式2:lvcreate -l 32 -n data vg0
-l 32:生成的逻辑卷使用32个扩展块,逻辑卷大小=32*PE(默认4M)则为128M
-n data:逻辑卷的名字;
vg0 :设置是有那个卷组生成的逻辑卷.
——————————————————————————————————
[root@station1 ~]# lvcreate -l 32 -n data128 vg0 
Logical volume "data128" created
//创建一个32个扩展块,容量为32*4=128MB的逻辑卷data128
——————————————————————————————————
2)格式化逻辑卷:
mkfs.ext3 /dev/vg0/data mke2fs -j /dev/vg0/data
3)lvsacn查看逻辑卷的信息:
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬——————————————————————————————————
[root@station1 ~]# lvscan
ACTIVE '/dev/vg0/data' [1000.00 MB] inherit
——————————————————————————————————

4)lvdisplay查看逻辑卷的具体参数:
——————————————————————————————————
[root@station1 ~]# lvdisplay /dev/vg0/data
--- Logical volume ---
LV Name /dev/vg0/data
VG Name vg0
LV UUID 9Od1nq-cHmY-MlrL-vgXW-7Kam-pAfU-Qc8mal
LV Write Access read/write
LV Status available
# open 0
LV Size 1000.00 MB
Current LE 250
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
——————————————————————————————————
3)增大逻辑卷大小:
lvextend命令:增大逻辑卷大小
格式:lvextend -L 100M /dev/vg0/data
——————————————————————————————————
[root@station1 ~]# lvextend -L 1000M /dev/vg0/data
Extending logical volume data to 1.95 GB
Logical volume data successfully resized
——————————————————————————————————
resize2fs /dev/vg0/data 使上面增加的立即生效.
——————————————————————————————————
[root@station1 ~]# resize2fs /dev/vg0/data
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg0/data to 512000 (4k) blocks.
The filesystem on /dev/vg0/data is now 512000 blocks long.
[root@station1 ~]# lvscan
ACTIVE '/dev/vg0/data' [1.95 GB] inherit
——————————————————————————————————
4)减少逻辑卷大小:
lvreduce命令:减少逻辑卷大小
格式:Lvreduce -L -100M /dev/vg0/data
——————————————————————————————————
[root@station1 ~]# lvreduce -L -1000M /dev/vg0/data

WARNING: Reducing active logical volume to 1000.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce data? [y/n]: y
Reducing logical volume data to 1000.00 MB
Logical volume data successfully resized
——————————————————————————————————
resize2fs /dev/vg0/data 使上面增加的立即生效.
——————————————————————————————————
[root@station1 ~]# resize2fs /dev/vg0/data
resize2fs 1.39 (29-May-2006)
resize2fs: Bad magic number in super-block while trying to open /dev/vg0/data
Couldn't find valid filesystem superblock.
[root@station1 ~]# lvscan
ACTIVE '/dev/vg0/data' [1000.00 MB] inherit
ACTIVE '/dev/vg0/data128' [128.00 MB] inherit
——————————————————————————————————
5)lvremove删除逻辑卷:
格式:lvremove /dev/卷组名/逻辑卷名
——————————————————————————————————
[root@station1 ~]# lvremove /dev/vg0/data128
Do you really want to remove active logical volume "data128"? [y/n]: y
Logical volume "data128" successfully removed
[root@station1 ~]# lvscan
ACTIVE '/dev/vg0/data' [1000.00 MB] inherit
——————————————————————————————————
五、LVM的快照:
1)快照的创建:
Lvcreate -l 64 -s -n databackup /dev/vg0/data
-l 64:之前我们已经说过了这里是 64个扩展块,总容量=64*单扩展块大小
-n databackup:生成的快照的名字.
/dev/vg0/data:源逻辑卷名字.
————————————————————————————————————
[root@station1 ~]# lvscan
ACTIVE '/dev/vg0/data' [1000.00 MB] inherit

[root@station1 ~]# lvcreate -L 1000M -s -n databackup /dev/vg0/data
Logical volume "databackup" created
[root@station1 ~]# lvscan
ACTIVE Original '/dev/vg0/data' [1000.00 MB] inherit
ACTIVE Snapshot '/dev/vg0/databackup' [1000.00 MB] inherit
————————————————————————————————————
2)快照的删除:
lvremove /dev/vg0/databackup
————————————————————————————————————
[root@station1 ~]# lvremove /dev/vg0/databackup
Do you really want to remove active logical volume "databackup"? [y/n]: y
Logical volume "databackup" successfully removed
————————————————————————————————————
六、总结:
创建逻辑卷的顺序:Linux分区---物理卷---卷组---逻辑卷
删除逻辑卷的顺序:逻辑卷---卷组----物理卷---Linux分区

你可能感兴趣的:(卷管理)