Having recently got Back in to OS Development, I found myself needing to set up my development environment, having not touched a cross-compiler or Linux for many years. I use Windows 10 for my day-to-day computing (and will be among those switching to Windows 11 on any of my PC’s that are compatible), but I’ve found that GCC on Linux is by far my preferred toolchain for OS Development. Yes, I know you can do this without Linux at all (https://wiki.osdev.org/Visual_Studio), but that just doesn’t “do it” for me.
Just prior to stopping OS development last time, I had switched from using Cygwin to WSL. The close to native Ubuntu distro was perfect for my needs. This time, I’ve switched to WSL2 and I’m impressed.
So, how to start? Well, in the “old days” (a couple of months ago…) WSL 2 required patching windows, Powershell commands, adding Windows Features, enabling hyper-v and so on. No more! Now, after checking a couple of prerequisites, WSL2 is one command away!
This is really easy now. You no longer have to install the Hyper-V platform or go in to “Programs and Features”. All you need to do is enable the ONE change that Windows is unable to – a BIOS setting. So enter your your BIOS setting and, on Intel processors ensure that VT-x is enabled. On AMD processors ensure that AMD-V is enabled. I’ve found that generally on Intel motherboards, this setting quite high up and easy to find in the BIOS (sorry, UEFI!) settings page. For AMD, I often had to do some scratching around in advanced CPU settings subpages. But that’s it – one setting change and you’re ready!
Oh – perhaps one more thing. May be a good idea to check Windows is up to date…
Activating and installing WSL2
Now you have your CPU’s virtualisation enabled, there’s just one thing to do. Open Powershell as an administrator (Start –> right click on Powershell –> Run as Administrator) and type the following:
That’s it! Windows will now install hyper-v, set WSL2 as the default and install the default Ubuntu distro! My PC didn’t even reboot, but YMMV depending on whether you were already using hyper-v or not.
Once that’s complete, fire up Ubuntu. It will do some initial config which takes a while and will then ask for your new username and password. You’ll find yourself dumped in to your home directory. As always with these things, you may now like to:
sudo apt-get update
sudo apt-get upgrade
For a nice easy way to access your files from the Windows filesystem, take a look at the very short article, Accessing WSL Filesystem from Windows.
And you’re ready to go with the next step – Setting up the GCC Toolchain.