使用virtualbox搭建虚拟机,如果磁盘不够用了,可以通过以下方式扩展。
扩容磁盘
分区扩展
查看磁盘情况
fdisk -l
Disk /dev/sda: 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: 0x000a391a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Disk /dev/mapper/centos-root: 37.6 GB, 37576769536 bytes, 73392128 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
扩展分区
bash
fdisk /dev/sda
# 删除分区
d
2
# 新建分区
n
p
# 修改分区类型为 Linux LVM
t
2
8e
# 保存分区
w
扩展LVM
bash
# 扩展物理卷到整个磁盘大小
sudo pvresize /dev/sda2
# 确认物理卷现在显示新的大小
pvdisplay
# 查看卷组
vgdisplay
# 查看当前逻辑卷
lvdisplay
# 扩展根逻辑卷
lvextend -l +100%FREE /dev/centos/root
# 扩展文件系统,ext4用resize2fs, xfs用xfs_growfs,可以用df -T查看
sudo resize2fs /dev/centos/root
sudo xfs_growfs /