实际操作如下:
[root@0003 ~]# df -h (查看当前磁盘使用情况)
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 44G 19G 26G 43% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 9.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 209M 806M 21% /boot
/dev/loop1 11G 11G 0 100% /mnt
tmpfs 1.6G 12K 1.6G 1% /run/user/985
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@0003 ~]#
[root@0003 ~]#
[root@0003 ~]# yum -y install parted (安装parted)
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
Centos7.6 | 3.6 kB 00:00:00
(1/2): Centos7.6/group_gz | 166 kB 00:00:00
(2/2): Centos7.6/primary_db | 6.0 MB 00:00:00
Package parted-3.1-29.el7.x86_64 already installed and latest version
Nothing to do
[root@0003 ~]#
[root@0003 ~]# lsblk (查看磁盘设备)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 49G 0 part
├─centos-root 253:0 0 44G 0 lvm /
└─centos-swap 253:1 0 5G 0 lvm [SWAP]
vdb 252:16 0 200G 0 disk
loop0 7:0 0 4.3G 0 loop /mnt
loop1 7:1 0 10G 0 loop /mnt
[root@0003 ~]#
[root@0003 ~]# parted /dev/vdb (给新硬盘分区并打上lvm标签,视实际情况确定分区)
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt (设置分区类型为gpt)
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes (确认继续下一步)
(parted) mkpart extended 0% 100% (扩展分区extended,主分区primary 并使用整个硬盘空间)
(parted) p (查看分区情况)
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 215GB 215GB extended
(parted) toggle 1 lvm (将1分区打上lvm标签)
(parted) p (查看分区情况)
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 215GB 215GB extended lvm
(parted) quit (退出)
Information: You may need to update /etc/fstab.
[root@0003 ~]# partprobe (不重启读取分区信息)
[root@0003 ~]#
[root@0003 ~]# fdisk -l (查看新的分区情况)
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000af3ef
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 104857599 51379200 8e Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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: gpt
Disk identifier: EA31CBB9-8C39-4EFA-8C8C-9DE7091BEFC7
# Start End Size Type Name
1 2048 419428351 200G Linux LVM extended
Disk /dev/mapper/centos-root: 47.2 GB, 47240445952 bytes, 92266496 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/centos-swap: 5368 MB, 5368709120 bytes, 10485760 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/loop0: 4588 MB, 4588568576 bytes, 8962048 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: 0x15a0523f
Device Boot Start End Blocks Id System
/dev/loop0p1 * 0 8962047 4481024 0 Empty
/dev/loop0p2 2396 19803 8704 ef EFI (FAT-12/16/32)
Disk /dev/loop1: 10.7 GB, 10743709696 bytes, 20983808 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: 0x5321f7e0
Device Boot Start End Blocks Id System
/dev/loop1p1 * 0 20983807 10491904 0 Empty
/dev/loop1p2 5688 23095 8704 ef EFI (FAT-12/16/32)
[root@0003 ~]#
[root@0003 ~]# pvcreate /dev/sda1 (错误示例,需要按照实际分区名来操作)
Device /dev/sda1 not found.
[root@0003 ~]#
[root@0003 ~]#
[root@0003 ~]# vgdisplay (显示VG名称为:centos)
--- Volume group ---
VG Name centos
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 <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12543 / <49.00 GiB
Free PE / Size 0 / 0
VG UUID b3j9qA-lGWu-22NJ-TYwA-a9fr-Ig3y-U2jObn
[root@0003 ~]#
[root@0003 ~]# pvcreate /dev/vdb1 (将分出来的分区转为物理卷)
Physical volume "/dev/vdb1" successfully created.
[root@0003 ~]#
[root@0003 ~]# vgextend centos /dev/vdb1 (将vdb1分区加入到centos卷组)
Volume group "centos" successfully extended
[root@0003 ~]#
[root@0003 ~]#
[root@0003 ~]# lvextend -l +100%FREE /dev/mapper/centos-root (将所有空间分配给centos-root)
Size of logical volume centos/root changed from <44.00 GiB (11263 extents) to 243.99 GiB (62462 extents).
Logical volume centos/root successfully resized.
[root@0003 ~]#
[root@0003 ~]# xfs_growfs /dev/mapper/centos-root (同步文件系统,使扩容生效)
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2883328 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11533312, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5631, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11533312 to 63961088
[root@0003 ~]#
[root@0003 ~]# lsblk (查看分区情况)
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 49G 0 part
├─centos-root 253:0 0 244G 0 lvm /
└─centos-swap 253:1 0 5G 0 lvm [SWAP]
vdb 252:16 0 200G 0 disk
└─vdb1 252:17 0 200G 0 part
└─centos-root 253:0 0 244G 0 lvm /
loop0 7:0 0 4.3G 0 loop /mnt
loop1 7:1 0 10G 0 loop /mnt
[root@0003 ~]#
[root@0003 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 244G 19G 226G 8% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 9.9M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 1014M 209M 806M 21% /boot
/dev/loop1 11G 11G 0 100% /mnt
tmpfs 1.6G 12K 1.6G 1% /run/user/985
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@0003 ~]#