Skip to content

Instantly share code, notes, and snippets.

@guipacheco2
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guipacheco2/10302171 to your computer and use it in GitHub Desktop.
Save guipacheco2/10302171 to your computer and use it in GitHub Desktop.
VirtualBox

Vagrantizar uma VM Comum.

  • Acessar VM atual e adicionar eth1 no /etc/network/interfaces
auto eth1
iface eth1 inet static
address 172.16.0.100
netmask 255.255.255.0
  • Parar a VM e renomear para um nome sem espaços, Ex: Ubuntu
  • Executar os seguintes comando para reconfiguração da VM
VBoxManage hostonlyif ipconfig vboxnet0 --ip 172.16.0.1 --netmask 255.255.255.0
  • Se vboxnet0 não existir...
VBoxManage hostonlyif create
VBoxManage modifyvm Ubuntu --cpus 2
VBoxManage modifyvm Ubuntu --memory 1024
VBoxManage modifyvm Ubuntu --nic1 nat
VBoxManage modifyvm Ubuntu --natdnshostresolver1 on
VBoxManage modifyvm Ubuntu --nic2 hostonly
VBoxManage modifyvm Ubuntu --hostonlyadapter1 vboxnet0
VBoxManage modifyvm Ubuntu --accelerate3d off
VBoxManage modifyvm Ubuntu --natpf1 "Embalagens,tcp,,8081,,8081"
VBoxManage modifyvm Ubuntu --natpf1 "Flow,tcp,,8000,,80"
VBoxManage modifyvm Ubuntu --natpf1 "Proof,tcp,,8080,,8080"
VBoxManage modifyvm Ubuntu --natpf1 "SSH,tcp,,2222,,22"
  • Alterar IP de dev-blabla.local para 172.16.0.100 no /etc/hosts do sistema hospedeiro (Mac) sudo vim /etc/hosts

Comandos do VirtualBox para iniciar e parar VM sem precisar abrir o programa do VirtualBox.

VBoxManage startvm Ubuntu --type headless
VBoxManage controlvm Ubuntu savestate
VBoxManage controlvm Ubuntu poweroff

===

Shell script para executar operações, como no vagrant.

sudo vim /usr/local/bin/dev

Copie o conteúdo do arquivo dev.sh, e adicionar no bin do usuário.

sudo chmod +X dev

Com isso é possível manipular a VM com comando como:

dev up
dev halt
dev suspend
dev ssh
#!/bin/sh
COMMAND=$1
VALIDS="'up', 'halt', 'suspend' e 'ssh'"
VM="Ubuntu"
HOST="dev@dev-guilherme.local"
SSHPASS="123mudar"
if [ -z "$COMMAND" ]
then
echo "Informe o comando, $VALIDS"
exit
fi
case "$COMMAND" in
up)
VBoxManage startvm $VM --type headless
;;
suspend)
VBoxManage controlvm $VM savestate
;;
halt)
VBoxManage controlvm $VM poweroff
;;
ssh)
expect -c "
spawn ssh $HOST
expect \"assword:\"
send $SSHPASS\r
interact
"
;;
*)
echo "Comandos válidos $VALIDS"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment