一、修改磁盘大小
从20G扩展为40G
二、进行配置
1、修改后启动虚机发现扩容了并未生效,仍然只有18G可用
df -h
fdisk -l
2、进行配置
(1)输入fdisk /dev/sda 将虚拟磁盘的空闲空间创建为⼀个新的分区这时候会弹出对话框,需要不断选择,输入顺序n-p-3-回车-回车-t-3-8e-w
[root@node1 ~]# fdisk /dev/sda
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 (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (41943040-83886079, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
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.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@node1 ~]#
配置完成后重启虚机
(2)输入pvcreate /dev/sda3,将新分配的磁盘空间作为物理卷
[root@node1 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
(3)输入vgextend centos /dev/sda3
[root@node1 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
(4)输入lvextend /dev/mapper/centos-root /dev/sda3,用来扩展物理卷centos-root
[root@node1 ~]# lvextend /dev/mapper/centos-root /dev/sda3
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 36.99 GiB (9470 extents).
Logical volume centos/root successfully resized.
[root@node1 ~]#
(5)输入xfs_growfs /dev/centos/root,cent6的话输入resize2fs /dev/mapper/centos-root
[root@node1 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, 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 4455424 to 9697280
[root@node1 ~]#
(6)查看是否扩容成功
[root@node1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 37G 16G 22G 42% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 145M 870M 15% /boot
tmpfs 378M 0 378M 0% /run/user/0
[root@node1 ~]#
[root@node1 ~]#