Skip to content

Instantly share code, notes, and snippets.

@elleryq
Last active January 6, 2022 17:18
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elleryq/cef9f5e15107e3d335cd to your computer and use it in GitHub Desktop.
Save elleryq/cef9f5e15107e3d335cd to your computer and use it in GitHub Desktop.
Import Vagrant box into VirtualBox
#!/bin/bash
BOX=$1
if [ -z $BOX ]; then
echo "Need argments."
exit -1
fi
if [ ! -e $BOX ]; then
echo "Not existed."
exit -2
fi
mkdir -p /tmp/box
cp $BOX /tmp/box/$BOX
# Use the original box name as VM name.
# For example, your vagrant box is "myvm_xxxxxxxx", use "myvm"
VM="your_vm"
pushd /tmp/box
# extract box
tar xf $BOX
# import
vboxmanage import box.ovf
# Rename to a better name.
UUID=$(vboxmanage list vms | grep $VM | awk '{print $2;}')
vboxmanage modifyvm $UUID --name $VM
# p4p1 is your new network adapter name.
vboxmanage modifyvm $VM --bridgeadapter2 p4p1
popd
# remove temporary files
rm -rf /tmp/box
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment