1. 扩展虚拟机磁盘空间
Vm虚拟机下Linux扩展原有磁盘空间,10G
10G的基础上不能满足需求,只好进行磁盘扩展。
调整到合适的磁盘空间
需注意以下几点: linux只能扩展磁盘容量而不能减小, 所填写的容量为总容量,即包含已分区的磁盘。
2.查看、创建系统分区
- 启动虚假机,查看磁盘分区
[root@node1 ~]
总磁盘大小32.2GB,其中磁盘分了sda1,sda2两个分区。Linux LVM为虚拟机分区约有9GB磁盘空间。
- 创建新分区
[root@node1 ~]
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
3.执行分区创建
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 (20971520-62914559, default 20971520):
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-62914559, default 62914559):
Using default value 62914559
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
4.重新查看分区
我们的新建分区/dev/sda3
[root@node1 ~]
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x00009cb6
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 20971519 9436160 8e Linux LVM
/dev/sda3 20971520 62914559 20971520 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
Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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
4.查看文件系统格式、分区格式化
df -T -h
mkfs.xfs /dev/sda3
lvm
lvm> pvcreate /dev/sda3
WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
lvm> vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <9.00 GiB
PE Size 4.00 MiB
Total PE 2303
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 0 / 0
VG UUID zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
LV Write Access read/write
LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
LV Status available
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID 2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
LV Write Access read/write
LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
LV Status available
LV Size <8.00 GiB
Current LE 2047
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
PV Status allocatable
Total PE / Free PE 2303 / 0
lvm> vgextend centos /dev/sda3
Volume group "centos" successfully extended
可以查看到新加入的物理卷sda3
通过vgdisplay再次查看,可以发现Volume group中多了Free PE / Size 5119 / <20.00 GiB一行记录
lvm> vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 5119 / <20.00 GiB
VG UUID zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
LV Write Access read/write
LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
LV Status available
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID 2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
LV Write Access read/write
LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
LV Status available
LV Size <8.00 GiB
Current LE 2047
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
PV Status allocatable
Total PE / Free PE 2303 / 0
PV Name /dev/sda3
PV UUID V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
PV Status allocatable
Total PE / Free PE 5119 / 5119
lvm> lvextend -l+5119 /dev/mapper/centos-root
Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 27.99 GiB (7166 extents).
Logical volume centos/root successfully resized.
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2303
Free PE 0
Allocated PE 2303
PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 20.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 5119
Free PE 0
Allocated PE 5119
PV UUID V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
lvm>quit
3.文件系统的扩容
以上只是做成了卷扩容,接下来做文件系统的真正扩容
df -h
centos7执行执行扩容
xfs_growfs /dev/mapper/centos-root
再次查看磁盘使用情况
df -h
可以看见根目录下的磁盘空间已经扩展为28G了
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)