还是以上次添加的新盘为例: [root@cs-1 ~]# fdisk -l Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe4bb91de Device Boot Start End Blocks Id System -------------------------------------------------------------------- 首先分区 并将分区设置为LVM 类型 并保存. #因为磁盘大小没有超过2T所以使用fdisk即可 [root@cs-1 ~]# 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. 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-20971519, default 2048): // 回车,默认从2048开始往下分 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): //回车,将所有空间都给第一个分区 Using default value 20971519 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 // 改为 Linux LVM类型 Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): w // 保存 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@cs-1 ~]# fdisk -l // 查看所有磁盘信息 Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe4bb91de Device Boot Start End Blocks Id System /dev/sdb1 2048 20971519 10484736 8e Linux LVM // ⬅ 类型为: 为什么是 分区类型要选择 8e? 因为8e 是 linux lvm 类型的的标识符,所以要输入 8e Command (m for help): t // 设置分区类型 Selected partition 1 Hex code (type L to list all codes): 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 C: 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 eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e Hidden W95 FAT1 80 Old Minix ----------------------- 【创建物理卷】 查看可以作为物理卷的设备 [root@cs-1 ~]# lvmdiskscan /dev/centos/root [ <17.51 GiB] /dev/centos/swap [ 2.00 GiB] /dev/sda2 [ 500.00 MiB] /dev/sda3 [ <19.51 GiB] LVM physical volume /dev/sdb1 [ <10.00 GiB] // 可以看到 刚刚划分的linux lvm 类型的设备 2 disks 2 partitions 0 LVM physical volume whole disks 1 LVM physical volume 创建物理卷 [root@cs-1 ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. 查看物理卷状态 pvs 或 pvdisplay 查看物理卷的属性 [root@cs-1 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda3 centos lvm2 a-- <19.51g 0 /dev/sdb1 lvm2 --- <10.00g <10.00g [root@cs-1 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name centos PV Size <19.51 GiB / not usable 2.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4994 Free PE 0 Allocated PE 4994 PV UUID SHKiSF-g13G-fJAG-tpsA-Emda-kSUu-Jz3HQe "/dev/sdb1" is a new physical volume of "<10.00 GiB" --- NEW Physical volume --- // 新的物理卷 PV Name /dev/sdb1 VG Name PV Size <10.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID S29Y28-zKCa-ic6R-leV4-3O7J-shPb-L9O2ag 【为根目录扩容】 查看卷组 [root@cs-1 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <19.51g 0 // 可以看到根目录 物理卷组名称为 centos 将/dev/sdb1 物理卷 加入根目录的理卷组中 [root@cs-1 ~]# vgextend centos /dev/sdb1 Volume group "centos" successfully extended [root@cs-1 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 29.50g <10.00g // 可以看到centos物理卷组的大小已经从19.5扩容到了29.5. // 但是此时只是将物理卷加入到了物理卷组中,还没有给根空间扩容 // Free可以看到这10G的空间还未分配 [root@cs-1 ~]# vgdisplay // 查看物理卷属性信息 --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 29.50 GiB PE Size 4.00 MiB Total PE 7553 Alloc PE / Size 4994 / <19.51 GiB Free PE / Size 2559 / <10.00 GiB // 可以看到还有空间没有被分配 VG UUID lS5NF2-9EYz-xCK0-Uow4-xuTC-v1p0-ehN6e0 从卷组中把添加的空间给到根逻辑卷,并查看根逻辑卷的可用空间 [root@cs-1 ~]# lvextend -l +100%FREE /dev/mapper/centos-root Size of logical volume centos/root changed from <17.51 GiB (4482 extents) to 27.50 GiB (7041 extents). Logical volume centos/root successfully resized. 查看结果: [root@cs-1 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 2 2 0 wz--n- 29.50g 0 // 对比上述信息可以看到 根空间以被扩容到了29.50G 而Free未分配的空间以经为0. [root@cs-1 ~]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 29.50 GiB PE Size 4.00 MiB Total PE 7553 Alloc PE / Size 7553 / 29.50 GiB // 以分配空间被扩容了 Free PE / Size 0 / 0 // 为分配空间以归0 VG UUID lS5NF2-9EYz-xCK0-Uow4-xuTC-v1p0-ehN6e0 /dev/mapper/centos-root逻辑卷实际可用空间 root@cs-1 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 27.50g 注: 到这里还没有完成根空间的扩容, 因为文件系统并不会自动同步所以我们要手动使扩容生效 [root@cs-1 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 18G 4.5G 13G 26% / 手动使扩容生效 [root@cs-1 ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1147392 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=4589568, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 4589568 to 7209984 [root@cs-1 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 28G 4.5G 23G 17% / 至此, 扩容完成