目录
1 创建 centos7 虚拟机
2 扩容根目录
我知道的扩容方式有两种:1 直接扩容分区 ;2 扩容逻辑卷。
我没找到为根目录设置到逻辑卷的方法,所以使用直接扩容分区。
1 创建 centos7 虚拟机,
vagrant up
vagrant ssh
查看磁盘大小:
PS E:\workspace\Virtual Machines\vagrant\centos7-138> vagrant ssh
[vagrant@10 ~]$ sudo -i
[root@10 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
└─sda1 8:1 0 40G 0 part /
[root@10 ~]#
2 扩容根目录
停止 虚拟机 vagrant halt
修改 Vagrantfile,设置磁盘大小为60G
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.disksize.size = "60GB"
注意:需要安装 vagrant-disksize
启动 vagrant up
PS E:\workspace\Virtual Machines\vagrant\centos7-138> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Resized disk: old 40960 MB, req 61440 MB, new 61440 MB
==> default: You may need to resize the filesystem from within the guest.
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work.
PS E:\workspace\Virtual Machines\vagrant\centos7-138>
启动日志中出现
==> default: Resized disk: old 40960 MB, req 61440 MB, new 61440 MB
==> default: You may need to resize the filesystem from within the guest.
说明设置生效了。
PS E:\workspace\Virtual Machines\vagrant\centos7-138> vagrant ssh
Last login: Wed Jul 19 15:26:58 2023 from 10.0.2.2
[vagrant@10 ~]$ sudo -i[root@10 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
└─sda1 8:1 0 40G 0 part /
[root@10 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.5M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 40G 3.0G 38G 8% /
tmpfs 379M 0 379M 0% /run/user/1000
[root@10 ~]#
sda1 分区有 40G 的空间,新增的 20 G 不在sda1分区中。
现在要把 20G 的空间加入到 sda1 中。方案就是直接把 sda1 删除,接着重新创建 sda1 分区
扩容成功。
参考:https://blog.csdn.net/kylinlan/article/details/126007381