Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created July 31, 2013 18:06
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 mitchellh/6124502 to your computer and use it in GitHub Desktop.
Save mitchellh/6124502 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
IMAGE="image.bin"
DISK="coreos.vdi"
VM_NAME="CoreOS"
# Delete any existing VDI
rm -f $DISK
# Convert the raw image to a disk for VirtualBOx
VBoxManage convertfromraw $IMAGE $DISK
# Create a new VM to house this disk
VBoxManage createvm --name $VM_NAME --ostype 'Oracle_64' --register
VBoxManage modifyvm $VM_NAME --boot1 disk --boot2 dvd --boot3 none --boot4 none
VBoxManage modifyvm $VM_NAME --cpus 1
VBoxManage modifyvm $VM_NAME --memory 512
# Create the IDE controller so we can attach the disk
VBoxManage storagectl $VM_NAME --name 'IDE Controller' --add ide
VBoxManage storageattach $VM_NAME \
--storagectl 'IDE Controller' \
--port 0 --device 0 \
--type hdd \
--medium $DISK
# Create the Vagrantfile to package with the box
cat << 'EOF' > Vagrantfile.pkg
Vagrant.configure("2") do |config|
# SSH in as the 'core' user since that is recommended with CoreOS
config.ssh.username = "core"
# Disable the base shared folder so that no guest additions are required
config.vm.synced_folder ".", "/vagrant", disabled: true
end
EOF
# Export the machine
vagrant package --base $VM_NAME \
--output 'coreos.box' --Vagrantfile Vagrantfile.pkg
# Clean up the VM, we don't need it anymore. This will also delete our
# disk image.
VBoxManage unregistervm $VM_NAME --delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment