虚拟机LVM扩容

[root@yunpos-202-26 ~]# fdisk -l

Disk /dev/vda: 107.4 GB, 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: 0x000aeebb

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 411647 204800 83 Linux
/dev/vda2 411648 83886079 41737216 8e Linux LVM

Disk /dev/mapper/centos-root: 42.7 GB, 42735763456 bytes, 83468288 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@yunpos-202-26 ~]# fdisk /dev/vda
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.
Command (m for help): p

Disk /dev/vda: 107.4 GB, 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: 0x000aeebb

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 411647 204800 83 Linux
/dev/vda2 411648 83886079 41737216 8e Linux LVM

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 (83886080-209715199, default 83886080):
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 60 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): p

Disk /dev/vda: 107.4 GB, 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: 0x000aeebb

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 411647 204800 83 Linux
/dev/vda2 411648 83886079 41737216 8e Linux LVM
/dev/vda3 83886080 209715199 62914560 8e Linux LVM

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.
[root@yunpos-202-26 ~]# reboot

 

[root@yunpos-202-26 ~]# pvcreate /dev/vda3
Physical volume “/dev/vda3” successfully created.
[root@yunpos-202-26 ~]#
[root@yunpos-202-26 ~]#
[root@yunpos-202-26 ~]# pvdisplay
— Physical volume —
PV Name /dev/vda2
VG Name centos
PV Size 39.80 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 10189
Free PE 0
Allocated PE 10189
PV UUID dKWyTh-4rOg-Kk3k-dUoV-OfJJ-tkjS-wgCG0E

“/dev/vda3” is a new physical volume of “60.00 GiB”
— NEW Physical volume —
PV Name /dev/vda3
VG Name
PV Size 60.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID gXdKW5-rGN9-F7nD-4dzI-Rtmw-dVEw-4QMmUW

[root@yunpos-202-26 ~]# vgextend centos /dev/vda3
Volume group “centos” successfully extended
[root@yunpos-202-26 ~]# vgdisplay
— Volume group —
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size <99.80 GiB
PE Size 4.00 MiB
Total PE 25548
Alloc PE / Size 10189 / 39.80 GiB
Free PE / Size 15359 / <60.00 GiB
VG UUID StdL4h-GZ6k-D9Um-U3Os-3aSb-1txB-SfLAEn

 

[root@yunpos-202-26 ~]# lvextend -L +59G /dev/mapper/centos-root

lvextend -L +100%FREE   /dev/mapper/centos-root

 

[root@yunpos-202-26 ~]# 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.
[root@yunpos-202-26 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 40G 1009M 39G 3% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.5M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 197M 124M 74M 63% /boot
tmpfs 783M 0 783M 0% /run/user/0
[root@yunpos-202-26 ~]# resize2fs /dev/mapper/centos-root     (ext4重新识别硬盘命令)
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.

 

[root@yunpos-202-26 ~]# xfs_growfs /dev/mapper/centos-root     (xfs重新识别硬盘命令)
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2608384 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=10433536, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5094, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 10433536 to 25900032
[root@yunpos-202-26 ~]#
[root@yunpos-202-26 ~]#
[root@yunpos-202-26 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 99G 1010M 98G 1% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.5M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 197M 124M 74M 63% /boot
tmpfs 783M 0 783M 0% /run/user/0

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *