[原创]虚拟机下创建LVM设备操作_Hadoop,ERP及大数据讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Hadoop,ERP及大数据讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 4238 | 回复: 0   主题: [原创]虚拟机下创建LVM设备操作        下一篇 
kim
注册用户
等级:中校
经验:1729
发帖:222
精华:0
注册:2011-7-21
状态:离线
发送短消息息给kim 加好友    发送短消息息给kim 发消息
发表于: IP:您无权察看 2011-8-8 12:08:26 | [全部帖] [楼主帖] 楼主

首先添加三个磁盘,/dev/sdb,/dev/sdc,/dev/sdd, 分别为500M。

分区:

[root@testdb ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-512, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-512, default 512):
Command (m for help): t
Hex code (type L to list codes): 8e     --- 转换为8e类型
Changed system type of partition 1 to 8e (Linux LVM)
[root@testdb ~]# fdisk /dev/sdc


同上

[root@testdb ~]# fdisk /dev/sdd


同上

[root@testdb ~]# fdisk –l
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sdb1               1         512      524272   8e  Linux LVM
/dev/sdc1               1         512      524272   8e  Linux LVM
/dev/sdd1               1         512      524272   8e  Linux LVM


对分区进行初始化:

创建PV:

[root@testdb ~]# pvcreate /dev/sd[b,c,d]1
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdd1" successfully created


创建VG:

[root@testdb ~]# vgcreate vg0 /dev/sd[b,c]1 
Volume group "vg0" successfully created


查看VG 信息:

[root@testdb ~]# vgdisplay /dev/vg0
--- Volume group ---
VG Name               vg0
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               1016.00 MB
PE Size               4.00 MB


  Total PE              254     - - - 254个PE 模块

Alloc PE / Size       0 / 0
Free  PE / Size       254 / 1016.00 MB
VG UUID               ke01sq-9CRS-YSP4-jiQs-iGPR-50LG-Fug72V


创建 LV :

[root@testdb ~]# lvcreate -n lv0 -L 50M vg0- - - 50M大小的LV ,名称lv0
Rounding up size to full physical extent 52.00 MB
Logical volume "lv0" created


或“lvcreate –n lv0 –l 13 vg0”- - - 13个PE 大小,即52M,

[root@testdb ~]# lvcreate -n lv1 -l 5 vg0
Logical volume "lv1" created


查看LV 信息:

[root@testdb ~]# ls -l /dev/mapper/vg0-lv0 - - - 此文件一般不用
brw-rw---- 1 root disk 253, 2 Aug  6 13:16 /dev/mapper/vg0-lv0
[root@testdb ~]# ls -l /dev/vg0/lv0
lrwxrwxrwx 1 root root 19 Aug  6 13:16 /dev/vg0/lv0 -> /dev/mapper/vg0-lv0


查看LV 属性:

[root@testdb ~]# lvdisplay /dev/vg0/lv0
--- Logical volume ---
LV Name                /dev/vg0/lv0
VG Name                vg0
LV UUID                F7ncuY-Vcv4-t1Rs-L730-Bqci-eysU-A4mJGw
LV Write Access        read/write
LV Status              available
LV Size                52.00 MB
Current LE             13
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:2


格式化LV:

[root@testdb ~]# mkfs.ext3 /dev/vg0/lv0


挂载 lv0 到 /lv0目录:

[root@testdb /]# mkdir lv0
[root@testdb /]# mount /dev/vg0/lv0 /lv0/


注:若想开机挂载,修改/etc/fstab 文件,添加,

“/dev/vg0/lv0            /lv0                    ext3    defaults        0 0”


扩大LV :先umount 分区,再扩展。

[root@testdb /]# umount /lv0/
[root@testdb /]# lvextend -L +20M /dev/vg0/lv0
Extending logical volume lv0 to 72.00 MB
Logical volume lv0 successfully resized


检查LV:

[root@testdb /]# e2fsck -f /dev/vg0/lv0
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg0/lv0: 11/13328 files (9.1% non-contiguous), 6645/53248 blocks


重新定义分区大小:

[root@testdb /]# resize2fs /dev/vg0/lv0
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg0/lv0 to 73728 (1k) blocks.
The filesystem on /dev/vg0/lv0 is now 73728 blocks long.


再挂载:

[root@testdb /]# mount /dev/vg0/lv0 /lv0/
[root@testdb /]# df -h /lv0
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv0    70M  5.1M   62M   8% /lv0


扩大VG:

分区类型为8e,使用pvcreate对物理磁盘进行初始化:pvcreate /dev/sdd1

Vgextend vg0 /dev/sdd1  - - -将分区加入卷组

[root@testdb ~]# pvcreate /dev/sde1
Physical volume "/dev/sde1" successfully created
[root@testdb ~]# vgextend vg0 /dev/sde1
Volume group "vg0" successfully extended
[root@testdb ~]# vgdisplay vg0
VG Size               1.19 GB
PE Size               4.00 MB
Total PE              304


用快照执行备份:

Lvcreate –s –L 52M –n snap /dev/vg0/lv1


-s :表示快照

-L  : 快照大小要大于或等于被创建的逻辑卷 lv1

-n  : 快照名称

快照不用格式化即可使用

[root@testdb ~]# lvdisplay /dev/vg0/lv1
--- Logical volume ---
LV Size                20.00 MB
[root@testdb ~]# lvcreate -s -L 20M -n snap1 /dev/vg0/lv1
Logical volume "snap1" created


删除LV :

umount 所有LV

lvremove /dev/vg0/lv1  通过lvscan查看,如有快照,先移除快照再移除LV

vgchange –an /dev/vg0  休眠vg,以便删除,“vgchange –ay /dev/vg1”是激活vg

vgremove vg0




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论