{"id":627,"date":"2018-06-21T21:15:01","date_gmt":"2018-06-21T19:15:01","guid":{"rendered":"https:\/\/www.anginf.de\/?p=627"},"modified":"2018-06-22T09:47:00","modified_gmt":"2018-06-22T07:47:00","slug":"virtualbox-on-server","status":"publish","type":"post","link":"https:\/\/www.anginf.de\/?p=627","title":{"rendered":"VirtualBox on Server"},"content":{"rendered":"<p>I wanted to create a headless VirtualBox on a remote server. I did this before but didn&#8217;t remember the correct sequence, so I thought I&#8217;d better save the work for the next time and write my steps down:<\/p>\n<pre lang=\"bash\">\r\nVMNAME=\"newvm\"\r\nmkdir -p \"\/opt\/VirtualBox VMs\/${VMNAME}\"\r\ncd \"\/opt\/VirtualBox VMs\/${VMNAME}\"\r\n# You may have to change the next line:\r\nwget -nc http:\/\/releases.ubuntu.com\/18.04\/ubuntu-18.04-desktop-amd64.iso\r\n# Create a disk size that would fit your operation system. Here I chose 32768 MB = 32 GB.\r\nVBoxManage createhd --filename \"${VMNAME}\".vdi --size 32768\r\n# Create the VM itself. The available ostypes can be listed by issuing 'VBoxManage list ostypes'\r\nVBoxManage createvm --name \"${VMNAME}\" --ostype \"Ubuntu_64\" --register\r\n# Add a SATA controller with the dynamic disk attached.\r\nVBoxManage storagectl \"${VMNAME}\" --name \"SATA Controller ${VMNAME}\" --add sata --controller IntelAHCI\r\nVBoxManage storageattach \"${VMNAME}\" --storagectl \"SATA Controller ${VMNAME}\" --port 0 --device 0 --type hdd --medium ${VMNAME}.vdi\r\n# Add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive:\r\nVBoxManage storagectl \"${VMNAME}\" --name \"IDE Controller ${VMNAME}\" --add ide\r\nVBoxManage storageattach \"${VMNAME}\" --storagectl \"IDE Controller ${VMNAME}\" --port 0 --device 0 --type dvddrive --medium ubuntu-18.04-live-server-amd64.iso\r\n# Memory and graphics settings\r\nVBoxManage modifyvm \"${VMNAME}\" --memory 4096 --vram 128\r\n# If you want the network to be nat'ed:\r\nVBoxManage modifyvm \"${VMNAME}\" --nic1 nat\r\n\r\n# Disable audio\r\nVBoxManage modifyvm \"${VMNAME}\" --audio none\r\n\r\n# Enable ssh-access\r\nVBoxManage modifyvm \"${VMNAME}\" --natpf1 \"guestssh,tcp,127.0.0.1,60022,,22\"\r\n# If you ever want to remove this:\r\n# VBoxManage modifyvm \"${VMNAME}\" --natpf1 delete \"guestssh\"\r\n\r\n# Enable VRDE \/ You need this especially for the installation process\r\nVBoxManage modifyvm \"${VMNAME}\" --vrde on\r\nVBoxManage modifyvm \"${VMNAME}\" --vrdeaddress 127.0.0.1\r\n\r\n# Extensionpack to access via RDP etc.\r\nwget -nc https:\/\/download.virtualbox.org\/virtualbox\/5.2.12\/Oracle_VM_VirtualBox_Extension_Pack-5.2.12.vbox-extpack\r\nVBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.12.vbox-extpack\r\n\r\n\r\n# Bootup:\r\nVBoxHeadless -s \"${VMNAME}\"\r\n# It should be available via RDP on local port 3389.\r\n\r\n# Shutdown (three methods, best to worst):\r\n# 1.) Inside of the virtualbox\r\n# 2.) virtual powerbutton\r\nVBoxManage controlvm \"${VMNAME}\" acpipowerbutton\r\n# 3.) virtual power off\r\nVBoxManage controlvm \"${VMNAME}\" poweroff\r\n\r\n# If the installation is complete, shutdown the VirtualBox and eject the iso:\r\nVBoxManage storageattach \"${VMNAME}\" --storagectl \"IDE Controller ${VMNAME}\" --port 0 --device 0 --type dvddrive --medium none\r\n<\/pre>\n<p>If you want to secure your virtual machine even more (after logging into another openvpn, for example), you can use ufw, but remember that the connection comes from the VirtualBox Interface:<\/p>\n<pre lang=\"bash\">\r\nsudo ufw allow from 10.0.2.0\/24 to any\r\n<\/pre>\n<p><!--\n$ VBoxManage modifyvm $VM --ioapic on\n$ VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none\n$ VBoxManage modifyvm $VM --nic1 bridged --bridgeadapter1 e1000g0\n--><\/p>\n<p>Inspired by these posts on the internet:<\/p>\n<ul>\n<li>https:\/\/www.perkin.org.uk\/posts\/create-virtualbox-vm-from-the-command-line.html<\/li>\n<li>https:\/\/forums.virtualbox.org\/viewtopic.php?f=6&#038;t=65975<\/li>\n<li>https:\/\/askubuntu.com\/questions\/42482\/how-to-safely-shutdown-guest-os-in-virtualbox-using-command-line<\/li>\n<li>http:\/\/arunnsblog.com\/2010\/07\/20\/nat-with-port-forwarding-for-virtual-box\/<\/li>\n<li>https:\/\/www.reddit.com\/r\/virtualbox\/comments\/5lze8p\/remove_sound_card_with_vboxmanage\/<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to create a headless VirtualBox on a remote server. I did this before but didn&#8217;t remember the correct sequence, so I thought I&#8217;d better save the work for the next time and write my steps down: VMNAME=&#8220;newvm&#8220; mkdir -p &#8222;\/opt\/VirtualBox VMs\/${VMNAME}&#8220; cd &#8222;\/opt\/VirtualBox VMs\/${VMNAME}&#8220; # You may have to change the next line: &hellip; <a href=\"https:\/\/www.anginf.de\/?p=627\" class=\"more-link\"><span class=\"screen-reader-text\">VirtualBox on Server<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-627","post","type-post","status-publish","format-standard","hentry","category-allgemein"],"_links":{"self":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=627"}],"version-history":[{"count":17,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions"}],"predecessor-version":[{"id":645,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions\/645"}],"wp:attachment":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}