我想确保我的开发环境有足够的空闲空间来安装工具和其他东西。我找不到任何有关告诉Vagrant我想要的最小磁盘大小的配置选项。这是可能的吗?还是我需要创建自己的Box?
我想确保我的开发环境有足够的空闲空间来安装工具和其他东西。我找不到任何有关告诉Vagrant我想要的最小磁盘大小的配置选项。这是可能的吗?还是我需要创建自己的Box?
我使用了 Vagrant 插件 vagrant-disksize 调整磁盘大小。
它可以帮助指定初始磁盘大小,而且它管用!
在命令行中运行以下命令:
vagrant plugin install vagrant-disksize
并在您的 Vagrantfile 中使用以下内容:
vagrant.configure('2') do |config|
config.vm.box = 'ubuntu/xenial64'
config.disksize.size = '50GB'
end
vagrant up
命令,以便让更大的磁盘得以使用。由于虚拟机操作系统未能识别新的磁盘空间,因此 vagrant halt;vagrant up
命令无效。为了避免修复这个新问题,我选择重新创建虚拟机,这种方法对我有效。 - Buttle Butkus安装Vagrant插件vagrant-disksize
vagrant plugin install vagrant-disksize
如果希望在启动Vagrant时确保用户已安装插件,则可以在Vagrantfile开头添加以下内容:
# Install vagrant-disksize to allow resizing the vagrant box disk.
unless Vagrant.has_plugin?("vagrant-disksize")
raise Vagrant::Errors::VagrantError.new, "vagrant-disksize plugin is missing. Please install it using 'vagrant plugin install vagrant-disksize' and rerun 'vagrant up'"
end
在Vagrantfile中设置所需的磁盘大小
vagrant.configure('2') do |config|
config.disksize.size = '50GB'
end
更新现有的vagrant box
sudo resize2fs -p -F /dev/sda1
给我报错信息:resize2fs: Bad magic number in super-block while trying to open /dev/sda1
。Couldn't find valid filesystem superblock
。请问能否帮忙解决? - Damodar Bashyalsudo xfs_growfs /dev/sdaX
是 XFS 文件系统的有效命令。 - marc.guentherVagrant最近在VirtualBox提供者中添加了实验性支持自定义磁盘大小(包括磁盘调整大小)。一些常见的用法情况可以在此处和此处找到。
要启用此功能,请修改Vagrantfile
(参见下面的示例),在您的shell中设置VAGRANT_EXPERIMENTAL="disks"
环境变量,然后运行vagrant up
命令。
这是一个示例Vagrantfile
,使用bento/ubuntu-20.04
基础镜像(其基于LVM)经过Vagrant 2.2.19
测试:
Vagrant.configure("2") do |config|
...
config.vm.disk :disk, size: "150GB", primary: true
config.vm.box = "bento/ubuntu-20.04"
config.vm.box_version = "202005.21.0"
config.vm.box_check_update = false
...
end
vagrant up
期间看到以下输出(或类似输出):==> vagrant: You have requested to enabled the experimental flag with the following features:
==> vagrant:
==> vagrant: Features: disks
==> vagrant:
==> vagrant: Please use with caution, as some of the features may not be fully
==> vagrant: functional yet.
Bringing machine 'server' up with 'virtualbox' provider...
==> server: Clearing any previously set forwarded ports...
==> server: Clearing any previously set network interfaces...
==> server: Preparing network interfaces based on configuration...
server: Adapter 1: nat
==> server: Forwarding ports...
server: 22 (guest) => 49222 (host) (adapter 1)
server: 4200 (guest) => 49280 (host) (adapter 1)
server: 4243 (guest) => 49243 (host) (adapter 1)
==> server: Configuring storage mediums...
server: Disk 'vagrant_primary' needs to be resized. Resizing disk...
这个过程可能需要一段时间才能完成(在我的情况下,需要1到2小时)。
使用vagrant ssh
进入您的虚拟机,然后使用以下命令(基于此答案)收集有关文件系统的信息,然后扩展LVM卷。 如果您的基本框不使用LVM,则不应使用这些命令。
# Understand your partitions.
> lsblk
> df -lhT /
> sudo fdisk -l /dev/sda
> sudo vgdisplay
> sudo parted /dev/sda print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 538MB 537MB primary fat32 boot
2 539MB 68.7GB 68.2GB extended
5 539MB 68.7GB 68.2GB logical lvm
# Resize your partitions.
> sudo parted /dev/sda resizepart 2 100%
> sudo parted /dev/sda resizepart 5 100%
> sudo parted /dev/sda print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 538MB 537MB primary fat32 boot
2 539MB 161GB 161GB extended
5 539MB 161GB 161GB logical lvm
# Resize your LVM physical volume to match the new partition extents.
> sudo pvresize /dev/sda5
> sudo vgdisplay
Alloc PE / Size 16255 / <63.50 GiB
Free PE / Size 22016 / 86.00 GiB
# Resize your LVM logical volume to fill the available Free space.
> sudo lvdisplay
--- Logical volume ---
LV Path /dev/vgvagrant/root
> sudo lvextend -l+100%FREE /dev/vgvagrant/root
Size of logical volume vgvagrant/root changed from <62.54 GiB (16010 extents) to <148.54 GiB (38026 extents).
Logical volume vgvagrant/root successfully resized.
# Apply the changes to the filesystem.
> sudo resize2fs /dev/vgvagrant/root
> df -lhT /
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vgvagrant-root ext4 146G 55G 85G 40% /
vagrant plugin install vagrant-disksize
vagrant.configure('2') do |config|
config.disksize.size = '300GB'
end
vagrant halt
vagrant up
SSH 到 vagrant box
使用 vgdisplay 命令检查旧的大小:
vgdisplay
--- Volume group ---
VG Name vagrant-vg
System ID
Format lvm2
...
Alloc PE / Size 16200 / 63.28 GiB
Free PE / Size 0 / 0
parted /dev/sda
p
Number Start End Size Type File system Flags
1 1049kB 768MB 767MB primary ext2 boot
2 769MB 68.7GB 67.9GB extended
5 769MB 68.7GB 67.9GB logical lvm
resizepart 2 321GB
resizepart 5 321GB
p
Number Start End Size Type File system Flags
1 1049kB 768MB 767MB primary ext2 boot
2 769MB 322GB 321GB extended
5 769MB 321GB 320GB logical lvm
quit
pvresize /dev/sda5
vgdisplay
Alloc PE / Size 16200 / 63.28 GiB
Free PE / Size 60148 / 234.95 GiB
lvextend -L+234.95 /dev/vagrant-vg/root
Size of logical volume vagrant-vg/root changed from 62.32 GiB (15955 extents) to 297.27 GiB (76102 extents).
Logical volume root successfully resized.
vgdisplay
Alloc PE / Size 76347 / 298.23 GiB
Free PE / Size 1 / 4.00 MiB
resize2fs /dev/vagrant-vg/root
df -h
/dev/mapper/vagrant--vg-root 293G 59G 222G 21% /
https://www.vagrantup.com/docs/virtualbox/configuration.html
config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"] end
配置.vm提供者"virtualbox",其中|v|是变量名,在其内部进行自定义["modifyvm",:id,"--cpuexecutioncap","50"]。https://www.virtualbox.org/manual/ch08.html#vboxmanage-list
但在修改vm部分中,我没有看到任何与磁盘调整相关的内容!也许你可以尝试附加一个次要磁盘!
$ vagrant plugin install --plugin-clean-sources --plugin-source https://rubygems.org vagrant-disksize
Vagrant.configure("2") do |config|
config.vm.box = "centos/8"
config.vm.network "public_network"
config.disksize.size = "11240MB"
end