Skip to content

Instantly share code, notes, and snippets.

@mikhailov

mikhailov/vbox.sh

Last active Jun 23, 2020
Embed
What would you like to do?
#!/bin/bash -e
curl -O http://ftp.heanet.ie/pub/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-Minimal.iso
export VM="MASTER"
export VMDISK="$VM-disk"
export REDHAT_IMAGE="/Users/user/Downloads/CentOS-7.0-1406-x86_64-Minimal.iso"
VBoxManage hostonlyif create
VBoxManage hostonlyif ipconfig vboxnet0 --ip 192.168.20.1
VBoxManage dhcpserver add --ifname vboxnet0 --ip 192.168.20.1 --netmask 255.255.255.0 --lowerip 192.168.20.10 --upperip 192.168.20.20 --enable
VBoxManage createhd --size 4096 --variant Fixed --filename ~/VirtualBox\ VMs/$VMDISK
VBoxManage createvm --register --name $VM --ostype RedHat_64
VBoxManage storagectl $VM --name "SATA Controller" --add sata --controller IntelAHCI
VBoxManage storageattach $VM --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $VMDISK.vdi
VBoxManage storageattach $VM --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium $REDHAT_IMAGE
VBoxManage modifyvm $VM --memory 512 --acpi on --boot1 dvd
VBoxManage modifyvm $VM --nic1 hostonly --nictype1 virtio --hostonlyadapter1 vboxnet0
VBoxManage modifyvm $VM --nic2 nat --nictype2 virtio
VBoxManage startvm $VM
VBoxManage controlvm $VM poweroff
VBoxManage storageattach $VM --storagectl "SATA Controller" --port 1 --device 0 --type dvddrive --medium none
VBoxManage clonevm $VM --name "SLAVE0" --register
VBoxManage clonevm $VM --name "SLAVE1" --register
VBoxManage startvm "SLAVE0" "SLAVE1" --type headless
ssh root@192.168.20.10 "echo 'HOSTNAME=SLAVE0' >> /etc/sysconfig/network; hostname SLAVE0"
ssh root@192.168.20.11 "echo 'HOSTNAME=SLAVE1' >> /etc/sysconfig/network; hostname SLAVE1"
# There is NO PROBLEM with IP addresses now. VMs are accessbile from the host.
# Guest VMs have access to the Internet via NAT, but host-only connection between each other,
# HOST can reach VMs via the following IP addresses:
# ssh root@192.168.20.10
# ssh root@192.168.20.11
@niccolox

This comment has been minimized.

Copy link

@niccolox niccolox commented Apr 12, 2015

Mirantis Openstack has a bunch of Virtualbox Bash scripts for test/dev installation (NOT Vagrant)

https://software.mirantis.com/quick-start/

this is not such a crazy idea

personally, I would love an alternative to Vagrant i.e. Ansible driven dev

all it would take is a Virtualbox module written based on some of the other providers ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.