- Download and install the latest version of VirtualBox 6.0 (as of this writing, version 6.0.22)
- Do not use VirtualBox 6.1. It causes networking issues, and it requires Intel VT-x/AMD-v to be enabled. Even if VT-x is enabled, if Hyper-v is also enabled, VirtualBox will not be able to use it. (https://forums.virtualbox.org/viewtopic.php?f=1&t=62339 kubernetes/minikube#4587)
- Follow the install and use all the defaults.
- After install, open the VirtualBox GUI
- Go to menu File -> Preferences
- In the General tab, look for the Default Machine Folder setting.
Set it to
C:\files\VirtualBox VMs. This will avoid your VM being created in your user's home directory, which could cause issues later. - Now click Extensions.
- Make sure there is no Oracle VirtualBox Extension Pack listed. If there is, select it, and click the "X" button to the right to uninstall it. The license for this Extension Pack is not free for commercial uses, and you don't need it for a basic headless Linux VM.
- Download and install the latest version of Vagrant for Windows (as of this writing, version 2.2.9)
- Download at https://gitforwindows.org/
- This is only used to download the files in this Git repo.
You can skip this step if you download each file in this repo and put them in the
devboxfolder shown in the next step. However, using Git will allow you togit pullany updates to this repo in the future.
- Open a command-line window (
cmd.exe) and run the following commands:TheC:\Users\willis> mkdir c:\files\vagrant\devbox C:\Users\willis> cd c:\files\vagrant C:\files\vagrant> git clone https://github.com/pwillis-els/vagrant-ubuntu-windows-10.git devbox C:\files\vagrant> cd devbox C:\files\vagrant\devbox> .\vagrant_up.batvagrant_up.batfile sets the location of your VAGRANT_HOME directory toC:\files\vagrant. Otherwise it would be created in your user's profile directory, which could cause problems later. If you're going to run morevagrantcommands, first set the variable in your console as shown invagrant_up.bat.
Vagrant will now create and provision your new Vagrant box. (this will take some time)
-
If
vagrant_up.batfails:- Edit the file to add
--debugaftervagrant up - Run
vagrant_up.batagain, which should provide more information about why it failed.
- Edit the file to add
-
If you get the following error:
Stderr: VBoxManage.exe: error: Call to WHvSetupPartition failed: ERROR_SUCCESS (Last=0xc000000d/87) (VERR_NEM_VM_CREATE_FAILED) VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component ConsoleWrap, interface IConsoleIt may mean VirtualBox is trying to use Hyper-V and failing. You should turn off HyperV and reboot.
- Open a new
cmd.execonsole with Administrator privileges. - Run the command
bcdedit /set hypervisorlaunchtype off - Reboot
- Open a new
-
Try opening VirtualBox GUI, going to Preferences, Networking, and make sure there is at least one "NAT" network.
-
If you have networking issues getting your Vagrant box up, try turning off any anti-virus software, or anything else that might mess with your network connection.
- To SSH in from the Windows console, just run the
vagrant_ssh.batscript. It will change to the correct directory and runvagrant sshfor you. - You can also get the ssh connection information with command
vagrant ssh-config, convert the IdentityFile to a PuTTY .ppk file, and use PuTTY to log in. With PuTTY you can also forward the X11 connection to run graphical apps.
Vagrant creates an SSH key for you, whose path you can retrieve with the vagrant ssh-config command.
However, it is more secure to have a password-protected key that lives only in your Vagrant box.
- Login to the Vagrant machine (see above)
- Run the following command and follow the prompts
$ ssh-keygen -o -t ed25519
- Navigate to Add new SSH key
- Put in a title ("Vagrant Devbox") and paste in your SSH public key, which you can get from your Vagrant box:
$ cat ~/.ssh/id_ed25519.pub - Navigate to Add a New personal access token
- Add a description ("Vagrant Devbox") and select the scopes ("repo" is enough to start), and click Generate Token
- Immediately copy down the token on the screen.
- If your GitHub account is SSO-linked, click Enable SSO next to the new Personal Access Token, and then click Authorize, and follow the prompts.
- In your Vagrant box, add your GitHub login credentials to the file
/home/vagrant/.netrc. Use your new Personal Access Token as the password. (Instructions: https://stackoverflow.com/questions/6031214/git-how-to-use-netrc-file-on-windows-to-save-user-and-password) - In your Vagrant box you can now use
gitto clone GitHub repos using either the HTTPS or SSH protocol.
- Use Docker inside the Vagrant box to run applications, as Ubuntu's versions are not the latest. Examples:
-
Terraform:
$ mkdir $HOME/bin $ printf '#!/bin/bash\ndocker run -i -t hashicorp/terraform:light "$@"\n' > $HOME/bin/dterraform $ chmod 755 $HOME/bin/dterraform $ ~/bin/dterraform version Terraform v0.12.28
-
AWS CLI:
$ mkdir $HOME/bin $ curl -o $HOME/bin/aws.sh https://raw.githubusercontent.com/mesosphere/aws-cli/master/aws.sh $ chmod 755 $HOME/bin/aws.sh $ export AWS_ACCESS_KEY_ID="<id>" $ export AWS_SECRET_ACCESS_KEY="<key>" $ export AWS_DEFAULT_REGION="<region>" $ ~/bin/aws.sh s3 ls
-