Last active
August 24, 2024 07:28
-
-
Save jtopper/8588263 to your computer and use it in GitHub Desktop.
Add a new disk to a VMWare vagrant box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
In 2021 I had to do this to make it work. Mostly it's still OK though.
unless File.exists?( disk4 )
`#{vdiskmanager} -c -s 5GB -a lsilogic -t 1 #{disk4}`
end
vm.vmx['scsi0.present'] = 'TRUE' # Had to change this to TRUE or it wouldn't be connected
vm.vmx['scsi0:0.present'] = 'TRUE'
vm.vmx['scsi0:0.filename'] = disk4
vm.vmx['scsi0:0.redo'] = ''
vm.vmx['bios.hddOrder'] = "sata0:0" # Ensure it doesn't boot from the new drive.
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
This is very helpful, thanks for sharing!