本来在搭建集群,是用的vmware虚拟机,centos7,开始只分配了30G的硬盘,后来安装节点时候报磁盘空间不足,所以考虑扩展虚拟机系统硬盘空间,
1. 关闭虚拟机,虚拟机设置->硬盘->磁盘实用工具->扩展
原来的linux硬盘只有30G,扩展到100G,根据自己实际情况填写就行了,
2. 对新增加的硬盘进行分区、格式化【centos的root用户】
2.1对新增加的硬盘进行分区
输入命令:fdisk /dev/sda (因为上面选择的是扩展,即在原有的硬盘sda进行扩展,所以增加空间的硬盘是/dev/sda)
按照提示输入:
[root@centos7dev~]# fdisk /dev/sda
Welcome to fdisk(util-linux 2.23.2).
Changes will remainin memory only, until you decide to write them.
Be careful beforeusing the write command.
Command (m for help):p (查看已分区数量 有两个/dev/sda1 /dev/sda2))
Disk /dev/sda: 107.4GB, 107374182400 bytes, 209715200 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:0x0003f424
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 62914559 30944256 8e Linux LVM(原来的30G硬盘)
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(分区号选3)
First sector (62914560-209715199, default 62914560):Entre(回车,选择默认起始扇区)
Using default value62914560
Last sector, +sectors or +size{K,M,G} (62914560-209715199, default209715199): Entre(回车,选择默认结束扇区)
Using default value209715199
Partition 3 of typeLinux and of size 70 GiB is set
Command (m for help):t (t修改分区类型)
Partition number (1-3, default 3):3(选分区3)
Hex code (type L to list all codes):8e(修改为LVM(8es就是上面p选项查看到的id)LVM是 LogicalVolume Manager(逻辑卷管理))
Changed type ofpartition 'Linux' to 'Linux LVM'
Command (m for help):w (保存)
The partition tablehas been altered!
Calling ioctl() tore-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 usedat
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos7dev~]# partprobe (根据上面的提示输入)
[root@centos7dev~]# reboot (重启linux)
2.2对新增加的硬盘进行格式化
重启linux后格式化分区:mkfs.xfs /dev/sda3(sda3是刚才分的区,另外注意:格式成什么文件系统要使用df -Th命令先查看你当前linux系统使用的是什么文件系统,我这边看到的打印内容是:
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 28G 12G 17G 42% /
所以使用mkfs.xfs命令
2.3.添加新LVM到已有的LVM组,实现扩容
命令lvm 进入lvm管理:
lvm> pvcreate /dev/sda3初始化刚才的分区
lvm> vgdisplay 查看卷组(Volumegroup)名称
--- Volumegroup ---
VGName centos
… … …
lvm> vgextend centos /dev/sda3 将初始化过的分区加入到虚拟卷组centos
lvm> lvdisplay 查看逻辑卷(Logical volume)情况,可以看到新建的70G逻辑卷
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 29.51 GiB / not usable 3.00 MiB
Allocatable yes
… … …
"/dev/sda3" is a new physicalvolume of "70.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 70.00 GiB
Allocatable NO
… … …
lvm> lvextend -l +70G /dev/centos/root 增加物理卷到根目录,从上面的打印信息中可以看到根目录是在/dev/centos/root
3. 以上只是卷扩容了,下面是文件系统的真正扩容,输入以下命令:
xfs_growfs /dev/mapper/centos-root
4. 结果查看
[root@centos7dev~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 97G 12G 86G 12% /