Skip to content

Instantly share code, notes, and snippets.

@ardrabczyk
Last active September 28, 2020 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ardrabczyk/65b68d0121f2964cd99e to your computer and use it in GitHub Desktop.
Save ardrabczyk/65b68d0121f2964cd99e to your computer and use it in GitHub Desktop.
vb.sh: create a new virtualbox machine
#!/usr/bin/env sh
# vb.sh: create a new virtualbox machine
#
## (c) 2016-2020, Arkadiusz Drabczyk, arkadiusz@drabczyk.org
if [ "$#" -lt 2 ]
then
echo Usage: "$0" \<MACHINE-NAME\> \<ISO\> [RAM] [DISK] [TYPE]
echo Example:
echo ./vb.sh \"Slackware x64 14.1\" slackware64-14.1-install-dvd.iso
echo RAM is 2 gigabytes if not explicitly requested.
echo Disk is 30 gigabytes if not explicitly requested.
echo Type is Linux_64 if not explicitly requested.
exit 1
fi
ram=${3:-2048}
hdd=${4:-30000}
type=${5:-Linux_64}
set -e
VBoxManage createvm --name "$1" \
--ostype "$type" \
--register
VBoxManage modifyvm "$1" \
--memory "$ram" \
--usb on
VBoxManage modifyvm "$1" \
--nic1 bridged \
--bridgeadapter1 eth0
VBoxManage modifyvm "$1" \
--vram 128
VBoxManage modifyvm "$1" \
--graphicscontroller vmsvga
VBoxManage modifyvm "$1" \
--firmware efi
VBoxManage createhd --filename "$PWD/${1}.vdi" \
--size "$hdd"
VBoxManage storagectl "$1" \
--name "IDE Controller" \
--add pcie \
--controller NVMe
VBoxManage storageattach "$1" \
--storagectl "IDE Controller" \
--port 0 \
--device 0 \
--type hdd \
--medium "$PWD/${1}.vdi"
VBoxManage storagectl "$1" \
--name "For CD" \
--add ide
VBoxManage storageattach "$1" \
--storagectl "For CD" \
--port 1 \
--device 0 \
--type dvddrive \
--medium "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment