################查看分区格式
[root@localhost ~]# fdisk -l ------需要达到的效果,分区格式为 LVM
Disk /dev/sdb: 2147.5 GB, 2147483648000 bytes
255 heads, 63 sectors/track, 261083 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x39a49a90
Device Boot Start End Blocks Id System
/dev/sdb1 1 261083 2097149166 8e Linux LVM
################修改分区格式为8e(lvm)
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x10342e9b.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n #####输入n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-97906, default 1): #####回车
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-97906, default 97906): #####回车,或者+size xxG,自己定
Using default value 97906
Command (m for help): t #####输入t
Selected partition 1
Hex code (type L to list codes): 8e #####输入8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p #####查看修改之后
Disk /dev/sdd: 805.3 GB, 805306368000 bytes
255 heads, 63 sectors/track, 97906 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x10342e9b
Device Boot Start End Blocks Id System
/dev/sdd1 1 97906 786429913+ 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 99.5G 0 part
├─VolGroup-lv_root (dm-0) 253:0 0 50G 0 lvm /
├─VolGroup-lv_swap (dm-1) 253:1 0 10G 0 lvm [SWAP]
└─VolGroup-lv_home (dm-2) 253:2 0 39.5G 0 lvm /home
sdb 8:16 0 2T 0 disk
└─sdb1 8:17 0 2T 0 part
sdc 8:32 0 450G 0 disk
└─sdc1 8:33 0 450G 0 part
sdd 8:48 0 750G 0 disk
└─sdd1 8:49 0 750G 0 part
###################
[root@localhost ~]# pvdisplay ------查看现有物理卷命令
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 99.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25474
Free PE 0
Allocated PE 25474
PV UUID 5CJGsP-wPWT-SumD-QXtC-9xQc-Gupc-41LYlF
[root@localhost ~]# pvscan ################ 扫描当前系统中所有硬盘的物理卷
PV /dev/sda2 VG VolGroup lvm2 [99.51 GiB / 0 free]
Total: 1 [99.51 GiB] / in use: 1 [99.51 GiB] / in no VG: 0 [0 ]
##############创建物理卷 PV
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 ------创建物理卷,将sdb1,sdc1和sdd1分区转成pv(这里根据现实资源)
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
Physical volume "/dev/sdd1" successfully created
[root@localhost ~]# pvs ------输出格式化的物理卷信息报表
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 a-- 1.95t 1.95t
/dev/sdc1 lvm2 a-- 449.99g 449.99g
/dev/sdd1 lvm2 a-- 750.00g 750.00g
################### 创建卷组 VG
[root@localhost ~]# vgcreate VolGroup_01 /dev/sd{b1,c1,d1} ----创建卷组VolGroup_01,并且将物理卷/dev/sd{b1,c1,d1}添加到卷组中
Volume group "VolGroup_01" successfully created
[root@localhost ~]# vgs ------查看新创建的VG
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 3 0 wz--n- 99.51g 0
VolGroup_01 3 0 0 wz--n- 3.12t 3.12t
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup_01
System ID
Format lvm2
Metadata Areas 3
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 3
Act PV 3
VG Size 3.12 TiB
PE Size 4.00 MiB
Total PE 819196
Alloc PE / Size 0 / 0
Free PE / Size 819196 / 3.12 TiB
VG UUID 13Ktx5-BiIm-9DS8-H6BH-xu39-aS0T-Gs1Hux
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 99.51 GiB
PE Size 4.00 MiB
Total PE 25474
Alloc PE / Size 25474 / 99.51 GiB
Free PE / Size 0 / 0
VG UUID Ho7xTt-MEjV-XcUm-cXtp-VA2v-NtRx-cqPS9A
################ 创建逻辑卷 LV
[root@localhost ~]# lvcreate -l 819196 -n lv_data VolGroup_01 ----819196就是从上面执行的命令”vgdisplay“ VolGroup_01 中列出所有PE数量的空间给 lv_data 使用
Logical volume "lv_data" created
-L 指定创建的LV 的大小
-l 指定创建的LV 的PE 数量
-n LV的名字
[root@localhost ~]# lvdisplay ------查看已创建的LV
--- Logical volume ---
LV Path /dev/VolGroup_01/lv_data
LV Name lv_data
VG Name VolGroup_01
LV UUID 2A0W6d-16Rv-Vc1u-34Bi-GPH8-bXWg-xgv0NN
LV Write Access read/write
LV Creation host, time localhost, 2019-02-21 17:44:57 +0800
LV Status available
# open 0
LV Size 3.12 TiB
Current LE 819196
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
############挂载文件系统
[root@localhost VolGroup_01]# mkfs.ext4 /dev/VolGroup_01/lv_data ------格式化 LV
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
209715200 inodes, 838856704 blocks
41942835 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
25600 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, 214990848, 512000000, 550731776, 644972544
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
mkdir /data ------创建挂载目录
mount /dev/VolGroup_01/lv_data /data ------挂载
[root@localhost VolGroup_01]# vi /etc/fstab ------写入fstab
/dev/mapper/VolGroup_01-lv_data /data ext4 defaults 0 0
[root@localhost VolGroup_01]# df -h ------检查磁盘是否挂载
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 1.1G 46G 3% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/mapper/VolGroup-lv_home 39G 3.8G 34G 11% /home
/dev/mapper/VolGroup_01-lv_data 3.1T 199M 3.0T 1% /data