1. 创建/dev/sdb5分区
[root@Server ~]# fdisk -l //查看可用磁盘
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: gpt
Disk identifier: 46A5EB63-2865-4CEB-9610-34486A1BF0B4
Device Start End Sectors Size Type
/dev/sda1 2048 1230847 1228800 600M EFI System
/dev/sda2 1230848 3327999 2097152 1G Linux filesystem
/dev/sda3 3328000 83884031 80556032 38.4G Linux LVM
Disk /dev/mapper/cl-root: 36.3 GiB, 39019610112 bytes, 76210176 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/cl-swap: 2.1 GiB, 2222981120 bytes, 4341760 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/sdb: 100 GiB, 107374182400 bytes, 209715200 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@Server ~]# fdisk /dev/sdb //创建/dev/sdb5分区,并设置分区类型为Linux LVM
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0x0ac19ae2.
Command (m for help): n //创建新分区
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): e //选择创建扩展分区
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199):
Created a new partition 1 of type 'Extended' and of size 100 GiB.
Command (m for help): n //创建新分区
All space for primary partitions is in use.
Adding logical partition 5
First sector (4096-209715199, default 4096):
Last sector, +sectors or +size{K,M,G,T,P} (4096-209715199, default 209715199):
Created a new partition 5 of type 'Linux' and of size 100 GiB.
Command (m for help): p //查看分区信息
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x0ac19ae2
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 209715199 209713152 100G 5 Extended
/dev/sdb5 4096 209715199 209711104 100G 83 Linux
Command (m for help): t //设置分区类型
Partition number (1,5, default 5):
Hex code (type L to list all codes): L //查看分区类型列表
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto
1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep
1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT
Hex code (type L to list all codes): 8e //选择分区类型为8e(Linux LVM)
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): p //查看分区信息
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x0ac19ae2
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 209715199 209713152 100G 5 Extended
/dev/sdb5 4096 209715199 209711104 100G 8e Linux LVM
Command (m for help): w //保存配置
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
2. 创建PV
[root@Server ~]# pvcreate /dev/sdb5 //创建/dev/sdb5为新的PV
Physical volume "/dev/sdb5" successfully created.
[root@Server ~]# pvdisplay //查看PV信息
--- Physical volume ---
PV Name /dev/sdb5
VG Name datavg
PV Size <100.00 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25599
Free PE 0
Allocated PE 25599
PV UUID BAsyjg-PVIe-GjNo-d55M-iBi9-X6jn-KlajeP
--- Physical volume ---
PV Name /dev/sda3
VG Name cl
PV Size 38.41 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 9833
Free PE 0
Allocated PE 9833
PV UUID BHxOnt-YIaL-7wir-0Sip-VVS2-Ukw9-eKit3w
3. 创建VG
[root@Server ~]# vgcreate datavg /dev/sdb5 //创建datavg为新的VG,并将/dev/sdb5加入datavg
Volume group "datavg" successfully created
[root@Server ~]# vgdisplay //查看VG信息
--- Volume group ---
VG Name datavg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <100.00 GiB
PE Size 4.00 MiB
Total PE 25599
Alloc PE / Size 25599 / <100.00 GiB
Free PE / Size 0 / 0
VG UUID AyKTSF-a0UP-9ZI4-IhVR-iLQ2-refF-nUfkMA
--- Volume group ---
VG Name cl
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 38.41 GiB
PE Size 4.00 MiB
Total PE 9833
Alloc PE / Size 9833 / 38.41 GiB
Free PE / Size 0 / 0
VG UUID 1Vdnc1-dGKd-b02C-WE9N-03sB-AmwS-yZwy8T
4. 创建LV
[root@Server ~]# lvcreate -l 100%FREE -n lvdata datavg //将datavg中的所有空闲空间创建为lvdata(新的LV)
Logical volume "lvdata" created.
[root@Server ~]# lvdisplay //查看LV信息
--- Logical volume ---
LV Path /dev/datavg/lvdata
LV Name lvdata
VG Name datavg
LV UUID xbVQC5-FnDJ-IWMY-gcIc-SFYd-MfzT-oV0jQu
LV Write Access read/write
LV Creation host, time Server, 2019-09-25 14:25:35 +0800
LV Status available
# open 1
LV Size <100.00 GiB
Current LE 25599
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID Dw3lKM-s21d-EB72-3NiP-pvJT-AXPi-Vn2ygN
LV Write Access read/write
LV Creation host, time localhost, 2019-09-25 13:19:20 +0800
LV Status available
# open 1
LV Size <36.34 GiB
Current LE 9303
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID 01Xx4H-0fJV-D1Vf-Dfec-RfwO-Divn-Fglo3Z
LV Write Access read/write
LV Creation host, time localhost, 2019-09-25 13:19:20 +0800
LV Status available
# open 2
LV Size 2.07 GiB
Current LE 530
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
5. 格式化LV
[root@Server ~]# mkfs.xfs /dev/datavg/lvdata //格式化/dev/datavg/lvdata分区为xfs格式
meta-data=/dev/datavg/lvdata isize=512 agcount=4, agsize=6553344 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=26213376, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
6. 挂载LV
[root@Server ~]# mkdir /Data //创建/Data目录
[root@Server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 981M 0 981M 0% /dev
tmpfs 995M 0 995M 0% /dev/shm
tmpfs 995M 9.2M 986M 1% /run
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/mapper/cl-root 37G 4.1G 33G 12% /
/dev/sda2 976M 144M 765M 16% /boot
/dev/sda1 599M 6.7M 593M 2% /boot/efi
tmpfs 199M 28K 199M 1% /run/user/42
tmpfs 199M 4.0K 199M 1% /run/user/0
[root@Server ~]# mount /dev/datavg/lvdata /Data/ //将/dev/datavg/lvdata分区挂载到/Data目录
[root@Server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 981M 0 981M 0% /dev
tmpfs 995M 0 995M 0% /dev/shm
tmpfs 995M 9.2M 986M 1% /run
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/mapper/cl-root 37G 4.1G 33G 12% /
/dev/sda2 976M 144M 765M 16% /boot
/dev/sda1 599M 6.7M 593M 2% /boot/efi
tmpfs 199M 28K 199M 1% /run/user/42
tmpfs 199M 4.0K 199M 1% /run/user/0
/dev/mapper/datavg-lvdata 100G 747M 100G 1% /Data
[root@Server ~]# vi /etc/fstab //配置/etc/fstab,使得系统启动时自动挂载/dev/datavg/lvdata分区
#
# /etc/fstab
# Created by anaconda on Wed Sep 25 01:19:25 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root / xfs defaults 0 0
/dev/mapper/datavg-lvdata /Data xfs defaults 0 0
UUID=0bcf7aac-1c37-4fec-9108-4a7ed9ce5c9f /boot ext4 defaults 1 2
UUID=8D69-EC05 /boot/efi vfat umask=0077,shortname=winnt 0 2
/dev/mapper/cl-swap swap swap defaults 0 0
[root@Server ~]# reboot
7. 查看挂载分区
[root@Server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 981M 0 981M 0% /dev
tmpfs 995M 0 995M 0% /dev/shm
tmpfs 995M 9.3M 986M 1% /run
tmpfs 995M 0 995M 0% /sys/fs/cgroup
/dev/mapper/cl-root 37G 4.1G 33G 12% /
/dev/mapper/datavg-lvdata 100G 747M 100G 1% /Data
/dev/sda2 976M 144M 765M 16% /boot
/dev/sda1 599M 6.7M 593M 2% /boot/efi
tmpfs 199M 28K 199M 1% /run/user/42
tmpfs 199M 4.0K 199M 1% /run/user/0
8. 查看创建的/Data目录
[root@Server ~]# cd /
[root@Server /]# ls -l
total 28
lrwxrwxrwx. 1 root root 7 May 11 08:33 bin -> usr/bin
dr-xr-xr-x. 6 root root 4096 Sep 25 14:14 boot
drwxr-xr-x 2 root root 6 Sep 25 14:25 Data
drwxr-xr-x 20 root root 3300 Sep 25 14:27 dev
drwxr-xr-x. 133 root root 8192 Sep 25 14:27 etc
drwxr-xr-x. 3 root root 19 Sep 25 13:29 home
lrwxrwxrwx. 1 root root 7 May 11 08:33 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 May 11 08:33 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 May 11 08:33 media
drwxr-xr-x. 2 root root 6 May 11 08:33 mnt
drwxr-xr-x. 2 root root 6 May 11 08:33 opt
dr-xr-xr-x 298 root root 0 Sep 25 14:27 proc
dr-xr-x---. 15 root root 4096 Sep 25 14:28 root
drwxr-xr-x 38 root root 1140 Sep 25 14:27 run
lrwxrwxrwx. 1 root root 8 May 11 08:33 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 May 11 08:33 srv
dr-xr-xr-x 13 root root 0 Sep 25 14:27 sys
drwxrwxrwt. 16 root root 4096 Sep 25 14:28 tmp
drwxr-xr-x. 12 root root 144 Sep 25 13:20 usr
drwxr-xr-x. 21 root root 4096 Sep 25 13:30 var