vagrant package how to save changes to new box - virtual-machine

My question is related to this here but I do not get it to work.
I use a pre-made vagrant box from vagrantbox.es ( http://goo.gl/KwQSa2 ) and I want to make some changes and repackage the new virtual machine into a new vagrant box file.
To get the initial box, I add config.vm.box_url = "http://goo.gl/KwQSa2" to my vagrant file.
After invoking vagrant up I do vagrant ssh and then some operation (e.g. touch testfile.txt).
After logging out I use vagrant package which creates package.box.
Then I do vagrant destroy, add the path to package.box to config.vm.box_url in my vagrant file and do vagrant up again.
When I log into the VM, my testfile.txt is not there, so it looks like I packaged the unchanged box.
I tried other things such as vagrant box repackage without success.
What am I missing here?

When you package, you have to specify the UUID of the new VM created (by vagrant up) based on the base box.
NOTE: If you are using VirtualBox, it'll create a new VM with name - base_box_name-default-UUID.
When running
vagrant package --base name --output /path/to/name.box
The --base NAME, name should be either the new VM's name or its UUID.
You can get it by using the following command:
$ VBoxManage list vms
"oracle65" {5f9e6136-7773-4cd5-99a1-3a66b5e48045}
"Ubuntu" {e8c5a28c-788d-4d57-8c4a-c1f032a02443}
"oracle510" {fed5f379-495e-4b4b-b4e2-24f98edd2e72}
"archlinux" {c79dcee9-a523-4300-b026-cbc93ad37062}
"Windows" {fa768a76-5710-4b07-a4df-cc388370f038}
"Wiki" {a50ce314-6af8-4633-b02e-82b765cbf401}
"openSUSE" {af3cdf13-7e00-4c24-ae52-423919359b18}
"Debian" {37680776-73b9-44fd-8348-f60fd3895624}
"Solaris" {bc7be4ab-293d-4c94-b591-b5445a954f6c}
"centos_default_1395637517620_29337" {03d1282a-c7ba-493b-91ad-ec26ed763b6c}
"Kubuntu" {787ce012-00ef-4f90-acda-1b65c6d9941b}

Related

virsh console hangs whenever I connect to Virtual Machine

Whenever I try to connect to VM using virsh console <vm name> my screen hangs and displays:
Connected to domain <vm name>
Escape character is ^]
I have found many solutions on the internet but nothing has worked for me and I am even not able to find the /etc/init directory as CentOS 7 has a different directory structure.
I need /etc/init directory to create a script which I found on the internet as a solution.
I am using only ssh connection and no GUI and I do not have any access to the physical machine.
I think you should start a console (e.g. ttyS0 ).
For example on my Debian 8 I enable it with systemd:
systemctl enable getty#tty1.service
Enable Serial Console on CentOS/RHEL 7
On the virtual machine, add ‘console=ttyS0‘ at the end of the kernel lines in the /boot/grub2/grub.cfg file:
grubby --update-kernel=ALL --args="console=ttyS0"
Note: Alternatively, you can edit the /etc/default/grub file, add console=ttyS0 to the GRUB_CMDLINE_LINUX variable and execute
grub2-mkconfig -o /boot/grub2/grub.cfg
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial –speed115200 –unit=0 –word=8 –parity=no –stop=1"
I had the same issue right after virt-install, then after trying to connect to the guest, too. I tried all the suggested solutions but none of them helped. Then I realized that I forgot to install KVM. A simple 'yum -y install kvm' resolved the issue.

How to open Virtual Box on Windows 10

