1,新创建一块硬盘
[root@centos7 ~]#
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
├─sda1 8:1 0 200M 0 part /boot
└─sda2 8:2 0 9.8G 0 part
├─centos-root 253:0 0 9.3G 0 lvm /
└─centos-swap 253:1 0 512M 0 lvm [SWAP]
sdb 8:16 0 3G 0 disk
sr0 11:0 1 1024M 0 rom
[root@centos7 ~]#
[root@centos7 ~]#
2,分区硬盘,创建一个扩展分区,然后分出3个逻辑分区
[root@centos7 ~]#
[root@centos7 ~]#
[root@centos7 ~]# fdisk /dev/sdb
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 0x1f2362c8.
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 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: 0x1f2362c8
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
First sector (2048-6291455, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-6291455, default 6291455):
Using default value 6291455
Partition 1 of type Extended and of size 3 GiB is set
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 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: 0x1f2362c8
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6291455 3144704 5 Extended
Command (m for help):n
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 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: 0x9929aef0
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6291455 3144704 5 Extended
/dev/sdb5 4096 106495 51200 83 Linux
/dev/sdb6 108544 210943 51200 83 Linux
/dev/sdb7 212992 315391 51200 83 Linux
Command (m for help): t
Partition number (1,5-7, default 7): 7
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: 3221 MB, 3221225472 bytes, 6291456 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: 0x9929aef0
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6291455 3144704 5 Extended
/dev/sdb5 4096 106495 51200 83 Linux
/dev/sdb6 108544 210943 51200 83 Linux
/dev/sdb7 212992 315391 51200 8e Linux LVM
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 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: 0x9929aef0
Device Boot Start End Blocks Id System
/dev/sdb1 2048 6291455 3144704 5 Extended
/dev/sdb5 4096 106495 51200 8e Linux LVM
/dev/sdb6 108544 210943 51200 8e Linux LVM
/dev/sdb7 212992 315391 51200 8e Linux LVM
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]#
---------------------------------------------------------------------上面操作是做好物理分区--------------------------
3,接下来做PV
[root@centos7 ~]# pvcreate /dev/sdb5 /dev/sdb6 /dev/sdb7
Physical volume "/dev/sdb5" successfully created.
Physical volume "/dev/sdb6" successfully created.
Physical volume "/dev/sdb7" successfully created.
[root@centos7 ~]#
4,接下来创建VG,vg绑定PV
[root@centos7 ~]# vgcreate vg1_demo /dev/sdb5 /dev/sdb6
Volume group "vg1_demo" successfully created
[root@centos7 ~]#
vg创建好了后就可以把他当成一块硬盘。
5,vg 创建好了,我们就把他当作成一块硬盘,然后我们用lvcreate 对他分区
查看vg的简易信息
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 9.80g 0
vg1_demo 2 0 0 wz--n- 96.00m 96.00m
[root@centos7 ~]#
[root@centos7 ~]# lvcreate -n lv1 -L +30M vg1_demo
Rounding up size to full physical extent 32.00 MiB
Logical volume "lv1" created.
[root@centos7 ~]#
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 9.80g 0
vg1_demo 2 1 0 wz--n- 96.00m 64.00m
[root@centos7 ~]#
6,接着对LV格式化
[root@centos7 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 9.30g
swap centos -wi-ao---- 512.00m
lv1 vg1_demo -wi-a----- 32.00m
[root@centos7 ~]#
[root@centos7 ~]# mkfs.ext4 /dev/vg1_demo/lv1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
8192 inodes, 32768 blocks
1638 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33554432
4 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 ~]#
[root@centos7 ~]#
7,挂载
[root@centos7 ~]# mkdir /app
[root@centos7 ~]#
[root@centos7 ~]# mount /dev/vg1_demo/lv1 /app
[root@centos7 ~]#
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 9.3G 1.1G 8.3G 12% /
devtmpfs 982M 0 982M 0% /dev
tmpfs 993M 0 993M 0% /dev/shm
tmpfs 993M 8.7M 984M 1% /run
tmpfs 993M 0 993M 0% /sys/fs/cgroup
/dev/sda1 197M 103M 95M 53% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/vg1_demo-lv1 27M 779K 24M 4% /app
[root@centos7 ~]#
8,重启主机,挂载会丢失,需要写入挂载信息到/etc/fstab 文件。
查看pv信息:pvs
查看vg信息:vgs
查看lv信息:lvs