Skip to content

Instantly share code, notes, and snippets.

@jtopper
Last active August 24, 2024 07:28
Show Gist options
  • Save jtopper/8588263 to your computer and use it in GitHub Desktop.
Save jtopper/8588263 to your computer and use it in GitHub Desktop.
Add a new disk to a VMWare vagrant box
config.vm.provider :vmware_fusion do |vm|
vdiskmanager = '/Applications/VMware\ Fusion.app/Contents/Library/vmware-vdiskmanager'
dir = "#{ENV['HOME']}/vagrant-additional-disk"
unless File.directory?( dir )
Dir.mkdir dir
end
file_to_disk = "#{dir}/var-lib-mysql.vmdk"
unless File.exists?( file_to_disk )
`#{vdiskmanager} -c -s 20GB -a lsilogic -t 1 #{file_to_disk}`
end
vm.vmx['scsi0:1.filename'] = file_to_disk
vm.vmx['scsi0:1.present'] = 'TRUE'
vm.vmx['scsi0:1.redo'] = ''
end
config.vm.provision :shell, :inline =>
"set -x && " +
"mkdir -p /var/lib/mysql && " +
"grep -q sdb1 /proc/partitions || ( " +
"echo ',,83' | sfdisk -q -D /dev/sdb && " +
"mkfs.ext4 /dev/sdb1 " +
") && " +
"grep -q sdb1 /etc/fstab || echo '/dev/sdb1 /var/lib/mysql ext4 defaults 0 0' >> /etc/fstab && " +
"grep -q /var/lib/mysql /proc/mounts || mount /var/lib/mysql"
@sven-m
Copy link

sven-m commented Jun 14, 2024

For some reason all of these options caused vmrun to crash:

$ vagrant up mymachine
==> mymachine: Stopping the VMware VM...
==> mymachine: Deleting the VM...
Bringing machine 'mymachine' up with 'vmware_desktop' provider...
==> mymachine: Cloning VMware VM: 'bento/debian-12'. This can take some time...
==> mymachine: Checking if box 'bento/debian-12' version '202404.23.0' is up to date...
==> mymachine: Verifying vmnet devices are healthy...
==> mymachine: Preparing network adapters...
==> mymachine: Starting the VMware VM...
An error occurred while executing `vmrun`, a utility for controlling
VMware machines. The command and output are below:

Command: ["-T", "fusion", "start", "/path/to/my/.vagrant/machines/mymachine/vmware_desktop/a1b9f67e-ee76-4483-90bb-4d083951c14e/debian-12.5-aarch64.vmx", "nogui", {:notify=>[:stdout, :stderr], :timeout=>45}]

Stdout: 2024-06-14T14:15:10.078| ServiceImpl_Opener: PID 9156
Error: The operation was canceled

Stderr:

But the three lined below did work for me, so sharing here for anyone having the same issue:

vm.vmx['nvme0.present'] = 'TRUE'
vm.vmx['nvme0:0.present']  = 'TRUE'
vm.vmx['nvme0:0.filename'] = disk_file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment