Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rgl/esxi-vagrant

ESXi running in QEMU/KVM/libvirt/ESXi wrapped in a vagrant environment
https://github.com/rgl/esxi-vagrant

esx esxi kvm libvirt packer vagrant

Last synced: 3 months ago
JSON representation

ESXi running in QEMU/KVM/libvirt/ESXi wrapped in a vagrant environment

Awesome Lists containing this project

README

        

# About

This is a packer template for installing ESXi inside a VM in a way that
can be later used as a vagrant base box.

**NB** This builds a base box **without any datastore**. This means you
have to create one yourself in your vagrant environment (see the
[vagrant example](example)).

**NB** If you want to create a base box with a datastore, you have to edit
the `esxi.json` file to add `autoPartitionOSDataSize=4096` to the
`boot_command` array (after the `ks=` element) and increase `disk_size` to
a size that is big enough to hold your datastore.

**NB** This is needed until [packer#9160](https://github.com/hashicorp/packer/issues/9160) and [vagrant-libvirt#602](https://github.com/vagrant-libvirt/vagrant-libvirt/issues/602) are addressed.

## Usage

**NB** These instructions are for an Ubuntu 22.04 host.

Install Packer 1.6.0+ ([because we need to use the qemu bridge mode](https://github.com/hashicorp/packer/issues/9156)).

Download the [Free ESXi 8.0 (aka vSphere Hypervisor) iso file](https://www.vmware.com/go/get-free-esxi).

### qemu-kvm usage

Install qemu-kvm:

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

Allow non-root users to add tap interfaces to a bridge:

```bash
# allow non-root users to add tap interfaces to virbr0.
# NB a tap (L2) interface is created by qemu when we use a bridge netdev.
sudo chmod u+s /usr/lib/qemu/qemu-bridge-helper
sudo bash -c 'mkdir -p /etc/qemu && echo "allow virbr0" >>/etc/qemu/bridge.conf'
```

Create the base box and follow the returned instructions:

```bash
time make build-libvirt
```

Launch the vagrant example:

```bash
apt-get install -y virt-manager libvirt-dev
vagrant plugin install vagrant-libvirt # see https://github.com/vagrant-libvirt/vagrant-libvirt
cd example
time vagrant up
```

Try using it:

```bash
vagrant ssh
ps -c
esxcli software vib list
esxcli system version get
exit
```

Create the [debian-vagrant base box and example](https://github.com/rgl/debian-vagrant) within this esxi instance.

#### raw qemu-kvm usage

To fiddle with ESXi it can be more straightforward to directly use qemu, e.g.:

```bash
# allow non-root users to add tap interfaces to virbr0.
# NB a tap (L2) interface is created by qemu when we use a bridge netdev.
sudo chmod u+s /usr/lib/qemu/qemu-bridge-helper
sudo bash -c 'mkdir -p /etc/qemu && echo "allow virbr0" >>/etc/qemu/bridge.conf'

# create an empty disk.
qemu-img create -f qcow2 test.qcow2 40G
qemu-img info test.qcow2

# launch the vm.
# NB to known the available options use:
# qemu-system-x86_64 -machine help
# qemu-system-x86_64 -cpu help
# qemu-system-x86_64 -netdev help
# qemu-system-x86_64 -device help
# see http://wiki.qemu.org/download/qemu-doc.html
qemu-system-x86_64 \
-name 'ESXi Test Baseline' \
-machine pc,accel=kvm \
-cpu host \
-m 4G \
-smp cores=4 \
-k pt \
-qmp unix:test.socket,server,nowait \
-netdev bridge,id=net0,br=virbr0 \
-device vmxnet3,id=nic0,netdev=net0,mac=52:54:00:12:34:56 \
-drive if=ide,media=disk,discard=unmap,format=qcow2,cache=unsafe,file=test.qcow2 \
-drive if=ide,media=cdrom,file=VMware-VMvisor-Installer-8.0-20513097.x86_64.iso

# wait for the mac address to appear in the virbr0 interface, e.g. it
# should output something alike:
# IP address HW type Flags HW address Mask Device
# 192.168.121.111 0x1 0x2 52:54:00:12:34:56 * virbr0
cat /proc/net/arp

# play with the qmp socket.
# see https://gist.github.com/rgl/dc38c6875a53469fdebb2e9c0a220c6c.
nc -U test.socket # directly access the socket.
qmp-shell test.socket # access it in a friendlier way.

# open a ssh session (after you enable ssh access in ESXi).
ssh -v [email protected]

# open a browser session.
xdg-open https://192.168.121.111
```

### VMware ESXi usage

Set your ESXi details, and test the connection to ESXi:

```bash
vagrant plugin install vagrant-vmware-esxi
cat >secrets.sh <secrets.sh <