Build the Linux Kernel for VirtualBox

Feb 3, 2017
3 minute read

This post is a just a quick walkthrough of how to build the Linux kernel and run it on VirtualBox, instead of your
own machine. This is useful for any development in the kernel you might do that is purely software related, and
doesn’t require direct access to any hardware (though you can give VirtualBox direct access to a USB device).

The benefits of installing a custom kernel on a VM are manifold. The most compelling, in my opinion, is that
you don’t have to worry about messing up your system, so you have freedom to really experiment.

This will take a while (it is gigabytes large), and we have other stuff to do.

Go ahead and download the boot ISO for your favorite distro (the instructions will assume
the distro you are currently running, but that doesn’t have to be the case). Make sure that
the distro you want to use can work with the version of Linux that you want to build and install.

Next open up VirtualBox and create a new virtual machine. When you come to the option about
disks make sure to choose “Create a virtual hard disk now”. Make sure to choose the “VDI”
format rather than “VHD” or “VMDK”. Depending on what your’re doing and what your distro
expects you might have to allocate more or less space for the virtual disk, and if disk
performance isn’t a concern you can choose “Dynamically Allocated” rather than “Fixed Size”
for how to store it on your machine. Make note of where the vdi file is saved. Also, make
sure to size the volume decently large (say at least 15GB), the unmodified install commands
we will be running require a lot of space.

Click on the “Settings” button for your new virtual machine and then the “Storage” setting.
Click on the CD-looking icon and choose “Live CD/DVD” then choose your distro ISO from the
other CD-looking icon next to the “Optical Drive” dropdown.

Start the virtual machine and install the distro.

Once the distro is installed shutdown the VM, remove the Live CD/DVD and start the VM up
again to make sure the distro is installed.