一、创建物理卷
[root@centos ~]# fdisk /dev/sdb #创建3主分区,每个区5G
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x29162724.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G
Partition 2 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (20973568-41943039, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +5G
Partition 3 of type Linux and of size 5 GiB is set
Command (m for help): t #修改分区号
Partition number (1-3, default 3): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t
Partition number (1-3, default 3): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p #查看创建的分区
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x29162724
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 8e Linux LVM
/dev/sdb2 10487808 20973567 5242880 8e Linux LVM
/dev/sdb3 20973568 31459327 5242880 8e Linux LVM
Command (m for help): w #保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# pvcreate /dev/sdb{1,2,3} #创建物理卷
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
Physical volume "/dev/sdb3" successfully created.
[root@centos ~]# pvs #查看物理卷信息
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <19.00g 0
/dev/sdb1 lvm2 --- 5.00g 5.00g
/dev/sdb2 lvm2 --- 5.00g 5.00g
/dev/sdb3 lvm2 --- 5.00g 5.00g
二、创建卷组
[root@centos ~]# vgcreate vg01 /dev/sdb{1,2,3} #创建卷组 (注:vg01指的是卷组的名称)
Volume group "vg01" successfully created
[root@centos ~]# vgs #查看卷组信息
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <19.00g 0
vg01 3 0 0 wz--n- <14.99g <14.99g
三、创建逻辑卷
[root@centos ~]# lvcreate -n lv01 -L +2G vg01 #创建逻辑卷 (注:lv01 是指逻辑卷的名称 -L 后面跟的是逻辑卷的大小)
Logical volume "lv01" created.
[root@centos ~]# lvs #查看逻辑卷信息
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <17.00g
swap centos -wi-ao---- 2.00g
lv01 vg01 -wi-a----- 2.00g
四、格式化以及挂载
[root@centos ~]# mkdir /lv001 #创建文件
[root@centos ~]# cd /
[root@centos /]# ls
bin boot dev etc home lib lib64 lv001 media mnt opt proc root run sbin srv sys tmp usr var
[root@centos /]# cd
[root@centos ~]# ls /dev/vg01 #查看逻辑卷
lv01
[root@centos ~]# ll /dev/vg01/lv01 #其实lv01是dm-2的软链接
lrwxrwxrwx. 1 root root 7 Apr 28 02:38 /dev/vg01/lv01 -> ../dm-2
[root@centos ~]# mkfs.xfs /dev/vg01/lv01 #格式化
meta-data=/dev/vg01/lv01 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@centos ~]# mount /dev/vg01/lv01 /lv001 #挂载到lv001
[root@centos ~]# df -Th /lv001 #查看磁盘大小,解决:删除比较大无用的文件
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg01-lv01 xfs 2.0G 33M 2.0G 2% /lv001