Skip to main content

Using Debian Cloud Images in VMWare Fusion

Published

In my last post I described how to use debian-cloud-tools to build an AMI for AWS EC2 instances. What about running that same instance locally? Personally, I do most of my development in VMWare Fusion and I want that instance to look like my AWS instance. I use VMWare Fusion because I want to be able to develop without an internet connection and because I don’t want to pay to run two instances in the cloud. Let’s see how I did this.

The steps start out the same as building for AWS. You will run all of these commands as root and you can work out of the root user’s home directory. Thus I will not write sudo or mention logging in as root.

First we need to install some software:

apt-get install -y --no-install-recommends \
    ca-certificates debsums dosfstools fai-server fai-setup-storage \
    make python3 python3-libcloud python3-marshmallow qemu-utils udev sudo rsync

Then you will run the build like this:

bin/debian-cloud-images build buster nocloud amd64 \
    --build-id manual --version 1 --override-name nocloud-buster-image --build-type official

That command will run for a while and create a file called nocloud-buster-image.raw. We need to convert that to a VMDK image usable by VMWare Fusion. That can be done like this:

qemu-img convert -O vmdk nocloud-buster-image.raw nocloud-buster-image.vmdk

Once you have a VMDK image, copy it to the host where you run VMWare Fusion. I’m running VMWare Fusion 11.5 and these steps apply to that version.

  1. Choose “Create a vustom virtual machine.”
  2. For the operating system select “Debian 10.x 64-bit”.
  3. Select “Legacy BIOS”.
  4. Select “Use an existing virtual disk.” We’re going to select the VMDK file that we just created and we want to “make a separate copy of the virtual disk.”
  5. Finally, click “Customize Settings”. Give the system a name that you like.

Now you’ll see a settings dialog. Make these changes.

  1. Remove the camera.
  2. Remove the printer.
  3. Remove the sound card.
  4. Remove the USB controller.
  5. Adjust the memory size and the total CPU count to your preferences.
  6. Connect a CD/DVD drive and attach a buster installation ISO. I’m using the debian-10.x.x-amd64-netinst.iso boot disk.
  7. Adjust the hard disk size to your preferences.
  8. Set the CD/DVD drive as the startup disk and restart.

Now you’ll be at a Debian installer menu. Choose “Advanced options” and then “Rescue mode”. This will begin booting the rescue disk where we will make a couple changes.

  1. Choose the correct language and keyboard configuration.
  2. Choose any hostname and domain name. It doesn’t matter.
  3. Choose any timezone. It doesn’t matter.
  4. Boot to /dev/sda1.
  5. Mount a separate /boot/efi partition.
  6. Execute a shell in /dev/sda1.

Once you’re on the shell we’re going to edit /etc/default/grub and make these changes:

  1. Comment out the lines labeled GRUB_TERMINAL and GRUB_SERIAL_COMMAND.
  2. Change the line labeled GRUB_CMDLINE_LINUX to be empty, like this: GRUB_CMDLINE_LINUX="".
  3. Change this line, too: GRUB_CMDLINE_LINUX_DEFAULT="quiet elevator=noop net.ifnames=0 transparent_hugepages=never". I think that the elevator option is redundant and you probably don’t need the transparent_hugepages option but since I use Redis I put it in there.

After adjusting /etc/default/grub we need to install it by running this command:

update-grub

And finally, right now we have no users and no passwords. We need to give the root user a password by running the passwd command. Just choose a password. You can change it or disable it later or add new users later.

Now exit out of the shell and reboot. When it reboots it will be on the Debian installer again and we are done with the installer so now disconnect the CD/DVD drive and send Ctrl-Alt-Delete to the host. The host will now boot normally.

There are two final steps before you’re on your own. You need to give the host some SSH keys and create the admin user. These are quite easy:

dpkg-reconfigure openssh-server
systemctl restart sshd
adduser admin

You can choose to examine the SSH configuration but I used the existing one without issue.

Now you have a VMWare Fusion cloud host that looks just like your AWS host.

And while you’re at it, you might find yourself wanting to edit the networking configuration to, for example, adjust the subnet that your host is on or to, say, assign a static DHCP IP address. You can adjust the subnet by editing this file:

sudo vi /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

Then restart networking like this:

sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --configure

Then, once the host is configured and you have a MAC address for it, edit this file:

sudo vi /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

You want to add a block like this at the very bottom:

host dev {
    hardware ethernet 00:0C:29:F4:40:66;
    fixed-address 10.64.0.254;
}

And then, again, restart networking.