PV(物理卷)
整个硬盘,或使用fdisk等工具建立的普通分区
包括许多默认4MB大小的PE
VG (卷组)
一个或多个物理卷组合而成的整体
LV(逻辑卷)
从卷组中分割处的一块空间,用于建立文件系统
先创建物理卷,然后创建卷组,最后再创建逻辑卷。
1.进行系统df -h,查看磁盘信息【文件系统 容量 已用 可用 已用% 挂载点】
[root@icoolkj ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 46G 1.7G 44G 4% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 26M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 1014M 145M 870M 15% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
[root@icoolkj ~]#
2.进入系统fdisk -l,查看当前磁盘信息。
[root@icoolkj ~]# fdisk -l
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000ca465
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 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 /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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 /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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
[root@icoolkj ~]#
3.fdisk在Disk /dev/vdb 新的磁盘上创建分区
[root@icoolkj ~]# fdisk /dev/vdb # 注意,这里的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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x1c98c327.
Command (m for help): n # new新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p # 选择主分区
Partition number (1-4, default 1): 1 # 分区编号,直接回车,选择默认的1就好
First sector (2048-1048575999, default 2048): # 设置起始扇区,直接回车,选择默认的
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): # 设置结束扇区,直接回车,默认选择到磁盘的最后一个扇区。
Using default value 1048575999 # 默认分区的容量就是整个磁盘的容量
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): p # print打印当前设置好的磁盘信息(注意,此时还没物理生效)
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x1c98c327
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048575999 524286976 83 Linux
Command (m for help): t # 输入t,修改磁盘格式为LVM格式
Selected partition 1
Hex code (type L to list all codes): 8e # 输入8e,8e代表LVM格式
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p # 再次打印磁盘信息
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x1c98c327
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048575999 524286976 8e Linux LVM
Command (m for help): w # w开始保存设置的磁盘分区信息,此时才是真正作用生效了。
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@icoolkj ~]# fdisk -l # fdisk -l 重新查看一下当前磁盘信息
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000ca465
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 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 /dev/mapper/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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 /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x1c98c327
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048575999 524286976 8e Linux LVM
[root@icoolkj ~]#
4.创建pv
创建LVM概念中的物理卷。
注意:这里要选带数字编号的磁盘,这里的/dev/vdb1就是上面我们用fdisk创建好的磁盘分区,1表示我们的分区编号,上面设置的是1,所以这里就是vdb1
[root@icoolkj ~]# pvscan # 查看当前系统上的物理卷信息
PV /dev/vda2 VG centos lvm2 [<49.00 GiB / 4.00 MiB free]
Total: 1 [<49.00 GiB] / in use: 1 [<49.00 GiB] / in no VG: 0 [0 ]
[root@icoolkj ~]# pvcreate /dev/vdb1 # 创建物理卷,注意这里的磁盘尾号vdb1必须带数字
Physical volume "/dev/vdb1" successfully created.
[root@icoolkj ~]# pvscan # 再次查看当前系统上的物理卷信息
PV /dev/vda2 VG centos lvm2 [<49.00 GiB / 4.00 MiB free]
PV /dev/vdb1 lvm2 [<500.00 GiB]
Total: 2 [<549.00 GiB] / in use: 1 [<49.00 GiB] / in no VG: 1 [<500.00 GiB]
[root@icoolkj ~]#
5.将pv加入vg组,扩容vg
pv是物理卷,vg是卷组,多个pv组成一个vg,然后vg里面去构建逻辑卷组lv
5.1、则创建新的vg组【如果系统没有vg 或者需要创建新的】
[root@icoolkj ~]# vgscan # 查看系统中存在的LVM卷组
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
[root@icoolkj ~]# vgcreate vgdata /dev/vdb1 # 创建vg,vg名字设置为vgdata,/dev/vdb1是我们上面创建的pv卷的名字
Volume group "vgdata" successfully created
[root@icoolkj ~]# vgscan # 再次查看系统中存在的LVM卷组
Reading volume groups from cache.
Found volume group "vgdata" using metadata type lvm2
Found volume group "centos" using metadata type lvm2
[root@icoolkj ~]#
[root@icoolkj ~]# vgdisplay # 再次查看系统中各卷组的详细信息
--- Volume group ---
VG Name vgdata
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 <500.00 GiB
PE Size 4.00 MiB
Total PE 127999
Alloc PE / Size 0 / 0
Free PE / Size 127999 / <500.00 GiB
VG UUID 4eAgqt-SG3h-73gK-kIv2-kerR-RRXP-Tjc2Zt
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID sqCM5T-M2CY-szNH-3jS4-WkIs-lbqZ-sduWU8
[root@icoolkj ~]#
5.2、创建新的lV【如果LV逻辑卷不存在,则创建】
[root@icoolkj ~]# lvscan
ACTIVE '/dev/centos/swap' [<3.88 GiB] inherit
ACTIVE '/dev/centos/root' [<45.12 GiB] inherit
[root@icoolkj ~]# lvcreate -n lvdata -L 500G vgdata # 一般无法用到500G,所以稍微小一点就好了
Volume group "vgdata" has insufficient free space (127999 extents): 128000 required.
[root@icoolkj ~]# lvcreate -n lvdata -L 499G vgdata
Logical volume "lvdata" created.
[root@icoolkj ~]# lvscan
ACTIVE '/dev/vgdata/lvdata' [499.00 GiB] inherit
ACTIVE '/dev/centos/swap' [<3.88 GiB] inherit
ACTIVE '/dev/centos/root' [<45.12 GiB] inherit
[root@icoolkj ~]#
[root@icoolkj ~]# mkfs.ext4 /dev/vgdata/lvdata # 格式化该逻辑分区
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32702464 inodes, 130809856 blocks
6540492 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
3992 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@icoolkj ~]#
5.3、挂载
[root@icoolkj ~]# lvscan
ACTIVE '/dev/vgdata/lvdata' [499.00 GiB] inherit
ACTIVE '/dev/centos/swap' [<3.88 GiB] inherit
ACTIVE '/dev/centos/root' [<45.12 GiB] inherit
[root@icoolkj ~]# mkdir /data # 创建挂载的目录
[root@icoolkj ~]# mount /dev/vgdata/lvdata /data/ # 开始挂载
[root@icoolkj ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 46G 1.7G 44G 4% /
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 16G 26M 16G 1% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 145M 870M 15% /boot
tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/mapper/vgdata-lvdata ext4 492G 73M 467G 1% /data
# 加入开机自动挂载配置
[root@icoolkj ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 26 14:55:48 2019
#
# 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=806c808a-d433-4bc3-b879-d5602821fd97 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/vgdata/lvdata /data ext4 defaults 0 0
6.列出所有的块设备
[root@icoolkj ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 49G 0 part
├─centos-root 253:0 0 45.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
vdb 252:16 0 500G 0 disk
└─vdb1 252:17 0 500G 0 part
└─vgdata-lvdata 253:2 0 499G 0 lvm /data
[root@icoolkj ~]#
到此,LVM磁盘创建完成。