标签:physical volume extent linux 操作系统
1.LVM是什么
LVM是一个Linux操作系统的逻辑卷管理器,现在有两个版本的LVM。LVM2是目前最新的版本,LVM 2是几乎完全向后兼容卷LVM。
PS:由LVM升级到LVM2需要删除快照。
2.使用LVM的优点
2.1逻辑卷管理提供了一个高级的较为磁盘管理,我们能够更灵活地分配存储空间(动态扩容,数据迁移,自定义卷组名,而不是以传统物理磁盘命名sd[a-z])。
2.2某分区空间紧缺,比如/home目录空间紧缺,使用传统的分区,解决此问题需要花费很大精力;但是使用LVM可以很快解决问题(在线扩容)。
3.缺点
因为使用LVM(分区,pv,vg,lv,格式化挂载)比传统文件系统管理多出了3个节点,性能必有所损失。
3.LVM的主要组成元素
PE(physicalextent), physical volume(PV), volume group(VG), logical extent(LE), logicalvolume (LV).
LVM创建步骤
1.准备磁盘分区
# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘).
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-4568, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-4568, default 4568): +5G
Command (m for help): N Command action e extended p primary partition (1-4) P Partition number (1-4): 2 First cylinder (655-4568, default 655): Using default value 655 Last cylinder, +cylinders or +size{K,M,G} (655-4568, default 4568): +5G
Command (m for help): T Partition number (1-4): 1 Hex code (type L to list codes): 8E Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): T Partition number (1-4): 2 Hex code (type L to list codes): 8E Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): W The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks. |
2.准备PV物理卷
创建
# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created # pvcreate /dev/sdb2 Physical volume "/dev/sdb2" successfully created |
查看
# pvdisplay /dev/sdb[12] "/dev/sdb1" is a new physical volume of "5.01 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 5.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID TIxk0t-icRJ-UcAX-rPRP-gpzj-j9s0-b01DAZ
"/dev/sdb2" is a new physical volume of "5.01 GiB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 5.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID n8plJt-0AYQ-IzKX-juf2-8Msa-a4ZA-ddaBY3 |
删除
pvremove /dev/sdb1
3.准备卷组vg
创建
# vgcreate test-vg /dev/sdb1 Volume group "test-vg" successfully created |
查看
# vgdisplay --- Volume group --- VG Name test-vg System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size 5.01 GiB PE Size 4.00 MiB Total PE 1282 Alloc PE / Size 0 / 0 Free PE / Size 1282 / 5.01 GiB VG UUID ImZcU6-pTww-G0nY-Ib4H-giyi-x3D3-RRENXK |
从以上信息中我们知道卷组名,卷组状态,空间大小等信息。
4.准备LV逻辑卷
创建
# lvcreate -L 2G -n test-lv test-vg Logical volume "test-lv" created |
查看
# lvdisplay --- Logical volume --- LV Path /dev/test-vg/test-lv LV Name test-lv VG Name test-vg LV UUID Z6PNy1-qzfa-JN8n-pJX6-dCXI-ZpW3-IDifMg LV Write Access read/write LV Creation host, time localhost.localdomain, 2015-08-24 19:47:23 +0800 LV Status available # open 0 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:4 |
逻辑卷创建好了,我们就可以进行格式化和挂载,就像ext3/4一样
# mkfs -t ext4 -c /dev/test-vg/test-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 131072 inodes, 524288 blocks 26214 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
Checking for bad blocks (read-only test): done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
# mkdir /lvm-test #创建挂载目录 # mount /dev/test-vg/test-lv /lvm-test #挂载 # blkid /dev/test-vg/test-lv /dev/test-vg/test-lv: UUID="1a569dec-0a9d-44fa-8125-9ad1bed42a4f" TYPE="ext4"
#echo ‘UUID="1a569dec-0a9d-44fa-8125-9ad1bed42a4f" /lvm-test ext4 defaults 0 0’>>/etc/fstab #开机自动挂载 |
关于删除和创建正好相反,取消挂载,删除逻辑卷,删除卷组,删除物理卷,删除分区。
PS:删除前最好先进行备份.
标签:physical volume extent linux 操作系统
原文地址:http://7431686.blog.51cto.com/7421686/1688887