1. Questions
I created a VMware virtual machine to install OpenStack Kolla. Since only 8G of space was allocated to the root directory when the virtual machine was created, it was obviously not enough for later use and I wanted to expand 10G of space.
View Current Disk
[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
......
2. Solution
Since the /dev/sda1 partition is of type LVM, it can be extended
First, add a 10G hard drive to the virtual machine and restart it
You see that a disk/dev/sdb already exists, size 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
......
Create partition/dev/sdb, note that 8e is also the LVM type
#followed by my comment
[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 # Enter command n to create a new partition
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p # Enter p, or press Enter directly
Partition number (1-4, default 1): 1 # input 1,Or press Enter directly
First sector (2048-20971519, default 2048): # Press Enter Directly
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): # Press Enter Directly
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t # Enter command t to define the type of new partition
Selected partition 1
Hex code (type L to list all codes): 8e # input 8e,8e yes Linux LVM Type Code
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w # Enter command w to complete the modification
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
You see that partition/dev/sdb1 already exists
[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
......
Create PV
[root@kolla-queens ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
Look at the LV and show that the LV Path is/dev/centos/root and the VG Name is 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
Extend VG centos
[root@kolla-queens ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
Extend 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.
If your system is using an XFS file system, you need to run the following commands:
xfs_growfs /dev/centos/root
If the system is not using an XFS file system, you need to run the following command:
resize2fs /dev/centos/root
I am the xfs file system
So run
[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
Viewing disk space information, /dev/mapper/centos-root has been expanded to 18G
[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