标签:lvm linux
1、实验环境:
1)、CentOS6.5-32bit;
四块SCSI硬盘,分别为:
/dev/sdb(10G),/dev/sdc(5G),/dev/sdd(15G),/dev/sde(20G);
需求软件包:lvm2
2、实验步骤:
1)、安装所需软件包
yum --disablerepo=\* --enablerepo=c6-media install lvm2 mdadm -y
2)、创建物理卷
[root@fcy ~]# pvcreate /dev/sdb /dev/sdc /dev/sdd Physical volume "/dev/sdb" successfully created Physical volume "/dev/sdc" successfully created Physical volume "/dev/sdd" successfully created
显示创建的物理卷
[root@fcy ~]# pvdisplay "/dev/sdb" is a new physical volume of "10.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb #物理卷名称 VG Name #加入的存储池名称 PV Size 10.00 GiB #物理卷的大小 Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID LqriDi-mS2t-jq0Y-l137-E9DD-hSdd-xaBiBy
扫描系统上的物理卷
[root@fcy ~]# pvscan PV /dev/sdb lvm2 [10.00 GiB] PV /dev/sdc lvm2 [5.00 GiB] PV /dev/sdd lvm2 [15.00 GiB] Total: 3 [30.00 GiB] / in use: 0 [0 ] / in no VG: 3 [30.00 GiB]
3)、创建卷组(存储池)
[root@fcy ~]# vgcreate fcy-vg /dev/sdb /dev/sdc Volume group "fcy-vg" successfully created
显示卷组
[root@fcy ~]# vgdisplay --- Volume group --- VG Name fcy-vg #卷组名称 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 14.99 GiB #存储池大小 PE Size 4.00 MiB #PE块的大小 Total PE 3838 #总PE数量 Alloc PE / Size 0 / 0 Free PE / Size 3838 / 14.99 GiB VG UUID AiEzvv-Y5gt-u7S1-9vCB-5yZP-Qsmq-t7WO7n
扫描卷组
[root@fcy ~]# vgscan Reading all physical volumes. This may take a while... Found volume group "fcy-vg" using metadata type lvm2
增加物理卷到卷组
[root@fcy ~]# vgextend fcy-vg /dev/sde Physical volume "/dev/sde" successfully created Volume group "fcy-vg" successfully extended
从卷组移除物理卷
[root@fcy ~]# vgreduce fcy-vg /dev/sde Removed "/dev/sde" from volume group "fcy-vg"
删除卷组
vgremove fcy-vg
4)、创建逻辑卷
[root@fcy ~]# lvcreate -L 10G -n fcy-lv fcy-vg #-L指定大小,-n指定名称 Logical volume "fcy-lv" created
查看逻辑卷
[root@fcy ~]# lvdisplay --- Logical volume --- LV Path /dev/fcy-vg/fcy-lv LV Name fcy-lv VG Name fcy-vg LV UUID KF3klx-2aex-c3el-EduY-a3p8-Jh0G-W9IgHQ LV Write Access read/write LV Creation host, time fcy.com.cn, 2015-07-15 20:05:27 +0800 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
扫描逻辑卷
[root@fcy ~]# lvscan ACTIVE ‘/dev/fcy-vg/fcy-lv‘ [10.00 GiB] inherit
格式化创建的逻辑卷
[root@fcy ~]# mkfs -t ext3 /dev/fcy-vg/fcy-lv mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2684354560 80 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
挂载逻辑卷
[root@fcy ~]# mount /dev/fcy-vg/fcy-lv /mnt/fcy-lvm/ [root@fcy ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 15G 1.9G 12G 14% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 194M 26M 158M 15% /boot /dev/sr0 3.6G 3.6G 0 100% /media/cdrom /dev/mapper/fcy--vg-fcy--lv 9.9G 151M 9.2G 2% /mnt/fcy-lvm #已经挂载并可以使用
在线扩展逻辑卷大小
[root@fcy ~]# lvresize -L +1G /dev/fcy-vg/fcy-lv Extending logical volume fcy-lv to 11.00 GiB Logical volume fcy-lv successfully resized [root@fcy ~]# lvdisplay --- Logical volume --- LV Path /dev/fcy-vg/fcy-lv LV Name fcy-lv VG Name fcy-vg LV UUID KF3klx-2aex-c3el-EduY-a3p8-Jh0G-W9IgHQ LV Write Access read/write LV Creation host, time fcy.com.cn, 2015-07-15 20:05:27 +0800 LV Status available # open 1 LV Size 11.00 GiB Current LE 2816 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
注意:执行完lvresize后要继续执行如下命令才能扩展完成
[root@fcy ~]# resize2fs /dev/fcy-vg/fcy-lv resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/fcy-vg/fcy-lv is mounted on /mnt/fcy-lvm; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/fcy-vg/fcy-lv to 2883584 (4k) blocks. The filesystem on /dev/fcy-vg/fcy-lv is now 2883584 blocks long.
减小逻辑卷的大小(注意该指令不支持在线,所以要先卸载挂载点)
[root@fcy ~]# e2fsck -f /dev/fcy-vg/fcy-lv #强制系统文件检测 e2fsck 1.41.12 (17-May-2010) 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/fcy-vg/fcy-lv: 11/720896 files (0.0% non-contiguous), 84449/2883584 blocks
[root@fcy ~]# lvresize -L 8G /dev/fcy-vg/fcy-lv WARNING: Reducing active logical volume to 8.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce fcy-lv? [y/n]: y Reducing logical volume fcy-lv to 8.00 GiB Logical volume fcy-lv successfully resized
创建逻辑卷的快照
[root@fcy ~]# lvcreate -L 1G -n fcy-snap -s /dev/fcy-vg/fcy-lv #-s指定要做快照的逻辑卷 Logical volume "fcy-snap" created
挂载并对比
[root@fcy ~]# mount /dev/fcy-vg/fcy-snap /mnt/fcy-snapshot/ [root@fcy ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 15G 1.9G 12G 14% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 194M 26M 158M 15% /boot /dev/sr0 3.6G 3.6G 0 100% /media/cdrom /dev/mapper/fcy--vg-fcy--lv 7.9G 151M 7.4G 2% /mnt/fcy-lvm /dev/mapper/fcy--vg-fcy--snap 7.9G 151M 7.4G 2% /mnt/fcy-snapshot
本文出自 “却邪水心泮” 博客,请务必保留此出处http://shmilyfl.blog.51cto.com/8897986/1675107
标签:lvm linux
原文地址:http://shmilyfl.blog.51cto.com/8897986/1675107