Last active
February 7, 2018 07:53
-
-
Save solaris9000/0ff6133cda160b6f7146273c15fcac02 to your computer and use it in GitHub Desktop.
How to create Vagrant box from scratch
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
How to install a vagrant base box from scratch using VirtualBox only for CentOS7 by Solaris9000 | |
Some info from: https://www.skoblenick.com/vagrant/creating-a-custom-box-from-scratch/ | |
Pre-Reqs | |
VirtualBox for Windows, VirtualBox Extensions, Vagrant for Windows, ISO of CentOS7 | |
Directory structure to store all VM's and Vagrant boxes. Eg D:\VM | |
1. Set up a new VM (dont use spaces in the name) in the usual way ie with GUI, with these settings: | |
Name: vagrant-centos74 (this will also be the name of the DIR where the VM will live) | |
Memory: 1024MB | |
1 x Disk: 40GB | |
Disable Sound and USB | |
1 x Adapter 1 as NAT and set the Port Forwarding in the Advance button to: | |
Name: SSH | |
Protocol: TCP | |
Host IP: blank | |
Host Port: 2222 | |
Guest IP: blank | |
Guest Port: 22 | |
2. Set up new user as vagrant with passwd as vagrant | |
3. Set root passwd as vagrant | |
---------------------------------------------------------------------------------------------------- | |
POST INSTALL TASKS (as root inside the VM using vagrant ssh) | |
1. yum update | |
2. yum install -y gcc make kernel-devel (pre-reqs for Linux Guest Editions) | |
3. yum install wget | |
4. reboot | |
5. Add vagrant to sudoers | |
echo "vagrant ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/vagrant | |
6. Install the "insecure" vagrant ssh pub key: | |
cd /home/vagrant | |
mkdir .ssh | |
chmod 700 .ssh | |
wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys | |
chmod 600 .ssh/authorized_keys | |
chown -R vagrant /home/vagrant/.ssh | |
7. Configure /etc/ssh/sshd_config as follows: | |
AuthorizedKeysFile %h/.ssh/authorized_keys | |
8. Install dev tools: | |
yum install kernel-headers kernel-devel | |
yum groupinstall "Development Tools" | |
9. Goto console window and select Devices > Insert Guest Additions CD image | |
10. mount /dev/cdrom /mnt | |
11. cd /mnt | |
12. Run the VBoxLinuxAdditions.run script. If this fails reboot and re-run. | |
13. Compile and install the Linux Guest Additions CD Image | |
./VBoxLinuxAdditions.run | |
14. Reboot | |
---------------------------------------------------------------------------------------------------- | |
Outside the VM using Powershell on Windows: | |
1. cd to the VM dir that contains the VM from step 1. | |
2. Package up the VM using the following command: | |
vagrant package --base <name of the VM excluding the .vbox ext) | |
This will produce the final base box called package.box | |
eg | |
vagrant package --base centos74 | |
3. Then add the package box to the repo cache and name as follows <distro/version>: | |
vagrant box add centos/74 package.box | |
The name "centos/74" will be shown in vagrant box list | |
4. vagrant init centos74-vagrant | |
5. vagrant up | |
6. Cleanup the VirtualBox initial VM by right clicking on the VM and delete all files. This will remove all files related to the original manual VM creation stage using VirtualBox, BUT will leave the vagrant files that were created by the vagrant commands. | |
7. The boxes dir in the main dir (VM) contains the Vagrant boxes. | |
8. Cleanup the package.box file by delete this in the VM dir. This is no longer needed as a copy has been cached in the boxes dir. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment