一.LVM创建过程
1.首先在分区上创建物理卷
[root@wenqing ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d7ee8 Device Boot Start End Blocks Id System /dev/sda1 1 523 4194304 8e Linux LVM Partition 1 does not end on cylinder boundary. /dev/sda2 * 523 5222 37747712 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_wenqing-LogVol00: 4290 MB, 4290772992 bytes 255 heads, 63 sectors/track, 521 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
#这里使用/dev/sdb分区
2.建立物理卷
[root@wenqing ~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created
3.使用物理卷建立卷组
[root@wenqing ~]# vgcreate oslvm /dev/sdb Volume group "oslvm" successfully created [root@wenqing ~]# vgs VG #PV #LV #SN Attr VSize VFree oslvm 1 0 0 wz--n- 10.00g 10.00g vg_wenqing 1 1 0 wz--n- 4.00g 0
4.在卷组中建立逻辑卷
[root@wenqing ~]# lvcreate -L 500M -n ruyan oslvm Logical volume "ruyan" created. [root@wenqing ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ruyan oslvm -wi-a----- 500.00m LogVol00 vg_wenqing -wi-ao---- 4.00g
5.在逻辑卷上建立文件系统
[root@wenqing ~]# mkfs -t ext4 /dev/oslvm/ruyan mke2fs 1.43-WIP (20-Jun-2013) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 128016 inodes, 512000 blocks 25600 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67633152 63 block groups 8192 blocks per group, 8192 fragments per group 2032 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done
6.将文件系统挂载到Linux系统目录树中
#创建一个文件夹
[root@wenqing ~]# mkdir /ruyan
#挂载到该文件夹下
[root@wenqing ~]# mount /dev/oslvm/ruyan /ruyan
#查看容量
[root@wenqing ~]# df -Ph Filesystem Size Used Avail Use% Mounted on /dev/sda2 36G 13G 22G 36% / tmpfs 2.0G 72K 2.0G 1% /dev/shm /dev/mapper/oslvm-ruyan 477M 2.3M 445M 1% /ruyan
7.编辑fstab文件,实现自动挂载
[root@wenqing ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sat Oct 24 03:41:24 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=925f051e-2f6d-478f-83e6-bd73798b966b / ext4 defaults 1 1 /dev/mapper/vg_wenqing-LogVol00 swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults,size=2G 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/oslvm/ruyan /ruyan ext4 defaults 1 1
二.LVM扩充容量
可以进行动态扩充
1.添加物理卷
[root@wenqing ~]# vgextend oslvm /dev/sdc Physical volume "/dev/sdc" successfully created Volume group "oslvm" successfully extended
#可以看到有两个物理卷
[root@wenqing ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda1 vg_wenqing lvm2 a-- 4.00g 0 /dev/sdb oslvm lvm2 a-- 10.00g 9.51g /dev/sdc oslvm lvm2 a-- 2.00g 2.00g [root@wenqing ~]# vgs VG #PV #LV #SN Attr VSize VFree oslvm 2 1 0 wz--n- 11.99g 11.50g vg_wenqing 1 1 0 wz--n- 4.00g 0
2.扩充逻辑卷容量
[root@wenqing ~]# lvextend -L +100M /dev/oslvm/ruyan Size of logical volume oslvm/ruyan changed from 500.00 MiB (125 extents) to 600.00 MiB (150 extents). Logical volume ruyan successfully resized #查看扩充后大小 [root@wenqing ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert ruyan oslvm -wi-ao---- 600.00m LogVol00 vg_wenqing -wi-ao---- 4.00g
3.更新文件系统
[root@wenqing ~]# resize2fs /dev/oslvm/ruyan resize2fs 1.43-WIP (20-Jun-2013) Filesystem at /dev/oslvm/ruyan is mounted on /ruyan; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 3 The filesystem on /dev/oslvm/ruyan is now 614400 blocks long. #再次查看文件系统,容量已经增加。 [root@wenqing ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 36G 13G 22G 36% / tmpfs 2.0G 72K 2.0G 1% /dev/shm /dev/mapper/oslvm-ruyan 574M 2.3M 539M 1% /ruyan
三.LVM缩小容量
缩小操作,必须卸载逻辑卷。
否则报错:
[root@wenqing ~]# resize2fs /dev/oslvm/ruyan 200M resize2fs 1.43-WIP (20-Jun-2013) Filesystem at /dev/oslvm/ruyan is mounted on /ruyan; on-line resizing required resize2fs: On-line shrinking not supported
1.卸载逻辑卷
[root@wenqing ~]# umount /dev/oslvm/ruyan
2.缩小文件系统,提示错误
[root@wenqing ~]# resize2fs /dev/oslvm/ruyan 400M resize2fs 1.43-WIP (20-Jun-2013) Please run 'e2fsck -f /dev/oslvm/ruyan' first. [root@wenqing ~]# e2fsck -f /dev/oslvm/ruyan e2fsck 1.43-WIP (20-Jun-2013) 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/oslvm/ruyan: 11/152400 files (0.0% non-contiguous), 29738/614400 blocks [root@wenqing ~]# resize2fs /dev/oslvm/ruyan 400M resize2fs 1.43-WIP (20-Jun-2013) Resizing the filesystem on /dev/oslvm/ruyan to 409600 (1k) blocks. The filesystem on /dev/oslvm/ruyan is now 409600 blocks long.
3.缩小逻辑卷
[root@wenqing ~]# lvreduce -L -200M /dev/oslvm/ruyan WARNING: Reducing active logical volume to 400.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce ruyan? [y/n]: y Size of logical volume oslvm/ruyan changed from 600.00 MiB (150 extents) to 400.00 MiB (100 extents). Logical volume ruyan successfully resized
4.查看缩小后的逻辑卷大小
[root@wenqing ~]# lvdisplay --- Logical volume --- LV Path /dev/oslvm/ruyan LV Name ruyan VG Name oslvm LV UUID 5ExcKU-0U0g-cvf1-XsPc-QQOe-1Zkd-cUZxOj LV Write Access read/write LV Creation host, time wenqing, 2016-08-15 14:22:14 +0800 LV Status available # open 0 LV Size 400.00 MiB Current LE 100 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:1 --- Logical volume --- LV Path /dev/vg_wenqing/LogVol00 LV Name LogVol00 VG Name vg_wenqing LV UUID Aosxon-N9zJ-2aOe-S3T5-GVv2-9isH-GJNJaE LV Write Access read/write LV Creation host, time wenqing, 2015-10-24 03:40:17 +0800 LV Status available # open 2 LV Size 4.00 GiB Current LE 1023 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0
5.挂载文件系统
[root@wenqing ~]# mount /dev/oslvm/ruyan /ruyan
6.查看文件系统大小
[root@wenqing ~]# df -Ph Filesystem Size Used Avail Use% Mounted on /dev/sda2 36G 13G 22G 36% / tmpfs 2.0G 72K 2.0G 1% /dev/shm /dev/mapper/oslvm-ruyan 380M 2.3M 354M 1% /ruyan
四.删除逻辑卷
[root@wenqing ~]# lvremove /dev/oslvm/ruyan Logical volume oslvm/ruyan contains a filesystem in use.
#需要卸载文件系统
[root@wenqing ~]# umount /dev/oslvm/ruyan [root@wenqing ~]# lvremove /dev/oslvm/ruyan Do you really want to remove active logical volume ruyan? [y/n]: y Logical volume "ruyan" successfully removed
版权声明:本文为博主原创文章,未经博主允许不得转载。