Giter Site home page Giter Site logo

cesarjorgemartinez / build-virtual-machines-environment Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 6.0 377 KB

Automate Linux Virtual Machines for Cloud VirtualBox OpenStack VMware ESXI Nutanix CentOS Ubuntu

Home Page: https://cesarjorgemartinez.github.io/automate-virtual-machine-linux-images

License: GNU Affero General Public License v3.0

Shell 100.00%
centos windows cygwin packer qemu bash docker virtualbox vmware esxi openstack nutanix gnome virtual-machines cloud linux virtualization-systems build-automation ubuntu

build-virtual-machines-environment's Introduction

Automate Virtual Machine Linux Images


Author: Cesar Jorge Martínez

Site: https://cesarjorgemartinez.github.io/automate-virtual-machine-linux-images

Read the LICENSE GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007

Index

1. Introduction

This project helps to build automatically multiple Virtual Machine Images of Operating Systems that are compatible with different virtualization systems, as OpenStack, KVM, VirtualBox, VMware, VMware ESXI, Nutanix, etc.

The image formats that are generated are the following:

  • vmdk: For VirtualBox, VMware and VMware ESXI.
  • ovf: For VirtualBox, VMware and VMware ESXI.
  • qcow2: For OpenStack, KVM and Nutanix.

The virtualization system VirtualBox also uses the vdi format but it is not necessary since the VirtualBox itself converts the vmdk format into vdi.

You can deploy and boot directly these images in these virtualization systems without doing anything special or extra, thanks to the use of two systemd units:

  • control-cloud-init.service: If the virtual machine boots in OpenStack or KVM or AWS then lets execute cloud-init. If the virtual machine boots in VMware or VirtualBox or other virtualization systems then mask cloud-init.
  • guest-vmtools.service: If the virtual machine boots inside VirtualBox then install its GuestTools disabling others. If the virtual machine boots inside VMware or VMware ESXI then install its VMwareTools disabling others.

These images are ideal to work as servers in Cloud, traditional or development environments, and is very useful to work with Docker, because the size of the image created is very small and clean. These images are builded with a Linux admin account provided as parameter at the time of build. The cloud-init software use other account provided as optional parameter at the time of build (not created because the cloud-init do this work at the first boot of the virtual machine) that by default is cloud-user. Also these images come with six network intefaces named eth0, eth1, eth2, eth3, eth4 and eth5 by default.

To work with this software you need Windows 10 64 bits and CygWin 64 bits to use Linux-Bash commands.

1.2. Tested software versions