I am unable to access the virtual box that I initialized with the "vagrant up" command. I now get this:
[C:\web\Homestead]vagrant global-status
id name provider state directory
------------------------------------------------------------------------
13650ef default virtualbox running C:/web/Homestead
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
[C:\web\Homestead]vagrant ssh 13650ef
C:/web/Homestead/Vagrantfile:4: warning: already initialized constant
....
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:
The executable 'cygpath' Vagrant is trying to run was not
found in the %PATH% variable. This is an error. Please verify
this software is installed and on the path.
I am running Windows 10 and set my environment variables, as follows:
Path c:\php;C:\Program Files\Oracle\VirtualBox;
C:\Program Files\Git\usr\bin;C:\cygwin64;
C:\Users\Kevin\AppData\Roaming\npm
The cygpath file it seeks is clearly under both c:\Program Files\Git\usr\bin and under C:\cygwin64.
I tried to access the virtual box through Putty, but got the simple message "connection refused". I have used Puttygen to convert the ssh keys to Putty ppk files.
I have tried to retrace my steps initializing the virtual box, but I fail to see how to step forward and open the box.
Should I destroy my virtual box and start over?
Try to change the PATH paths with 'Program Files' to Progra~1 paths or to wrap each path item with double-quotes, e.g.:
Path c:\php;"C:\Program Files\Oracle\VirtualBox"; "C:\Program
Files\Git\usr\bin";C:\cygwin64; C:\Users\Kevin\AppData\Roaming\npm
or
Path c:\php;C:\Progra~1\Oracle\VirtualBox;
C:\Progra~1\Git\usr\bin;C:\cygwin64;
C:\Users\Kevin\AppData\Roaming\npm

Vagrant stuck in "Waiting for VM to Boot"

I want to preface this question by mentioning that I have indeed looked over most if not all vagrant "Waiting for VM to Boot" troubleshooting threads:
Things I've tried include:
vagrant failed to connect VM
https://superuser.com/questions/342473/vagrant-ssh-fails-with-virtualbox
https://github.com/mitchellh/vagrant/issues/410
http://vagrant.wikia.com/wiki/Usage
http://scotch.io/tutorials/get-vagrant-up-and-running-in-no-time
And more.
Here's how I setup my Vagrant:
Note: We are using Vagrant 1.2.2 since we do not at the moment have time to change configs to newer versions. I am also using VirtualBox 4.2.26.
My office has an /official/ folder which includes things such as Vagrantfile inside. Inside my Vagrantfile are these custom settings:
config.vm.box = "my_box"
config.ssh.private_key_path = "~/.ssh/github_rsa"
config.ssh.forward_agent = true
config.ssh.forward_x11 = true
config.ssh.max_tries = 300
config.vm.provision :shell, :inline => "/etc/init.d/networking restart"
I installed our custom box (called package.box) via vagrant box add my_box absolute_path/package.box which went without a hitch.
Running vagrant up, I would look at the "preview" of the VirtualBox, and it would simply be stuck at the login page. My Terminal would also only say: Waiting for VM to boot. This can take a few minutes. As far as I know, this is an SSH issue. Or my private key issues, though in my Vagrantfile I explicitly pointed to my private key location.
Interesting Notes:
Running dhclient within the VirtualBox GUI, it says command no found. Running sudo dhclient eth0 was one of the suggested fixes.
This fix: https://superuser.com/a/343775/298915 of "modify the /etc/rc.local file to include the line sh /etc/init.d/networking restart just before exit 0." did nothing to fix the issue.
Conclusion:
Having tried to re-install everything thinking I messed up a file, it did not seem to ameliorate the issue. I am unable to work with this issue. Could someone give me some insight?
So after around twelve hours of dejected troubleshooting, I was able to (finally) get the VM to boot.
Setup your private/public keys using the link provided. My box is a Debian Linux 3.2.0-4-amd64, so instead of /root/.ssh/id_rsa.pub, you have to use /home/vagrant/.ssh/id_rsa.pub (and the respective id_rsa path for the private key).
Note: make sure your files have the right permissions. Check using ls -l path, and change using chmod. Your machine may not have /home/vagrant/.ssh/authorized_keys, so generate that file with touch /home/vagrant/.ssh/authorized_keys.
Boot your VM using the VirtualBox GUI using (through either Vagrantfile boot-GUI command, or starting your VM using VirtualBox). Login using vagrant and vagrant when prompted.
Within the GUI, manually start dhclient using sudo dhclient eth0 -v. Why is it off by default? I have no idea. I found out that it was off when I tried to wget the private/public keys in the tutorial above, but was unable to.
Go to your local machine's command line and reload vagrant using vagrant reload. It should boot, and no longer hang at "Waiting for VM to Boot."
This worked for me. Though it may be different for other machines, for whatever reason Vagrant likes to break.
Suggestion: can this be saved as a script so we don't need to manually do this everytime?
EDIT: Update to the latest version of Vagrant, and you will never see this issue again. About time, huh?

