/ howto

how to export a digital ocean droplet to vmware / virtual box

UPDATE (11/7/18): there may be an easier way to do this now. also, the boot interface is now able to be accessed by using digital ocean's web console feature so you can now modify grub to boot an iso and image your vps that way. guide coming soon! see digital ocean's How To Create an Image of Your Linux Environment and Launch It On DigitalOcean.

i have always wished digital ocean had a way to download your droplet to your local computer so you could run it in a vm and do various things offline. by chance, one of my droplets had disk errors that needed to be worked out by fscking it from a recovery console. taking advantage of the downtime, i created an image of my droplet from the recovery console and then modified it so that i could boot it with vmware workstation (or virtual box). here's how:

  1. if you don't have a block storage disk already, create one and attach it to your droplet. you can delete this after you image your droplet.
  2. open a support ticket and request your droplet be put in recovery mode. this may take up to 6 hours depending on when you open a ticket.
  3. once in recovery mode, first ensure your disk is free of errors by running fsck:

fsck -vfy /dev/vda1

  1. create an image of your root file system while it is offline using dd and gzip. in my case a 90% full 40gb droplet image compressed to about 18gb.

dd if=/dev/vda1 | gzip -c > vda1.img.gz

  1. test the gzip archive and then create a checksum of your disk image to ensure it's consistency is intact after being transferred.

gzip -t vda1.img.gz ; md5sum vda1.img.gz > vda1.img.gz.md5

  1. using something like filezilla, connect to your droplet over sftp/scp (port 22) and transfer the vda1.img.gz to your local disk.

  2. now that you have your droplet image (vda1.img.gz) locally, check the md5sum again and if it's OK go ahead and create a backup of it by copying it somewhere. (making it read-only is good too)

  3. if you are on windows, use vmware/vbox to boot into an ubuntu iso. if you are on linux, your already good for this next part. convert your disk image to a vmdk by using qemu-img from the debian package qemu-tools (apt-get install qemu-tools)

gzip -d vda1.img.gz; qemu-img convert -O vmdk vda1.img

  1. now use vmware/vbox create an empty custom (advanced) ubuntu virtual machine and attach your newly created vda1.vmdk to it. in my case my VPS needed the non 64-bit ubuntu template.

  2. power on your new virtual machine and boot into recovery mode from grub. fsck your disk for good measure, enable networking and then select the option drop in to a root console. re-mount your root file system to read/write.

mount -o remount,rw /

  1. finally, edit the network interfaces to use dhcp by editing the file: /etc/network/interfaces. comment out the static eth0 & eth1 interfaces and insert the following:

auto eth0

iface eth0 inet dhcp

auto eth1

iface eth1 inet dhcp

some finishing touches..
restart networking using

service networking restart

then do:

dhclient eth0 ; dhclient eth1

to manually request an ip address via dhcp. use ifconfig to determine the ip address of your virtual machine and save it somewhere (like in your ssh client)

before you restart your virtual machine and boot it normally, start the sshd service and try to connect to it from your regular ssh client (like putty)

service ssh start

if you can connect successfully, reboot the virtual machine and boot from grub in normal mode. you have now successfully exported your digital ocean droplet in to locally hosted virtual machine. congrats!

update: here's another guide i found on the subject: ConvertDigitalOceanDroplettoVMwareVM.pdf. it does the same thing but in a little riskier way, dropping to runlevel 1 instead of booting into a recovery enviroment. piping the dd output, gzipping and sending the dd image out over ssh on the fly, which have always left me with corrupted disk images or slightly different checksums, but hey, YMMV.

nick giotis

nick giotis

linux sysadmin/devops w/occasional moonlighting into netsec & full stack development 💯✝️🇺🇸🇬🇷🇮🇪🏴

Read More