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 want to start with an installation of buster and clone the debian-cloud-images repository and install some dependencies. 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.1.0 and these steps apply to that version.
- Choose “Create a vustom virtual machine.”
- For the operating system select “Other Linux 4.x or later kernel 64-bit”. This is because VMWare doesn’t know about buster yet.
- Select “Legacy BIOS”.
- 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.”
- Finally, click “Customize Settings”. Give the system a name that you like.
Now you’ll see a settings dialog. Make these changes.
- Remove the camera.
- Remove the printer.
- Remove the sound card.
- Adjust the memory size and the total CPU count.
- Connect a CD/DVD drive and attach a buster boot disk. I’m using the
- Adjust the hard disk size.
- 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.
- Choose the correct language and keyboard configuration.
- Choose any hostname and domain name. It doesn’t matter.
- Choose any timezone. It doesn’t matter.
- Boot to
- Mount a separate
- Execute a shell in
Once you’re on the shell we’re going to edit
/etc/default/grub and make these changes:
- Comment out the lines labeled
- Change the line labeled
GRUB_CMDLINE_LINUXto be empty, like this:
- Change this line, too:
GRUB_CMDLINE_LINUX_DEFAULT="quiet elevator=noop net.ifnames=0 transparent_hugepages=never". I think that the
elevatoroption is redundant and you probably don’t need the
transparent_hugepagesoption but since I use Redis I put it in there.
/etc/default/grub we need to install it by running this command:
grub-mkconfig -o /boot/grub/grub.cfg
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 so now disconnect the drive and send Ctrl-Alt-Delete to the host. The host will now boot in VMWare Fusion.
There are two final steps before you’re on your own. You need to give the host some SSH keys and you need to expand the disk. These are quite easy:
dpkg-reconfigure openssh-server systemctl restart sshd resize2fs /dev/sda1
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.