This project has been tested with the following software versions:

  • Windows: 10 64 bits updated
  • VirtualBox: 6.1.16
  • CygWin 64 bits: 64 bits 3.1.7(0.340/5/3)
  • QEMU for Windows: qemu-w64-setup-20201124 qemu-img version 5.1.92 (v5.2.0-rc2-11843-gf571c4ffb5-dirty)
  • VMware Workstation Player: 16.1.0 build-17198959
  • VMware ESXI: 6.5 and 6.7
  • OpenStack (curl https://<identity_endpoint>:13000/v3): 3.7 Newton
  • Nutanix: community edition 5.18

2. Operating Systems that can be built

Actually you can build the following Operating Systems:

  • CentOS 7 Minimal: CentOS 7.9 (2009)
  • CentOS 8 Minimal: CentOS 8.2 (2004) and CentOS 8.3 (2011)
  • Ubuntu 20 Minimal: Ubuntu 20.04.1 (server)

3. Create and configure the environment

You need to do the next tasks.

3.1. Install VirtualBox

Go to this URL https://www.virtualbox.org/wiki/Downloads and install latest VirtualBox for Windows. You need to ensure that in addition to installing VirtualBox you also install Oracle VM VirtualBox Extension Pack.

3.2. Install VMware Workstation Player

Go to this URL https://www.vmware.com/go/downloadworkstationplayer and install latest VMware Workstation Player for Windows.

This is optional step only if you will be use VMware or VMware ESXI.

3.3. Install CygWin 64 bits

To install CygWin 64 bits you need to do the following tasks:

  • With a browser download https://cygwin.com/setup-x86_64.exe.
  • Install this doing right button of the mouse over this downloaded file, and Run as admistrator.
  • Following.
  • Install from Internet.
  • Following.
  • Local Package Directory: C:\cygwin64\mypackages.
  • Use System Proxy Settings.
  • Choose A Download Site, choose one and:
  • Following.
  • Use default packages (Don't select others).
  • Following.
  • Following.
  • Finalize.

When terminate these tasks, then:

  • In Cygwin64 Terminal Desktop Icon click on right button of the mouse and select properties.
  • Click in Advanced options.
  • Set Run as administrator and click Accept and Accept.

3.4. Disable Windows Python installation

To prevent that CygWin use the Python installed in Windows (if exist), do the following to disable access to Windows Python installation:

  • Enter in a Cygwin64 session.
  • Launch this:
echo $'PATH=$(echo $PATH | tr \':\' \'\\n\' | grep -v "/cygdrive/.*/Python[23]" | paste -sd:)' >> .bash_profile
exit

3.5. Install needed CygWin packages

You need to do the following tasks:

  • Enter in a Cygwin64 session.
  • Launch this:
curl -O https://cygwin.com/setup-x86_64.exe
./setup-x86_64.exe -q --upgrade-also --packages="bash,python2,python2-devel,python2-setuptools,python2-crypto,python2-paramiko,python2-boto,python2-certifi,python2-pip,python2-nacl,python3,python3-devel,python38,python38-devel,openssl,openssh,openssl-devel,libffi-devel,gcc-g++,git,nc,nc6,libsodium-common,libsodium-devel,dialog,figlet,rsync,gettext,autoconf,automake,binutils,cygport,gcc-core,make,lynx,zip,sshpass,jq,expect,procps-ng"

3.6. Install Python system pip packages

To work with Python install basic pip packages in a system level:

TODO: Check if this tasks are obsoleted using last CygWin version. In a existing CygWin installation is not necessary.

  • Enter in a Cygwin64 session.
  • Launch this:
easy_install-2.7 pip
pip install --upgrade pip
pip install --upgrade setuptools
pip install --upgrade wheel
pip install --upgrade virtualenv
pip install --upgrade terrafile

3.7. Configure your Git environment to work with github

To work with https://github.com you need to do the next tasks. Example to use Git with SSH.

  • Get your public and private SSH keys of your GitHub account.

  • Enter in a Cygwin64 session.

mkdir -p ~/.ssh
echo "StrictHostKeyChecking no
UserKnownHostsFile /dev/null
ServerAliveInterval 30
ServerAliveCountMax 3
ControlMaster no

Host github.com
  IdentityFile ~/.ssh/id_rsa_private_github
" > ~/.ssh/config
  • Store your public key to ~/.ssh/id_rsa_private_github.pub and your private key to ~/.ssh/id_rsa_private_github.

  • Set good permissions in the SSH config folder.

chmod 600 ~/.ssh/*
chmod 700 ~/.ssh
  • Configure your Git client settings. You need the user.name and user.email of your GitHub account. Enter in a Cygwin64 session.
git config --system color.ui "true"
git config --system alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
git config --system user.name "<your user.name>"
git config --system user.email "<your user.email>"
git config --system http.sslVerify false

3.8. Howto generate SHA-512 password hashes with Python3 in CygWin command line

To generate SHA-512 password hashes you need to do the following tasks:

  • Enter in a Cygwin64 session.

  • Launch this command where password is the plain text password:

python3 -c 'import crypt; print(crypt.crypt("password", crypt.mksalt(crypt.METHOD_SHA512)))'

4. Getting started

After you have completed the previous sections, follow the next steps.

4.1. Clone and enter into the git root directory of this repository

Do the following tasks:

git clone [email protected]:cesarjorgemartinez/automate-virtual-machine-linux-images.git
cd automate-virtual-machine-linux-images

4.2. Install QEMU for Windows

The QEMU for Windows is needed to convert the vmdk to qcow2 image format. Launch this command:

download-and-install-qemu.sh

Then a QEMU for Windows installer window appears and do the following:

  • Please select a language: Select your language, as example English / English
  • Click in OK
  • Next
  • I Agree
  • Next
  • Install
  • Finish

5. Build CentOS 7 Minimal image

This section explains howto build this Virtual Machine Image: Build CentOS 7 Minimal image.

6. Build CentOS 8 Minimal image

This section explains howto build this Virtual Machine Image: Build CentOS 8 Minimal image.

7. Build Ubuntu 20 Minimal image

This section explains howto build this Virtual Machine Image: Build Ubuntu 20 Minimal image.

build-virtual-machines-environment's People

Contributors

cesarjorgemartinez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

build-virtual-machines-environment's Issues

Build for Debian

Is your feature request related to a problem? Please describe.
I need vms for Debian

Describe the solution you'd like
One step for build this.

Describe alternatives you've considered
By now is one dir to build

Additional context
None

BUG Ubuntu 20.04.1 with packer 1.6.5 show error ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

Describe the bug
BUG Ubuntu 20.04.1 with packer 1.6.5 show error ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

To Reproduce
Steps to reproduce the behavior:
Ubuntu20Minimal/bin/build-virtual-machine.sh --adminuser user --adminpass pass

Then when reach to install the SSH server:
==> virtualbox-iso: Error waiting for SSH: Packer experienced an authentication error when trying to connect via SSH. This can happen if your username/password are wrong. You may want to double-check your cr
edentials as part of your debugging process. original error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

Expected behavior
Ubuntu build successful.

Build vms using other SO apart from Windows. It is considered Ubuntu or Linux in general

Is your feature request related to a problem? Please describe.
Build vms using other SO apart from Windows. It is considered Ubuntu or Linux in general.
I don't have Windows

Describe the solution you'd like
One process to detect and build being transparent regarding the SO that I use for building.

Describe alternatives you've considered
None

Additional context
None

Multiple Operating System builds

Is your feature request related to a problem? Please describe.
Need to build multiple Operating Systems.

Describe the solution you'd like
One solution more simple and one directory by Operating System.

Show in host-info vcpus sockets cores and threads

Is your feature request related to a problem? Please describe.
The host-info utility not show this information and exist environments with multiple virtual cpus

Describe the solution you'd like
Show in host-info vcpus sockets cores and threads using lscpu output

Table for the best operating systems to build

Is your feature request related to a problem? Please describe.
Table for the best operating systems to build. I detect that I cannot decide what operating systems are the best election

Describe the solution you'd like
By now is unknown

Describe alternatives you've considered
Unknown

Additional context
None

Cannot control correctly disable or enable the cloud-init version 20.1 that use Ubuntu 20.0x

Describe the bug
Cannot control correctly disable or enable the cloud-init version 20.1 that use Ubuntu 20.0x

To Reproduce
Generate the Ubuntu 20 Minimal image.
Load into VMware or VirtualBox.
Boot the virtual machine.
Then, the cloud-init not disabled and causes delays 2 or 3 minutes and malfunctions.

Expected behavior
When boot then all cloud-init must be disabled. Enabled in other environments supported and that use cloud-init.

Build for Ubuntu not works correctly and it is very disk expensive

Describe the bug
Build for Ubuntu not works correctly and it is very disk expensive

To Reproduce
Steps to reproduce the behavior:
Build Ubuntu 20. Not start well and it is very high consumption 1Gb or more.

Expected behavior
This is not clear. Maybe Ubuntu not for servers virtualized well

Screenshots
None

Additional context
None

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.