Extended centos7.4 virtual machine disk size

Assigned virtual machine disk 40GB, only the actual system partition 20GB, the need to manually extend 40GB, operation is as follows:

 

View disk information (confirming primary partition only 17GB):
[root @ the Test-web1 ~] # df -h
Filesystem Size Used Avail the Use% Mounted ON
/ dev / Mapper / CentOS-root 17G 3.2G 14G 19% /
devtmpfs 1.9G 0 0% 1.9G / dev
tmpfs 1.9G 1.9G 0 0% / dev / SHM
tmpfs 8.8M 1.9G 1.9G. 1% / RUN
tmpfs 1.9G 1.9G 0 0% / SYS / FS / a cgroup
/ dev / Vdal of 10-14m for Style 179M % 18 is / Boot
tmpfs 380M 380M 12K. 1% / RUN / User / 42 is
tmpfs 380M 0 380M 0% / RUN / User / 0

 

View the total disk size 42.9GB , actually allocated only about 20GB, 20GB can be extended as well:
[root @ the Test-web1 ~] # fdisk the -l

Disk /dev/vda: 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: 0x000bb34f

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 41943039 19921920 8e Linux LVM

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/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

 

Primary new disk partitions, np sequentially input carriage Return Return W:
[Test-web1 the root @ ~] # the fdisk / dev / VDA
available for purchase to the 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): 回车
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): 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.

 

View disk information, adds a / dev / vda3:
[root @ the Test-web1 ~] # fdisk the -l

Disk /dev/vda: 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: 0x000bb34f

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 41943039 19921920 8e Linux LVM
/dev/vda3 41943040 83886079 20971520 83 Linux

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/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

 

挂载分区:
[root@test-web1 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.


[root@test-web1 ~]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.


[root@test-web1 ~]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2


[root@test-web1 ~]# vgextend centos /dev/vda3
Volume group "centos" successfully extended


[root@test-web1 ~]# lvextend -L +19G /dev/mapper/centos-root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <36.00 GiB (9215 extents).
Logical volume centos/root successfully resized.


[root@test-web1 ~]# xfs_growfs /dev/mapper/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 9436160

 

Confirm that the partition size becomes:
[Test-web1 the root @ ~] # DF -H
the Filesystem Size Used Avail the Use% Mounted ON
/ dev / Mapper / CentOS the root-36G 3.2G 33G. 9% /
devtmpfs 1.9G 1.9G 0 0% / dev
tmpfs 1.9G 1.9G 0 0% / dev / SHM
tmpfs 8.8M 1.9G 1.9G. 1% / RUN
tmpfs 1.9G 1.9G 0 0% / SYS / FS / a cgroup
/ dev / Vdal 18 is for Style 179M% of 10-14m / Boot
12K 380M 380M. 1% tmpfs / RUN / User / 42 is
tmpfs 380M 0 380M 0% / RUN / User / 0

Guess you like

Origin www.cnblogs.com/lavezhang/p/11542050.html