Vagrant corrupted index file C:\Users\USERNAME\.vagrant.d/data/machine-index/index

My Windows 8.1 just crashed. Now I have some files on my dist that are corrupted. This includes my vagrant machine index (Not shure if the naming is right but I know that it is this file -> C:\Users\USERNAME.vagrant.d/data/machine-index/index).
So There is a lot of binary or hexdecimal stuff in there (Again not shure because I don't deal with this stuff usualy so correct me if I'm wrong!) And Vagrant spits out the following message if I try to start everything after boot.
vagrant up returns this
The machine index which stores all required information about
running Vagrant environments has become corrupt. This is usually
caused by external tampering of the Vagrant data folder.
Vagrant cannot manage any Vagrant environments if the index is
corrupt. Please attempt to manually correct it. If you are unable
to manually correct it, then remove the data file at the path below.
This will leave all existing Vagrant environments "orphaned" and
they'll have to be destroyed manually.
Path: C:/Users/Username/.vagrant.d/data/machine-index/index
Same thing happened to me. So I just deleted the index file and the .lock file from the machine-index folder to get Vagrant working again.
When using Vagrant 2.2.5 in Windows 10, I had to navigate to /Users/{yourname}/.vagrant.d/data/machine-index and remove both index and index.lock, so rm index then rm index.lock.
Finally I navigated back to Homestead folder and ran vagrant up.
When accidentally my laptop crashed, I had the same vagrant issue (index) on my first attempt to run vagrant up.
The machine index which stores all required information about
running Vagrant environments has become corrupt. This is usually
caused by external tampering of the Vagrant data folder.
Vagrant cannot manage any Vagrant environments if the index is
corrupt. Please attempt to manually correct it. If you are unable
to manually correct it, then remove the data file at the path below.
This will leave all existing Vagrant environments "orphaned" and
they'll have to be destroyed manually.
Path: C:/Users/{user}/.vagrant.d/data/machine-index/index
Unfortunately my issue was not solved by deleting the index and index.lock files as the most voted up answer told. I rebooted my vm using virtualbox GUI (used as VM provider) and shown up the following message.
Entering emergency mode. Exit the shell to continue.
Type "journalctl" to view system logs.
You might want to save "/run/initramfs/rdsosreport.txt" to a USB stick or /boot
after mounting them and attach it to a bug report.
I realised that crash produced errors on VM's FS. So after searching and investigation I overcame that issue by executing the command below.
xfs_repair -v -L /dev/dm-0
Environment info: OS windows10, virtual-box 6.1, vagrant 2.2.7 and vm-os centos7

"The machine with the name 'c6401' was not found configured for this Vagrant environment." Error

I plan to work with Apache Ambari. To start, I've done everything according to https://cwiki.apache.org/confluence/display/AMBARI/Quick+Start+Guide. But whenever I try to start vms, I get following error:
The machine with the name 'c6401' was not found configured for
this Vagrant environment.
Had this error today on mac and decided to update this post with the solution that worked for me.
Steps
Delete all redundant machine folders ./.vagrant/machines (.vagrant folder is a hidden folder within the repo)
Run vagrant global-status --prune command in the root of the project
Destroy vagrant setup vagrant destroy
Ensure no related machine exists in the virtualbox UI
Run vagrant up again
cheers!
Please open the VagrantFile under the centos6.4 directory and verify if you see contents like this:
config.vm.define :c6401 do |c6401|
# uncomment the line below to set up the ambari dev environment
# c6401.vm.provision :shell, :path => "dev-bootstrap.sh"
c6401.vm.hostname = "c6401.ambari.apache.org"
c6401.vm.network :private_network, ip: "192.168.64.101"
end
I had faced a similar issue. The problem was that I had deleted the Vagrantfile that comes by default with ambari-vagrant.git and had run 'vagrant init', which creates a standard template file that doesn't have any reference to c6401 machine.
If you are on the same boat, just do a
git checkout centos6.4/VagrantFile
from under ambari-vagrant directory and try re-running
vagrant up c6401