1.在虚拟机中添加硬盘
一、添加新的磁盘
1、选择 ”虚拟机设置“ 并打开 ,将光标定位在“硬盘(SCSI)” 选项上,然后点击下方的“添加“按钮
2、点击下一步
3、选择SCSI ,点击下一步
4、选择创建新虚拟机磁盘,点击下一步
5、设定磁盘容量,点击下一步
6、点击完成
2.将新建磁盘挂载到根目录下
格式化分区
#查看磁盘空间
df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 36G 1.7G 34G 5% /
/dev/sda1 497M 142M 356M 29% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
#查看未挂载磁盘
fdisk -l
1
#创建分区
fdisk /dev/sdb
#新建一个分区
n
#出现两个菜单e表示扩展分区,p表示主分区
p
#按"p"键出现提示:"Partition number (1-4): "选择主分区号
#回车,默认1
#柱面开始分区
#回车,默认开始柱面
#最后一个柱面或大小
#回车,默认柱面大小
#保存退出
w
#xfs格式化
mkfs.xfs /dev/sdb1
1
新添加硬盘分区添加为物理卷
#进入lvm
lvm
lvm> pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
#查看当前系统的物理卷(PV)情况
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 39.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 10114
Free PE 0
Allocated PE 10114
PV UUID xxxxxx-Vka6-LdS7-lrH4-iWrc-MelQ-xxxxxx
"/dev/sdb1" is a new physical volume of "<500.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <500.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID xxxxxx-1Xvh-HXnc-jV9j-byjZ-XB19-xxxxxx
#查看当前卷组情况
lvm> vgdisplay
--- 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 <39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 10114 / <39.51 GiB
Free PE / Size 0 / 0
VG UUID xxxxxx-rOjI-b0IY-h4Mu-k8Of-QPCN-xxxxxx
#分区sdb1转换为扩展分区
lvm> vgextend centos /dev/sdb1 # 注意VG Name
Volume group "centos" successfully extended
#查看当前的逻辑卷
lvm> lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID xxxxxx-m7XN-SSq2-BvtF-WuEh-e5xG-xxxxxx
LV Write Access read/write
LV Creation host, time localhost, 2020-02-26 03:13:43 -0500
LV Status available
# open 2
LV Size <3.91 GiB
Current LE 1000
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 xxxxxx-vvW4-zI7z-r8uf-vXgv-D85s-xxxxxx
LV Write Access read/write
LV Creation host, time localhost, 2020-02-26 03:13:43 -0500
LV Status available
# open 1
LV Size 35.60 GiB
Current LE 9114
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
#查看扩展后的卷组情况
lvm> vgdisplay
--- Volume group ---
VG Name centos
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 539.50 GiB
PE Size 4.00 MiB
Total PE 138113
Alloc PE / Size 10114 / <39.51 GiB
Free PE / Size 127999 / <500.00 GiB
VG UUID xxxxxx-rOjI-b0IY-h4Mu-k8Of-QPCN-xxxxxx
#将新增的逻辑卷全部扩展到“/”分区中
lvm> lvextend -l +100%FREE /dev/centos/root #注意LV Path
Size of logical volume centos/root changed from 35.60 GiB (9114 extents) to <535.60 GiB (137113 extents).
Logical volume centos/root successfully resized.
#退出lvm
lvm> quit
Exiting.
5
#查看磁盘大小
df -h #没有变化
1
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 36G 1.7G 34G 5% /
/dev/sda1 497M 142M 356M 29% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
1
2
3
4
5
xfs格式的文件扩充
xfs_growfs /dev/mapper/centos-root
1
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2333184 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9332736, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4557, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
#重新查看磁盘
df -h
1
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 536G 1.7G 534G 1% /
/dev/sda1 497M 142M 356M 29% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
完成
步骤1:原文链接:https://blog.csdn.net/l_liangkk/article/details/81268938
步骤2:原文链接:https://blog.csdn.net/weixin_43841942/article/details/115211220