I solved this problem, and will answer in case anyone else has a similar issue.
What I did was: I enabled the GUI of Virtual box to see that it was waiting for input on startup to select whether I wanted to boot directly to ubuntu or safemode etc.
To turn on the GUI you have to put this in your vagrant config Vagrantfile
:
config.vm.provider :virtualbox do |vb|
vb.gui = true
end
Thanks to BMW for the well engineered and stylish answer, and Peter as well. The referenced article (gist.github.com/leifg/4713995) had the magic, which i will reproduce below in a Vagrant script and a corresponding bootstrap file that makes a file system from the newly added second disk, and adds it to /etc/fstab. This completely solves my problem [ no more disappearing data ].
Vagrantfile:
Vagrant.require_version ">= 1.4.3"
VAGRANTFILE_API_VERSION = "2"
disk = './secondDisk.vdi'
BOX_NAME="test"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :master do |master|
master.vm.box = "centos65"
master.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
master.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "4196"]
v.name = BOX_NAME
end
master.vm.network :private_network, ip: "192.168.33.10"
master.vm.hostname = BOX_NAME
end
config.vm.synced_folder(".", "/vagrant",
:owner => "vagrant",
:group => "vagrant",
:mount_options => ['dmode=777','fmode=777']
)
# create the second disk and attach it
config.vm.provider "virtualbox" do |vb|
unless File.exist?(disk)
vb.customize ['createhd', '--filename', disk, '--variant', 'Fixed', '--size', 1 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
end
# NEW - invoke script which partitions the new disk (/dev/sdb)
# and create mount directives in /etc/fstab
#config.vm.provision :shell, path: "bootstrap.sh"
config.vm.provision "shell" do |shell|
shell.inline = "sudo /vagrant/bootstrap.sh"
end
end
bootstap script:
#!/bin/bash -x
# configure and mount second disk
#
yum install -y parted
parted /dev/sdb mklabel msdos
parted /dev/sdb mkpart primary 512 100%
mkfs.xfs /dev/sdb1
mkdir /mnt/disk
echo `blkid /dev/sdb1 | awk '{print$2}' | sed -e 's/"//g'` /mnt/disk xfs noatime,nobarrier 0 0 >> /etc/fstab
mount /mnt/disk
Best Answer
I agree with you that documentation at vagrantup is on the shorter side.
Some information can be gleaned from command help system.
For example:
gem
command.Just type the command without arguments:
vagrant gem -h
and it produces the information that you may need.Vagrant ssh-config
:Under the hood, when you execute
vagrant ssh
to ssh into VM. It is utilizing it's well known ssh key. The information on this key is provided byvagrant ssh-config
. This is useful in case you want to change the well know key to your own private key and prepare boxes to use that.Also some times, you may want to use ssh based automation with your VMs. In that case, knowing which key is being used is useful. You could do use normal ssh command -
ssh -i keyfile ..
vagrant status <vmname>
This command is a wrapper which provides the information on the status of vm. It could be running, saved and powered off.
vagrant reload
If you make any changes to the configuration in vagrantfile which needs to take effect. You may want to reload the VM. It re-runs the provisioning defined in the vagrantfile unless you ask it not too.
It does not destroy the VM you have created from a base box. That means all the changes you have made to your VM, like say created a folder in your user directory will be there after reload.
It is like reboot where it powers off your VM and then applies certain configuration change which can be applied only when VM has been powered off. and then power it on. Example: like attaching another SATA Virtual Disk.
vagrant up
This reads your configuration file -
vagrantfile
and then creates a VM from base box. Base Box is like a Template. You can create many VMs from it.Similarly,
vagrant destroy
destroys your VM. In this case all changes you made when inside it will be lost. But thats the cool idea that you can start from a base predefined state when you create a new VM.I really like using it and have blogged about it.
In summary, it is a good wrapper over VirtualBox APIs and Commands. You can have a look at the VirtualBox commands to understand some of the capabilities better.