1.查看硬盘信息
[root@centos7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 4G 0 part [SWAP]
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 2G 0 part
sdb 8:16 0 200G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 10G 0 disk
sr0 11:0 1 3.7G 0 rom
sr1 11:1 1 10G 0 rom
以下将使用整块sdd一个盘和sdc硬盘中的10G空间共同创建物理卷组
- 在sdc硬盘上创建10G的分区
[root@centos7 ~]#fdisk /dev/sdc
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 0xf9b7c097.
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):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdc: 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: 0xf9b7c097
Device Boot Start End Blocks Id System
/dev/sdc1 2048 20973567 10485760 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
- 在sdc1分区和sdd上分别创建物理卷(pv)
[root@centos7 ~]#pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
[root@centos7 ~]#pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
[root@centos7 ~]#pvs
PV VG Fmt Attr PSize PFree
/dev/sdc1 lvm2 --- 10.00g 10.00g
/dev/sdd lvm2 --- 10.00g 10.00g
4.创建物理卷组(vg),并将以上的pv加入其中
[root@centos7 ~]#vgcreate -s 16M testvg /dev/sdd /dev/sdc1
Volume group "testvg" successfully created
[root@centos7 ~]#vgs
VG #PV #LV #SN Attr VSize VFree
testvg 2 0 0 wz--n- <19.97g <19.97g
- 在testvgz中创建大小为5G的逻辑卷(lv)
[root@centos7 ~]#lvcreate -n testlv -L 5G testvg
Logical volume "testlv" created.
[root@centos7 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 5.00g
- 创建文件系统
[root@centos7 ~]#mkfs.ext4 /dev/testvg/testlv
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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 ~]#blkid
/dev/sda1: UUID="793af41e-2bb7-4c31-9f0f-571251920f22" TYPE="xfs"
/dev/sda2: UUID="5e9ce9bf-255f-4fc9-8ec1-2ca462b11486" TYPE="xfs"
/dev/sda3: UUID="4366d641-77fb-4f52-8115-250792bbdf64" TYPE="xfs"
/dev/sda5: UUID="17b04a6b-f52d-4407-91d8-ca6052b65974" TYPE="swap"
/dev/sda6: LABEL="/mnt/sda6" UUID="137e7f1f-126b-430d-8379-1303dc8b4482" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda7: UUID="cbd2ed35-eeaa-40d4-8244-bce465365808" TYPE="ext4"
/dev/sdc1: UUID="BVowtB-XbIj-kzzL-Qd0J-AXD6-xsMz-LYogzM" TYPE="LVM2_member"
/dev/mapper/testvg-testlv: UUID="1b99642e-c5ab-432d-9ce6-5624a8a016a2" TYPE="ext4"
/dev/sdd: UUID="adCzZS-JTc3-gTpl-e5eE-lkgA-zs0p-A4jea1" TYPE="LVM2_member"
7.在/etc/fstab配置文件中添加以下内容:
UUID=1b99642e-c5ab-432d-9ce6-5624a8a016a2 /users ext4 defaults 0 0
8.创建目标文件夹,并手动使配置文件生效
[root@centos7 ~]#mkdir /users
[root@centos7 ~]#mount -a
9.查看结果
[root@centos7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 4G 0 part [SWAP]
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 2G 0 part
sdb 8:16 0 200G 0 disk
sdc 8:32 0 20G 0 disk
└─sdc1 8:33 0 10G 0 part
sdd 8:48 0 10G 0 disk
└─testvg-testlv 253:0 0 5G 0 lvm /users
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
至此,testlv已经可以正常使用了