1、查看硬盘使用情况
df -h
--------------------
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 12K 3.9G 1% /dev/shm
tmpfs 3.9G 14M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 26G 17G 17G 100% /
/dev/sda1 1014M 233M 782M 23% /boot
tmpfs 781M 0 781M 0% /run/user/0
发现/dev/mapper/centos-root已使用100%
2、在VMware Workstation中设置扩容
选择到虚拟机,右键设置,选择硬盘,扩容,输入容量。
3、新建分区
查看分区情况
fdisk -l
------------------
Disk /dev/sda: 42.9 GB, 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
Disk label type: dos
Disk identifier: 0x000b9f67Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 62914559 10485760 8e Linux LVMDisk /dev/mapper/centos-root: 27.9 GB, 27913093120 bytes, 54517760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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/sda: 42.9 GB说明扩容成功
现在进行分区操作
fdisk /dev/sda #上面查询出的挂载的设备号
查看分区情况
格式化分区
重启电脑
4、扩容主分区
查看虚拟卷组名
vgdisplay
--------------- Volume group ---VG Name centosSystem ID Format lvm2Metadata Areas 2Metadata Sequence No 5VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 2Act PV 2VG Size 28.99 GiBPE Size 4.00 MiBTotal PE 7422Alloc PE / Size 7167 / <28.00 GiBFree PE / Size 255 / 1020.00 MiBVG UUID 27c394-CgrW-lNJT-7KNZ-Mkkr-IXFL-EL2vuB
进入lvm管理
lvm
lvm> pvcreate /dev/sda4 #刚才新建分区Physical volume "/dev/sda4" successfully created.
lvm> vgextend centos /dev/sda4 #centos通过上面命令查询出来的VG NameVolume group "centos" successfully extended
lvm> lvextend -L +10G /dev/mapper/centos-root #扩展已有卷的容量
以上是卷扩了容量,执行以下命令来文件扩容
resize2fs /dev/mapper/centos-root
------------------------------
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
出现了错误
查询文件系统格式为xfs
cat /etc/fstab | grep centos-root
/dev/mapper/centos-root / xfs defaults 0 0
使用xfs命令扩容
xfs_growfs /dev/mapper/centos-root
----------------------------
meta-data=/dev/mapper/centos-root isize=512 agcount=7, agsize=1113856 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=6814720, 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 6814720 to 9436160
查询
df -h
----------------------
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 12K 3.9G 1% /dev/shm
tmpfs 3.9G 14M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 36G 17G 20G 46% /
/dev/sda1 1014M 233M 782M 23% /boot
tmpfs 781M 0 781M 0% /run/user/0
配置成功