续上一章日志《linux LVM配置》,这章主要讲LVM空间的延伸与缩减
一、配置LVM空间增加
下面我们来测试下LVM分区的收缩、延伸
1、 使用fdisk来增加一个system ID 为8e的分区
2、 建立PV
3、 将PV加入到aixevg这个VG里面
4、 将VG加入到aixelv里面,增加空间
5、 用resize2fs将文件系统的容量确实增加
第一步:增加分区
- [root@CentOS5 ~]# fdisk /dev/sdb
- Device Boot Start End Blocks Id System
- /dev/sdb1 1 1246 10008463+ 5 Extended
- /dev/sdb5 1 183 1469884+ 8e Linux LVM
- /dev/sdb6 184 366 1469916 8e Linux LVM
- /dev/sdb7 367 549 1469916 8e Linux LVM
- /dev/sdb8 550 732 1469916 8e Linux LVM
- /dev/sdb9 733 915 1469916 8e Linux LVM
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- Syncing disks.
- [root@CentOS5 ~]#partprobe
先查看一下pvscan
- [root@CentOS5 ~]# pvscan
- PV /dev/sdb5 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb6 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb7 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb8 VG aixevg lvm2 [1.39 GB / 0 free]
- Total: 4 [5.56 GB] / in use: 4 [5.56 GB] / in no VG: 0 [0 ]
下面开始创建PV
- [root@CentOS5 ~]#pvcreate /dev/sdb9
- Physical volume "/dev/sdb9" successfully created
- [root@CentOS5 ~]#pvscan
- PV /dev/sdb5 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb6 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb7 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb8 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb9 lvm2 [1.40 GB]
- Total: 5 [6.96 GB] / in use: 4 [5.56 GB] / in no VG: 1 [1.40 GB]
添加VG
- [root@CentOS5 ~]#vgdisplay
- --- Volume group ---
- VG Name aixevg
- System ID
- Format lvm2
- ...(部分省略)...
- VG Size 5.56 GB
- PE Size 16.00 MB
- Total PE 356
- Alloc PE / Size 356 / 5.56 GB
- Free PE / Size 0 / 0
- ...(部分省略)...
- [root@CentOS5 ~]#vgextend aixevg /dev/sdb9
- Volume group "aixevg" successfully extended
- [root@CentOS5 ~]#vgdisplay
- --- Volume group ---
- VG Name aixevg
- System ID
- Format lvm2
- ...(部分省略)...
- VG Size 6.95 GB
- PE Size 16.00 MB
- Total PE 445
- Alloc PE / Size 356 / 5.56 GB
- Free PE / Size 89 / 1.39 GB
- ...(部分省略)...
从这里看到,我们扩展了VG后,Free多了89个PV
下面添加LV
- [root@CentOS5 ~]#df -h /mnt/lvm/
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/aixevg-aixelv
- 5.5G 140M 5.1G 3% /mnt/lvm
- [root@CentOS5 ~]#lvresize -l +89 /dev/aixevg/aixelv
- Extending logical volume aixelv to 6.95 GB
- Logical volume aixelv successfully resized
- [root@CentOS5 ~]#df -h /mnt/lvm/
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/aixevg-aixelv
- 5.5G 140M 5.1G 3% /mnt/lvm
这里我们看到空间没有实际增加,大家在操作时可以先、后运行下lvdisplay命令,可以看到LV的空间已经增加了。下面我们用resize2fs命令那确定增加空间
Resize2fs命令格式
- [root@CentOS5 ~]#resize2fs [-f] [device] [size]
- -f:强制改变大小
- Device:设备名称
- Size:要增加或减少到的空间大小,如果不设置表示全部,它的单位有M、G、T
- [root@CentOS5 ~]#resize2fs /dev/aixevg/aixelv
- resize2fs 1.39 (29-May-2006)
- Filesystem at /dev/aixevg/aixelv is mounted on /mnt/lvm; on-line resizing required
- Performing an on-line resize of /dev/aixevg/aixelv to 1822720 (4k) blocks.
- The filesystem on /dev/aixevg/aixelv is now 1822720 blocks long.
- [root@CentOS5 ~]#df -h /mnt/lvm/
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/aixevg-aixelv
- 6.9G 141M 6.4G 3% /mnt/lvm
可以看到空间真的增加,到这来LVM的空间增加以告一段落,下面我们来试试LVM空间的减少
二、配置LVM空间减少
LVM减少空间的步骤只是把增加空间的步骤反做一遍就可以了
我演示一下减少/dev/sdb5这个分区
- [root@CentOS5 ~]#df -h /mnt/lvm/
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/aixevg-aixelv
- 6.9G 588M 6.0G 9% /mnt/lvm
- [root@CentOS5 ~]#pvscan
- PV /dev/sdb5 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb6 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb7 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb8 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb9 VG aixevg lvm2 [1.39 GB / 0 free]
- Total: 5 [6.95 GB] / in use: 5 [6.95 GB] / in no VG: 0 [0 ]
下面我们使用resize2fs来减少空间
这里我们算一下1.39X4X1024=5693M,这个值就是resize2fs要减少到的值
- [root@CentOS5 ~]#umount /mnt/lvm/
- [root@CentOS5 ~]#resize2fs /dev/aixevg/aixelv 5600M
- resize2fs 1.39 (29-May-2006)
- Please run 'e2fsck -f /dev/aixevg/aixelv' first.
提示我们使用:e2fsck -f /dev/aixevg/aixelv,扫描我们的分区
- [root@CentOS5 ~]#e2fsck -f /dev/aixevg/aixelv
- 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/aixevg/aixelv: 12062/908544 files (0.1% non-contiguous), 179023/1822720 blocks
- [root@CentOS5 ~]#resize2fs /dev/aixevg/aixelv 5600M
- resize2fs 1.39 (29-May-2006)
- Resizing the filesystem on /dev/aixevg/aixelv to 1433600 (4k) blocks.
- The filesystem on /dev/aixevg/aixelv is now 1433600 blocks long.
- [root@CentOS5 ~]#mount /dev/aixevg/aixelv /mnt/lvm/
- [root@CentOS5 ~]#df -h /mnt/lvm/
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/aixevg-aixelv
- 5.4G 587M 4.6G 12% /mnt/lvm
看到了吧,实际空间已经减小了,我们下面改变LV的大小
看看/dev/sdb5有多少个PV
- [root@CentOS5 ~]#pvdisplay
- --- Physical volume ---
- PV Name /dev/sdb5
- VG Name aixevg
- PV Size 1.40 GB / not usable 11.43 MB
- Allocatable yes (but full)
- PE Size (KByte) 16384
- Total PE 89
- Free PE 0
- Allocated PE 89
- PV UUID dR35q4-Y7ma-EVqe-Ggxw-0mVX-6xjF-NZRDcX
上面看到/dev/sdb5有89个PV
- [root@CentOS5 ~]#lvresize -l -89 /dev/aixevg/aixelv
- WARNING: Reducing active and open logical volume to 5.56 GB
- THIS MAY DESTROY YOUR DATA (filesystem etc.)
- Do you really want to reduce aixelv? [y/n]: y
- Reducing logical volume aixelv to 5.56 GB
- Logical volume aixelv successfully resized
- [root@CentOS5 ~]#pvdisplay
- --- Physical volume ---
- PV Name /dev/sdb5
- VG Name aixevg
- PV Size 1.40 GB / not usable 11.43 MB
- Allocatable yes (but full)
- PE Size (KByte) 16384
- Total PE 89
- Free PE 0
- Allocated PE 89
- PV UUID dR35q4-Y7ma-EVqe-Ggxw-0mVX-6xjF-NZRDcX
- ....(部分省略)...
- PV Name /dev/sdb9
- VG Name aixevg
- PV Size 1.40 GB / not usable 11.46 MB
- Allocatable yes
- PE Size (KByte) 16384
- Total PE 89
- Free PE 89
- Allocated PE 0
- PV UUID 8uWMkf-bIOE-ilG8-zEz1-EvN0-WQW2-YOUQdE
说明在/dev/sdb9上有空余的89个PV,也就是我们减少的那89个PV,但是我们要减少的/dev/sdb5这个分区,所以我们要转换一下
- [root@CentOS5 ~]#pvmove /dev/sdb5 /dev/sdb9
- /dev/sdb5: Moved: 100.0%
现在在查看一次PV
- [root@CentOS5 ~]#pvdisplay
- --- Physical volume ---
- PV Name /dev/sdb5
- VG Name aixevg
- PV Size 1.40 GB / not usable 11.43 MB
- Allocatable yes
- PE Size (KByte) 16384
- Total PE 89
- Free PE 89
- Allocated PE 0
- PV UUID dR35q4-Y7ma-EVqe-Ggxw-0mVX-6xjF-NZRDcX
- ...(部分省略)...
- --- Physical volume ---
- PV Name /dev/sdb9
- VG Name aixevg
- PV Size 1.40 GB / not usable 11.46 MB
- Allocatable yes (but full)
- PE Size (KByte) 16384
- Total PE 89
- Free PE 0
- Allocated PE 89
- PV UUID 8uWMkf-bIOE-ilG8-zEz1-EvN0-WQW2-YOUQdE
接下来在VG里面移除/dev/sdb5
- [root@CentOS5 ~]#vgreduce aixevg /dev/sdb5
- Removed "/dev/sdb5" from volume group "aixevg"
- [root@CentOS5 ~]#pvscan
- PV /dev/sdb6 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb7 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb8 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb9 VG aixevg lvm2 [1.39 GB / 0 free]
- PV /dev/sdb5 lvm2 [1.40 GB]
- Total: 5 [6.96 GB] / in use: 4 [5.56 GB] / in no VG: 1 [1.40 GB]
到这里LVM的增、减空间基本告一段落了,以后我会继续更新LVM的快照,敬请期待