一、问题
我创建了一个 VMware 虚拟机用来安装 OpenStack Kolla,由于创建虚拟机时仅给根目录分配 8G 的空间,后续明显不够用,想再扩展 10G 的空间。
查看当前磁盘
[root@kolla-queens ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000d78d5
Device Boot Start End Blocks Id System
/dev/sda1 2048 20971519 10484736 8e Linux LVM
/dev/sda2 20971520 41943039 10485760 83 Linux
Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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
......
二、解决
由于 /dev/sda1
分区是 LVM 类型,可以进行扩展
首先,给虚拟机加块 10G 大小硬盘,然后重启
看到已经存在盘 /dev/sdb
了,大小10.7 GB
[root@kolla-queens ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000d78d5
Device Boot Start End Blocks Id System
/dev/sda1 2048 20971519 10484736 8e Linux LVM
/dev/sda2 20971520 41943039 10485760 83 Linux
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
Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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
......
创建分区 /dev/sdb
,注意选择 8e 也即是 LVM 类型
# 后面是我写的注释
[root@kolla-queens ~]# 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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf9d73537.
Command (m for help): n # 输入命令n,建立一个新的分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p # 输入 p,或者直接按回车
Partition number (1-4, default 1): 1 # 输入 1,或者直接按回车
First sector (2048-20971519, default 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 # 输入命令 t,定义新分区的类型
Selected partition 1
Hex code (type L to list all codes): 8e # 输入 8e,8e是Linux LVM类型的代码
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w # 输入命令 w 完成修改
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
看到已经存在分区 /dev/sdb1
了
[root@kolla-queens ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000d78d5
Device Boot Start End Blocks Id System
/dev/sda1 2048 20971519 10484736 8e Linux LVM
/dev/sda2 20971520 41943039 10485760 83 Linux
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: 0xf9d73537
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 8e Linux LVM
Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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
......
创建 PV
[root@kolla-queens ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
查看 LV,显示 LV Path 为 /dev/centos/root
,VG Name 为 centos
[root@kolla-queens ~]# lvdisplay
......
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID eh3XHa-w5Hy-pbGA-qqbi-p4j6-H5Gl-LdBRlu
LV Write Access read/write
LV Creation host, time localhost, 2016-09-13 23:42:05 +0800
LV Status available
# open 1
LV Size <8.00 GiB
Current LE 2047
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
扩展 VG centos
[root@kolla-queens ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
扩展 LV /dev/centos/root
[root@kolla-queens ~]# lvextend /dev/centos/root /dev/sdb1
Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 17.99 GiB (4606 extents).
Logical volume centos/root successfully resized.
如果系统是用的XFS文件系统,需要要运行以下命令:
xfs_growfs /dev/centos/root
如果系统不是使用XFS文件系统,需要运行以下命令:
resize2fs /dev/centos/root
我这是xfs文件系统
所以运行
[root@kolla-queens ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=2096128, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 2096128 to 4716544
查看磁盘空间信息,/dev/mapper/centos-root
已经扩充到 18 G了
[root@kolla-queens ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 18G 2.0G 16G 12% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.7M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 781M 0 781M 0% /run/user/0