Linux的LVM管理(三)–其它命令

At 2010-12-15

转载请注明文章转载自:Dbabc.Net [http://dbabc.net]
本文链接:http://dbabc.net/archives/2010/12/15/othe.shtml

上接Linux的LVM管理(二)-在线扩容(On-line Extend),/dev/sdg未使用的状态

1、先将/dev/sdg划分为一个vg来做测试

以sdg为例,先将sdg划分为三个分区,做pv,此处只写操作信息。

[root@dbabc.net /]# fdisk  /dev/sdg
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-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 100
Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (101-261, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-261, default 261): 200
Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (201-261, default 201):
Using default value 201
Last cylinder or +size or +sizeM or +sizeK (201-261, default 261):
Using default value 261
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

此时用fdisk查看多出来三个device

[root@dbabc.net /]# fdisk -l
Device Boot         Start         End      Blocks   Id  System
/dev/sdg1               1         100      803218+  83  Linux
/dev/sdg2             101         200      803250   83  Linux
/dev/sdg3             201         261      489982+  83  Linux

将sdg的三个分区依次做PV、VG、LV

[root@dbabc.net /]# pvcreate /dev/sdg1 /dev/sdg2 /dev/sdg3
Physical volume "/dev/sdg1" successfully created
Physical volume "/dev/sdg2" successfully created
Physical volume "/dev/sdg3" successfully created
[root@dbabc.net /]# vgcreate /dev/vg02 /dev/sdg1 /dev/sdg2 /dev/sdg3
Volume group "vg02" successfully created
[root@dbabc.net /]# lvcreate -L 1024 vg02
Logical volume "lvol0" created
[root@dbabc.net /]# lvcreate -L 1000 vg02
Logical volume "lvol1" created

再格式化,mount,也可以完成lv的创建。

2、vgremove、lvremove命令:删除vg或lv。删除的时候,lv不能在挂载状态
[root@dbabc.net /]# vgremove vg02
Do you really want to remove volume group "vg02" containing 2 logical volumes? [y/n]: y
Can't remove open logical volume "lvol0"

提示不能删除正在使用的lv,那么就删除这个lv

[root@dbabc.net /]# lvremove /dev/vg02/lvol0
Can't remove open logical volume "lvol0"

仍然提示不能删除,卸载掉挂载的目录

[root@dbabc.net /]# umount /dev/vg02/lvol0
[root@dbabc.net /]# lvremove /dev/vg02/lvol0
Do you really want to remove active logical volume lvol0? [y/n]: y
Logical volume "lvol0" successfully removed
[root@dbabc.net /]# lvremove /dev/vg02/lvol1
Do you really want to remove active logical volume lvol1? [y/n]: y
  Logical volume "lvol1" successfully removed
[root@dbabc.net /]#vgremove /dev/vg02
Volume group "vg02" successfully removed

卸载掉挂载的目录后,也可以直接卸载pv,提示警告,会将下面的所有lv全部删除,选择y也可以将VG和下面的LV全部删除掉。

[root@dbabc.net ~]# vgremove vg02
Do you really want to remove volume group "vg02" containing 3 logical volumes? [y/n]: y
  Logical volume "lvol0" successfully removed
  Logical volume "lvol1" successfully removed
  Volume group "vg02" successfully removed

3、vgexport、vgimport、vgchange命令:vg结构的导出、导入和改变

进行vgexport的操作会提示有活动的lv。将其umount,然后以vgchange将其状态更改为不活动。

[root@dbabc.net /]# vgexport vg01
Volume group "vg01" has active logical volumes
[root@dbabc.net /]# umount /test01
[root@dbabc.net /]# umount /test02
[root@dbabc.net /]# umount /test03
[root@dbabc.net /]# vgexport vg01
Volume group "vg01" has active logical volumes

vgchange中的-a参数代表此VG下的所有(all)LV, n代表将其变为不活动, y代表将其激活。

[root@dbabc.net /]# vgchange -an  vg01
0 logical volume(s) in volume group "vg01" now active

将其改为不活动后,查看/dev下就会发现vg01不见了。

[root@dbabc.net /]# ls /dev | grep vg
vg00

用vgscan查看仍然存在,因为vg并没有被删除

[root@dbabc.net ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg01" using metadata type lvm2
  Found volume group "vg00" using metadata type lvm2

然后将vg01 export掉。(vgexport与vgremove的区别在于:vgexport执行后,只是相当于在系统里将其屏蔽掉使其不可用,还可以使用vgimport再将其恢复,而vgremove后就将彻底删除此vg。真正要删除vg的话一般使用vgremove命令。)

[root@dbabc.net /]# vgexport vg01
Volume group "vg01" successfully exported

将vgexport后,vg01就不可用了,如用vgchange将其激活会提醒已被export了:

[root@dbabc.net /]# vgchange -ay vg01
Volume group "vg01" is exported

再将其import后才可以激活。

[root@dbabc.net /]# vgimport vg01
Volume group "vg01" successfully imported

虽导入了但没激活的话,/dev下仍然没有vg01的信息

[root@dbabc.net /]# ls /dev | grep vg
vg00

将其激活后vg01又恢复正常。

[root@dbabc.net /]# vgchange -ay vg01
3 logical volume(s) in volume group "vg01" now active
[root@dbabc.net /]# ls /dev | grep vg
vg00
vg01

无觅相关文章插件,快速提升流量

Copyright © Dbabc.Net All Rights Reserved. 本站内容仅代表个人观点, 与其他任何组织或公司无关

-The End-

发表评论


*

为你保密









Copyright © Dbabc.Net All Rights Reserved. 本站内容仅代表个人观点, 与其他任何组织或公司无关

Powered by Wordpress and Theme by WPYOU