Code Monkey home page Code Monkey logo

ubuntu-vagrant's Introduction

This builds an up-to-date Vagrant Ubuntu Base Box as described at the From Iso To Vagrant Box article.

Currently this targets Ubuntu 22.04 (Jammy Jellyfish).

Other Ubuntu versions might be available in a separate branch.

Usage

Install Packer 1.7+ and Vagrant 2.2.14+.

Ubuntu Host

On a Ubuntu host, install the dependencies by running the file at:

https://github.com/rgl/xfce-desktop-vagrant/blob/master/provision-virtualization-tools.sh

And you should also install and configure the NFS server. E.g.:

# install the nfs server.
sudo apt-get install -y nfs-kernel-server

# enable password-less configuration of the nfs server exports.
sudo bash -c 'cat >/etc/sudoers.d/vagrant-synced-folders' <<'EOF'
Cmnd_Alias VAGRANT_EXPORTS_CHOWN = /bin/chown 0\:0 /tmp/*
Cmnd_Alias VAGRANT_EXPORTS_MV = /bin/mv -f /tmp/* /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_CHOWN, VAGRANT_EXPORTS_MV, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY
EOF

For more information see the Vagrant NFS documentation.

Windows Host

On a Windows host, install Chocolatey, then execute the following PowerShell commands in a Administrator PowerShell window:

# NB if you want to use Hyper-V see the Hyper-V section in this document.
choco install -y packer vagrant jq msys2

Then open a bash shell by starting C:\tools\msys64\mingw64.exe and install the remaining dependencies:

pacman --noconfirm -Sy make zip unzip tar dos2unix netcat procps xorriso mingw-w64-x86_64-libcdio openssh
for n in /*.ini; do
    sed -i -E 's,^#?(MSYS2_PATH_TYPE)=.+,\1=inherit,g' $n
done
exit

NB The commands described in this README should be executed in a mingw64 bash shell.

qemu-kvm usage

Install qemu-kvm:

apt-get install -y qemu-kvm
apt-get install -y sysfsutils
systool -m kvm_intel -v

Type make build-libvirt and follow the instructions.

Try the example guest:

cd example
apt-get install -y virt-manager libvirt-dev
vagrant plugin install vagrant-libvirt
vagrant up --provider=libvirt --no-destroy-on-error --no-tty
vagrant ssh
exit
vagrant destroy -f

Proxmox usage

Set the Proxmox VE details:

cat >secrets-proxmox.sh <<EOF
export PROXMOX_URL='https://192.168.1.21:8006/api2/json'
export PROXMOX_USERNAME='root@pam'
export PROXMOX_PASSWORD='vagrant'
export PROXMOX_NODE='pve'
EOF
source secrets-proxmox.sh

Create the template:

make build-proxmox

NB There is no way to use the created template with vagrant (the vagrant-proxmox plugin is no longer compatible with recent vagrant versions). Instead, use packer (e.g. see this repository) or terraform (e.g. see rgl/terraform-proxmox-ubuntu-example).

Hyper-V usage

Install Hyper-V and also install the Windows Sandbox feature (for some reason, installing this makes DHCP work properly in the vEthernet Default Switch).

Make sure your user is in the Hyper-V Administrators group or you run with Administrative privileges.

Make sure your Virtual Switch (its vEthernet network adapter) is excluded from the Windows Firewall protected network connections by executing the following commands in a bash shell with Administrative privileges:

PowerShell -Command 'Get-NetFirewallProfile | Select-Object -Property Name,DisabledInterfaceAliases'
PowerShell -Command 'Set-NetFirewallProfile -DisabledInterfaceAliases (Get-NetAdapter -name "vEthernet*" | Where-Object {$_.ifIndex}).InterfaceAlias'

Create the base image in a bash shell with Administrative privileges:

cat >secrets-hyperv.sh <<'EOF'
# set this value when you need to set the VM Switch Name.
export HYPERV_SWITCH_NAME='Default Switch'
# set this value when you need to set the VM VLAN ID.
#export HYPERV_VLAN_ID=''
# set the credentials that the guest will use
# to connect to this host smb share.
# NB you should create a new local user named _vagrant_share
#    and use that one here instead of your user credentials.
# NB it would be nice for this user to have its credentials
#    automatically rotated, if you implement that feature,
#    let me known!
export VAGRANT_SMB_USERNAME='_vagrant_share'
export VAGRANT_SMB_PASSWORD=''
# remove the virtual switch from the windows firewall.
# NB execute if the VM fails to obtain an IP address from DHCP.
PowerShell -Command 'Set-NetFirewallProfile -DisabledInterfaceAliases (Get-NetAdapter -name "vEthernet*" | Where-Object {$_.ifIndex}).InterfaceAlias'
EOF
source secrets-hyperv.sh
make build-hyperv

Try the example guest:

NB You will need Administrative privileges to create the SMB share.

cd example
# grant $VAGRANT_SMB_USERNAME full permissions to the
# current directory.
# NB you must first install the Carbon PowerShell module
#    with choco install -y carbon.
# TODO set VM screen resolution.
PowerShell -Command '&"$env:ChocolateyInstall/lib/Carbon/Carbon/Import-Carbon.ps1"; Grant-CPermission . $env:VAGRANT_SMB_USERNAME FullControl'
vagrant up --provider=hyperv --no-destroy-on-error --no-tty
vagrant ssh
exit
vagrant destroy -f

VMware vSphere usage

Download govc and place it inside your /usr/local/bin directory.

Set your VMware vSphere details and test the connection:

sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
vagrant plugin install vagrant-vsphere
cat >secrets-vsphere.sh <<'EOF'
export GOVC_INSECURE='1'
export GOVC_HOST='vsphere.local'
export GOVC_URL="https://$GOVC_HOST/sdk"
export GOVC_USERNAME='[email protected]'
export GOVC_PASSWORD='password'
export GOVC_DATACENTER='Datacenter'
export GOVC_CLUSTER='Cluster'
export GOVC_DATASTORE='Datastore'
export VSPHERE_OS_ISO="[$GOVC_DATASTORE] iso/ubuntu-22.04.4-live-server-amd64.iso"
export VSPHERE_ESXI_HOST='esxi.local'
export VSPHERE_TEMPLATE_FOLDER='test/templates'
export VSPHERE_TEMPLATE_NAME="$VSPHERE_TEMPLATE_FOLDER/ubuntu-22.04-amd64-vsphere"
export VSPHERE_VM_FOLDER='test'
export VSPHERE_VM_NAME='ubuntu-vagrant-example'
export VSPHERE_VLAN='packer'
export VSPHERE_IP_WAIT_ADDRESS='0.0.0.0/0'
# set the credentials that the guest will use
# to connect to this host smb share.
# NB you should create a new local user named _vagrant_share
#    and use that one here instead of your user credentials.
# NB it would be nice for this user to have its credentials
#    automatically rotated, if you implement that feature,
#    let me known!
export VAGRANT_SMB_USERNAME='_vagrant_share'
export VAGRANT_SMB_PASSWORD=''
EOF
source secrets-vsphere.sh
# see https://github.com/vmware/govmomi/blob/master/govc/USAGE.md
govc version
govc about
govc datacenter.info # list datacenters
govc find # find all managed objects

Download the Ubuntu ISO (you can find the full iso URL in the ubuntu.pkr.hcl file) and place it inside the datastore as defined by the iso_paths property that is inside the packer template file.

See the example Vagrantfile to see how you could use a cloud-init configuration to configure the VM.

Type make build-vsphere and follow the instructions.

Try the example guest:

source secrets-vsphere.sh
cd example
vagrant up --provider=vsphere --no-destroy-on-error --no-tty
vagrant ssh
exit
vagrant destroy -f

ubuntu-vagrant's People

Contributors

rgl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ubuntu-vagrant's Issues

following instructions build fails

☁  ubuntu-vagrant [master] make
rm -f ubuntu-amd64-virtualbox.box
packer build ubuntu.json
amd64-virtualbox output will be in this color.

==> amd64-virtualbox: Cannot find "Default Guest Additions ISO" in vboxmanage output (or it is empty)
==> amd64-virtualbox: Downloading or copying Guest additions checksums
    amd64-virtualbox: Downloading or copying: http://download.virtualbox.org/virtualbox/5.1.6/SHA256SUMS
==> amd64-virtualbox: Downloading or copying Guest additions
    amd64-virtualbox: Downloading or copying: http://download.virtualbox.org/virtualbox/5.1.6/VBoxGuestAdditions_5.1.6.iso
==> amd64-virtualbox: Downloading or copying ISO
    amd64-virtualbox: Downloading or copying: http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/mini.iso
==> amd64-virtualbox: Starting HTTP server on port 8531
==> amd64-virtualbox: Creating virtual machine...
==> amd64-virtualbox: Creating hard drive...
==> amd64-virtualbox: Creating forwarded port mapping for communicator (SSH, WinRM, etc) (host port 3923)
==> amd64-virtualbox: Executing custom VBoxManage commands...
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --memory 2048
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --cpus 2
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --vram 32
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --nictype1 virtio
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --nictype2 virtio
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --nictype3 virtio
    amd64-virtualbox: Executing: modifyvm packer-amd64-virtualbox-1480525579 --nictype4 virtio
==> amd64-virtualbox: Starting the virtual machine...
==> amd64-virtualbox: Error starting VM: VBoxManage error: VBoxManage: error: The virtual machine 'packer-amd64-virtualbox-1480525579' has terminated unexpectedly during startup because of signal 6
==> amd64-virtualbox: VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
==> amd64-virtualbox: Unregistering and deleting virtual machine...
==> amd64-virtualbox: Deleting output directory...
Build 'amd64-virtualbox' errored: Error starting VM: VBoxManage error: VBoxManage: error: The virtual machine 'packer-amd64-virtualbox-1480525579' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

==> Some builds didn't complete successfully and had errors:
--> amd64-virtualbox: Error starting VM: VBoxManage error: VBoxManage: error: The virtual machine 'packer-amd64-virtualbox-1480525579' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

==> Builds finished but no artifacts were created.
Makefile:2: recipe for target 'ubuntu-amd64-virtualbox.box' failed
make: *** [ubuntu-amd64-virtualbox.box] Error 1

cannot make it work using make command

☁  ubuntu-vagrant [master] make
rm -f ubuntu-amd64-virtualbox.box
packer build ubuntu.json
make: packer: Command not found
Makefile:2: recipe for target 'ubuntu-amd64-virtualbox.box' failed
make: *** [ubuntu-amd64-virtualbox.box] Error 127

Can't open file

Hi.

I get an error message when I have executed the command:

~/ubuntu-vagrant/example/vagrant up --provider=virtualbox --no-destroy-on-error --no-tty

The error message is:

Error message start

==> vagrant: You have requested to enabled the experimental flag with the following features:
==> vagrant:
==> vagrant: Features: typed_triggers
==> vagrant:
==> vagrant: Please use with caution, as some of the features may not be fully
==> vagrant: functional yet.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Running action triggers before up ...
==> default: Running trigger...
==> default: Box 'ubuntu-20.04-amd64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'ubuntu-20.04-amd64' (v0) for provider: virtualbox
default: Downloading: ubuntu-20.04-amd64

default: An error occurred while downloading the remote file. The error message, if any, is reproduced below. Please fix this error and try again.

Couldn't open file C:/tools/msys64/home//ubuntu-vagrant/example/ubuntu-20.04-amd64

Error message end

Host: Windows 10 Pro 20H2 build 19042.685
Vagrant version: 2.2.14
Provider model/version: Virtualbox 6.1.16 r140961 (Qt 5.6.2)

I have given Users and Authenticated Users Full Control to example directory and subfolders and files in Windows 10 File Explorer. The example directory is not encrypted. I have restarted the mingw64 bash shell. Issue still exists.

Do you know how I can troubleshoot this further?

Here are some screenshots too:

ErrorMessage
ExampleDirectoryContentAndPermissions
Ubuntu-vagrantDirectoryContentAndPermissions

Plans to support Virtualbox 6.x?

I tried building this recently on the latest Virtualbox (6.0.4 at the time of this posting) and it failed (I don't have the exact error in front of me as I promptly downgraded and rebuilt it just fine with 5.2.26). It seems their VboxManage CLI has changed. Just wondering if you plan to support the newer Virtualbox.

If you need the exact error, I can try building it with 6.0 again later.

make throws No rule to make a target

Hi.

I get this error message when executing the make build-virtualbox command

AzureAD+SensitiveValue@LAPTOP-SensitiveValue MINGW64 ~
$ make build-virtualbox
make: *** No rule to make target 'build-virtualbox'. Stop.

AzureAD+SensitiveValue@LAPTOP-SensitiveValue MINGW64 ~

I have started C:\tools\msys64\mingw64 from an adminstrator and a non administrator powershell prompt and run the make build-virtualbox command and I get the same error message:

I can't find the makefile anywhere in Mingw64 bash shell

In the powershell prompt I can find the make file but I get this error message instead:

make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • make build-virtualbox
  •   + CategoryInfo          : ObjectNotFound: (make:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

I have a Windows host and followed these steps:

  1. I have downloaded the files from github.
  2. I have executed following commands in an administrator powershell window:

choco install -y virtualbox --params "/NoDesktopShortcut /ExtensionPack"
choco install -y packer vagrant jq msys2

  1. I have opened the mingw64 bash shell by executing C:\tools\msys64\mingw64.exe
  2. I have executed these commands in the mingw64 bash shell:

pacman --noconfirm -Sy make zip unzip tar dos2unix netcat procps xorriso mingw-w64-x86_64-libcdio
for n in /*.ini; do
sed -i -E 's,^#?(MSYS2_PATH_TYPE)=.+,\1=inherit,g' $n
done
exit

  1. I have restarted the mingw64 bash by executing C:\tools\msys64\mingw64.exe
  2. make build-virtualbox gives this error:

AzureAD+MichaelDoganbas@LAPTOP-4O0UBBTT MINGW64 ~
$ make build-virtualbox
make: *** No rule to make target 'build-virtualbox'. Stop.

AzureAD+MichaelDoganbas@LAPTOP-4O0UBBTT MINGW64 ~

Windows Host
System Type: 64-bit operating system, x64-based processor
Operating System: Windows 10 Pro
Version: 20H2
OS Build: 19042.685

Provider/Hypervisor
Software: Oracle VirtualBox
Version: 6.1.16 r140961 (Qt 5.6.2)

I think I should be able to locate the makefile in the mingw64 bash shell but I am just a beginner in this field and I am a beginner in "linux". Is this a bug? Or is it just me that needs to do a additional step? But I feel I have read your instructions very carefully:-)

I would really appreciate if you help me to troubleshoot this issue.

Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.