物理分区
物理分区或磁盘是 LVM 的第一构建块。这些可以是分区、完整磁盘、 RAID 集或 SAN 磁盘
物理卷
物理卷是 LVM 所使用的基础 “物理 ”存储。这通常是块设备 , 例如分区或完整磁盘。设备必须初始化为 LVM 物理卷 , 才能与LVM 结合使用
卷组
卷组是存储池 , 由一个或多个物理卷组成
物理区块
物理区块是物理卷中存储的小型数据区块 , 用作 LVM 存储的后端
逻辑区块
逻辑区块映射到物理区块 , 构成 LVM 存储的前端。默认情况下 , 每个逻辑区块映射到一个物理区块。启用某些选项将更改此映射。例如 , 镜像会导致每个逻辑区块映射到两个物理区块
逻辑卷
逻辑卷是逻辑区块组。逻辑卷可以像硬盘驱动器分区一样使用
逻辑卷和逻辑卷管理有助于更加轻松地管理磁盘空间。如果文件系统需要更多的空间 , 可以将其卷组的可用空间分配给逻辑卷 , 并且可以调整文件系统的大小。如果磁盘开始出现错误 , 可以通过卷组将替换磁盘注册为物理卷 , 并且逻辑卷的范围可迁移到新磁盘
第一步:把/dev/vdb5更改分区类型为8e
[root@localhost ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t
Partition number (1-5, default 5): 5
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3250bf3e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 616447 204800 83 Linux
/dev/vdb3 616448 1230847 307200 83 Linux
/dev/vdb4 1230848 20971519 9870336 5 Extended
/dev/vdb5 1232896 1437695 102400 8e Linux LVM
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe
第二步:把物理分区做成物理卷
pvcreate /dev/vdb5
第三步:创建物理卷组
vgcreate weixingroup /dev/vdb5
第四步:创建逻辑卷
lvcreate -L 50M -n weixindata weixingroup ##逻辑卷组下的逻辑卷
第五步:格式化逻辑卷
mkfs.xfs /dev/weixingroup/weixindata
第六步:挂载逻辑卷到挂载点
mount /dev/weixingroup/weixindata /mnt
注意:
ll 可以查看/dev/weixingroup/weixindata和/dev/mappper/weixingroup-weixindata是一个,都是../dm-0的软连接
第一种:当磁盘上有空间时,先扩展逻辑卷,再扩展文件系统
lvextend -L 90M /dev/weixngroup/weixindata ##扩展物理边界
xfs_growfs /dev/weixngroup/weixindata ##扩展逻辑边界
第二种:当磁盘上没有空间时,先扩展物理卷组的大小,增加新的物理卷到物理卷组中
1.添加新的分区
[root@localhost ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (1439744-20971519, default 1439744):
Using default value 1439744
Last sector, +sectors or +size{K,M,G} (1439744-20971519, default 20971519): +100M
Partition 6 of type Linux and of size 100 MiB is set
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3250bf3e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 616447 204800 83 Linux
/dev/vdb3 616448 1230847 307200 83 Linux
/dev/vdb4 1230848 20971519 9870336 5 Extended
/dev/vdb5 1232896 1437695 102400 8e Linux LVM
/dev/vdb6 1439744 1644543 102400 83 Linux
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partprobe
2.创建新的物理卷
pvcreate /dev/vdb6
3.将新的物理卷添加到物理卷组中
vgextend weixingroup /dev/vdb6
4.扩展逻辑卷的物理边界和逻辑边界
lvextend -L 150M /dev/weixingroup/weixindata
xfs_growfs /dev/weixngroup/weixindata
xfs只支持拉神,不支持压缩
ext4支持拉伸和压缩
第一步:更改格式变为.ext4,重新挂载
第二步:扩展逻辑卷
lvextend -L 160M /dev/weixingroup/weixindata
第三步:扩展文件系统
resize2fs /dev/weixingroup/weixindata
第一步:缩减逻辑卷不能在线缩减,所以要先解挂
umount /mnt
e2fsck -f /dev/weiixngroup/weixindata
resize2fs /dev/weixingroup/weixindata 50M
lvreduce -L 50M /dev/weixngroup/weixindata
第一步:将要删除的设备上数据迁移到另一个设备
pvmove /dev/vdb6 /dev/vdb5
第二步:将逻辑卷从物理卷组中删除
vgreduce weixingroup /dev/vdb6
第三步:移除设备
pvremove /dev/vdb6
第一步:创建逻辑卷快照
lvcreate -L 20M -n weixindata_backup -s /dev/weixingroup/weixindata ##创建逻辑卷快照
mount /dev/weixingroup/weixindata_backup /weixindata/ ##挂载
第二步:删除逻辑卷快照
umount /weixindata/
lvremove /dev/wexingroup/weixindata_backup ##删除逻辑卷快照
错误:
1.当设备正在用的时候,把lvm删除,会出现错误
2./etc/fstab文件中的内容出现错误
########PE#######
[root@localhost ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created
[root@localhost ~]# vgcreate -s 16M vg0 /dev/vdb1
Volume group "vg0" successfully created
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vdb1
VG Name vg0
PV Size 100.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 16.00 MiB
Total PE 6
Free PE 6
[root@localhost ~]# vgremove vg0
Volume group "vg0" not found
Skipping volume group vg0
[root@localhost ~]# pvdisplay
"/dev/vdb1" is a new physical volume of "100.00 MiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ke7pPe-nHu6-hadc-8rHC-Ge7U-mQDK-qnVqDf
[root@localhost ~]# vgcreate vg0 /dev/vdb1默认状态下PE数值为4
Volume group "vg0" successfully created
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vdb1
VG Name vg0
PV Size 100.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 24
Free PE 24
Allocated PE 0
PV UUID ke7pPe-nHu6-hadc-8rHC-Ge
注意:默认PE大小为4M
pvdisplay ##查看pv详细信息
vgremove ##删除物理卷组
vgcreate 卷组名 设备 ##由哪个设备创建物理卷组
parted /dev/vdb5 ##更改分区类型
######改变分区类型######
[root@localhost ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
(parted) help 查看帮助
align-check TYPE N check partition N for TYPE(min|opt)
alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available
devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
(parted) mklabel
New disk label type?
aix amiga bsd dvh gpt loop mac msdos pc98 sun
New disk label type? gpt ##使用gpt类型分区
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this
disk will be lost. Do you want to continue?是否毁掉原磁盘数据
Yes/No? yes
(parted) q
Information: You may need to update /etc/fstab.
[root@localhost ~]# fdisk /dev/vdb建立一个新分区
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition number (1-128, default 1):
First sector (34-20971486, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971486, default 20971486): +100M
Created partition 1
Command (m for help): p 查看分区
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt类型已经改变
# Start End Size Type Name
1 2048 206847 100M Linux filesyste