ACTIVE '/dev/vg51cto/LogVol04' [22.80 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol01' [10.00 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol00' [2.00 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol03' [20.00 GiB]inherit
ACTIVE '/dev/vg51cto/LogVol02' [5.00 GiB]inherit
2.查看逻辑卷详细信息
lvdisplay 命令查看所有逻辑卷的详细信息
lvdisplay 逻辑卷名称
[root@hadoop01 ~]# lvdisplay /dev/vg51cto/LogVol00
— Logicalvolume —
LVPath /dev/vg51cto/LogVol00
LVName LogVol00
VGName vg51cto
LVUUID hSyH2r-mvMV-th7q-geKg-sVpm-O1zJ-D6DwT8
LV WriteAccess read/write
LV Creationhost, time hadoop01, 2015-11-05 17:30:58 +0800
LVStatus available
# open 1
LVSize 2.00 GiB
CurrentLE 512
Segments 1
Allocation inherit
Read aheadsectors auto
– currentlyset to 256
Block device 253:1
3.修改逻辑卷名
1)修改逻辑卷命令为lvrename,语法如下:
lvrename OldLogicalVolumePath NewLogicalVolumePath
[root@hadoop01 ~]# lvrename /dev/vg51cto/LogVol00 /dev/vg51cto/lv_swap
Renamed"LogVol00" to "lv_swap" in volume group "vg51cto"
[root@hadoop01 ~]# lvrename /dev/vg51cto/LogVol01 /dev/vg51cto/lv_root
Renamed"LogVol01" to "lv_root" in volume group "vg51cto"
[root@hadoop01 ~]# lvrename /dev/vg51cto/LogVol02 /dev/vg51cto/lv_home
Renamed"LogVol02" to "lv_home" in volume group "vg51cto"
[root@hadoop01 ~]# lvrename /dev/vg51cto/LogVol03 /dev/vg51cto/lv_data
Renamed"LogVol03" to "lv_data" in volume group "vg51cto"
[root@hadoop01 ~]# lvrename /dev/vg51cto/LogVol04 /dev/vg51cto/lv_usr
Renamed"LogVol04" to "lv_usr" in volume group "vg51cto"
2)修改/etc/fstab配置文件。
[root@hadoop01 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 5 17:33:46 2015
#
# Accessible filesystems, by reference, aremaintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8)and/or blkid(8) for more info
#
/dev/mapper/vg51cto-lv_root / ext4 defaults 1 1
UUID=9c02e519-3b85-4918-b9fd-395535cab496/boot ext4 defaults 1 2
/dev/mapper/vg51cto-lv_data /data ext4 defaults 1 2
/dev/mapper/vg51cto-lv_home /home ext4 defaults 1 2
/dev/mapper/vg51cto-lv_usr /usr/local ext4 defaults 1 2
/dev/mapper/vg51cto-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
3)修改grub.conf配置文件。
[root@hadoop01 ~]# vim /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub aftermaking changes to this file
# NOTICE: You have a /boot partition. Thismeans that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg51cto_lv-LogVol01
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
root(hd0,0)
kernel/vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg51cto-lv_root rd_NO_LUKSrd_LVM_LV=vg51cto/lv_root rd_LVM_LV=vg51cto/lv_swap rd_NO_MD crashkernel=autoLANG=zh_CN.UTF-8 KEYBOARDTYPE=pc KEYTABLE=usrd_NO_DM rhgb quiet
initrd/initramfs-2.6.32-431.el6.x86_64.img
第三部分:物理卷(physical volume,PV)相关操作。
1.查看物理卷(PV)名,这里为/dev/sda2,linux中SCSI的第1块硬盘为/dev/sda,第2块硬盘为/dev/sdb,依此类推。
[root@hadoop01 ~]# pvscan
PV /dev/sda2 VG vg51cto lvm2 [59.80 GiB / 0 free]
Total: 1[59.80 GiB] / in use: 1 [59.80 GiB] / in no VG: 0 [0 ]
2.查看物理卷详细信息。
[root@hadoop01 ~]# pvdisplay
—Physical volume —
PVName /dev/sda2
VGName vg51cto
PVSize 59.80 GiB / not usable 3.00 MiB
Allocatable yes (butfull)
PESize 4.00 MiB
TotalPE 15309
FreePE 0
AllocatedPE 15309
PVUUID pKC6SA-fkfe-OAl2-scVr-tq0h-EAXD-AWpwgX
四、LVM空间管理
1.LVM减少LV空间
举例:减少/data空间,从20G减少到10G。
1)卸载设备(Unmount thefilesystem)
[root@hadoop01 ~]# umount /data/
2)e2fsck命令检查文件系统(Checkthe filesystem)
[root@hadoop01 ~]# e2fsck -f/dev/mapper/vg51cto-lv_data
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/vg51cto-lv_data: 11/1310720files (0.0% non-contiguous), 126289/5242880 blocks
3)resize2fs命令调整lv大小,10G表示调整后/data剩余空间。
[root@hadoop01 ~]# resize2fs/dev/mapper/vg51cto-lv_data 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on/dev/mapper/vg51cto-lv_data to 2621440 (4k) blocks.
The filesystem on/dev/mapper/vg51cto-lv_data is now 2621440 blocks long.
4)lvreduce命令减少文件系统大小(Resizethe filesystem),表示将/data的空间减少9G。
[root@hadoop01 ~]# lvreduce -L -9G /dev/mapper/vg51cto-lv_data
WARNING: Reducing active logical volume to 11.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_data?[y/n]: y
Reducing logical volume lv_data to 11.00 GiB
Logical volume lv_data successfully resized
5)vgs命令查看卷组剩余空间为9G。
6)mount 文件系统并查看磁盘空间剩余空间。
2.LVM增加LV空间
举例:将刚才9G空间增加到/home分区。
1)vgs命令查看是否有空闲空间可以扩容。
[root@hadoop01 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg51cto 1 5 0wz–n- 59.80g 9.00g
2)df -h查看当前磁盘空间
3)lvextend命令将home分区空间增加9G。
[root@hadoop01 ~]# lvextend -L +9G -f -r/dev/mapper/vg51cto-lv_home
Extending logical volume lv_home to 14.00 GiB
Logical volume lv_home successfully resized
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg51cto-lv_homeis mounted on /home; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of/dev/mapper/vg51cto-lv_home to 3670016 (4k) blocks.
The filesystem on/dev/mapper/vg51cto-lv_home is now 3670016 blocks long.
4)查看分区是否增加成功。
五、LVM 在线扩容
服务器磁盘空间不足,添加新的硬盘后,需要把空间添加当前分区当中。
linux中SCSI的第1个硬盘/dev/sda,第2个硬盘/dev/sdb依此类推。其中服务器第一块硬盘/dev/sda已经划分为LVM分区。/dev/sdb是新加的硬盘。
1) 用pvcreate /dev/sdb命令初始化分区sdb为物理卷(PV)。
[root@hadoop01 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
2)pvdisplay命令显示物理卷的信息
[root@hadoop01 ~]# pvdisplay
—Physical volume —
PVName /dev/sda2
VGName vg51cto
PVSize 59.80 GiB / not usable3.00 MiB
Allocatable yes (butfull)
PESize 4.00 MiB
Total PE 15309
Free PE 0
Allocated PE 15309
PVUUID pKC6SA-fkfe-OAl2-scVr-tq0h-EAXD-AWpwgX
"/dev/sdb" is a new physical volume of "40.00 GiB"
—NEW Physical volume —
PVName /dev/sdb
VGName
PVSize 40.00 GiB
Allocatable NO
PESize 0
Total PE 0
Free PE 0
Allocated PE 0
PVUUID dMeOLS-Sks3-8k3q-pVWp-Iuz2-0Hh2-8njjhY
3)vgextend命令将pv加入到vg,vgcreate命令为新创建vg(vgcreate vg51cto /dev/sdb),这里的vg51cto已经存在,只需要用vgextend加入即可。
[root@hadoop01 ~]# vgextend vg51cto/dev/sdb
Volume group "vg51cto" successfully extended
4)用vgdisplay命令查看vg信息,看到已经有40G空闲PE。
5)lvextend命令扩展分区,将40G空间全部添加到/data分区。
直接增加40G空间不足,报下面的错误,因此添加39.9G的空间。
Insufficient free space:10240 extents needed, but only 10239 available
[root@hadoop01 ~]# lvextend -L +39.99G/dev/mapper/vg51cto-lv_data
Rounding size to boundary between physical extents: 39.99 GiB
Extending logical volume lv_data to 50.99 GiB
Logicalvolume lv_data successfully resized
6)上一步操作只是增加了逻辑卷的大小,用resize2fs命令重新定义文件系统的大小。
[root@hadoop01 ~]# resize2fs /dev/mapper/vg51cto-lv_data
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg51cto-lv_datais mounted on /data; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of/dev/mapper/vg51cto-lv_data to 13367296 (4k) blocks.
The filesystem on/dev/mapper/vg51cto-lv_data is now 13367296 blocks long.
7)查看磁盘在线扩容是否正常。
总结:
1)/分区不能umount,说明/分区只能扩容,不能减少/分区的空间。
2)减少分区的时候需要卸载分区,进行umount操作。
3)扩容的分区的时候不需要卸载分区。
4)重命名vg,lv命名后,需要修改/etc/fstab和/etc/grub.conf引导文件。
原创文章,作者:NddTx99521,如若转载,请注明出处:http://www.178linux.com/41664