hi in today's video I want to show you how you can use qmu as a kernel developer but first let's talk about what is qmu so basically qmu is an virtualizer so you can use it for virtualizing software or running virtual machines for example but the very cool thing about qmu is it's also an emulator for example if you have virtual box you can only run virtual machines for x86 systems if you're on x86 platform like a laptop or PC with an Intel processor but with qmu it is POS also possible to emulate other architectures and get for example virtual machines with yeah arm architectures or open risk five architectures up and running in today's video I want to show you how you can run a Linux kernel and a root file system built for r with qmu so let's get started the first thing we have to do is we have to install qmu so here I'm Arch and in Arch the package name is qmu system arm this is also a package name for obuntu for example but I have already installed a package so I can skip it for now and now I need to download something so we will need a root file system therefore we will use busy box we need to compile the Linux kernel and we need the tool chain to build everything so the first thing we need is we have to download a tool chain and here I am on the arm web page and here I can find the cross compiler which I can use for cross compiling arm so let's download the um arm non Linux can e a [Music] BF compiler okay this will take a few seconds then we will also need to download busy box which we can get from here and we also need to download a Linux kernel and here I will go with a long-term version 6. 1. 5 seems promising so let's download this okay so back in my terminal in this folder I will first extract the tool chain this will take just a moment as it's quite a bit of files to extract okay then I will extract busy box busy box okay and last but not least let's see if the download of the kernel is already done yeah it looks good so I can also extract the kernel in here okay so now let's see what we we have in this folder so we have this incredible long folder here containing our tool chain we have Psy box here and we have our Linux kernel here and the first thing I will do is I will rename this to arm Cano tool chain to make this a little bit this folder a little bit smaller and in here we have a bin folder containing the compilers we will need to compile everything okay so now let's start by with compiling the Linux kernel first we need to configure it our Target architecture will be arm and our cross compiler will be arm tool chain pin arm yeah this one here and I will use the default configuration for Arm based for Arm based kernel so this is the configuration which will be used and this fine and after applying the configuration let's build it and the build process will take several minutes so let me pause the video here and I'm back when the kernel is compiled successfully okay so the compilation has completed and if I look into Arch arm boot I can see here is my built kernel image or my image and here is my compressed image and if I take a look what f this is yeah data because this is a binary file but I think set image yeah Linux kernel arm boot executable set image little andian so this is exactly what we wanted to have cool so now the next step is we have to build busy box so here it's quite similar first I will use the default configuration here okay and now I will use menu config to set one option manually so here in settings we have option to build this as a statistic or static binary with no shared libraries and this is what I want to do the reason for this is when I using the static build I don't have to include any yeah any um yeah shared libraries or I don't have to copy any sh libraries from a cross compilers folder into my root file system so this is why I'm doing this and now let's build this to once again here I'm assigning the numbers of available threats of my CPU which is 12 in this case and this should build quite quickly but I will pause the video okay so now the build is successful and we can see here all the libraries resolve is needed can includ it okay let's check if we need any shared libraries for our um busy box install so we read elf minus lowercase D and then the binary we're interested in and then I will grab for needed yeah so I don't need any shed libraries in case I would build it without the static option here I would see all the libraries which are needed for running busy box cool good next thing we will do is I will run install here so it will copy everything in a under install folder which we can see here and now let's create our root file system so we need a PIN folder and aspin folder Etc procus and we need user and for user we need bin and S spin okay ah yeah wrong brace here sorry okay so now we have a root file system here cool and now what I will do is I will copy any everything from my Psy box under install um into root FS okay so now everything is here and let's navigate into the root fs and what I will do is I will create a new symbolic link um which will point to bin B box and I will call this init here so this is the init script which will be executed on Startup or when the kernel tries to call the init function this is what will be called okay so now we have to create some we have to create a little some um here some device files in the dev folder so with make not I will create some files so the first thing with the permission 660 I will create meem this is a character device my major device number one minor one and now of course I have to give it my password as I'm using sud sudo here okay and I need some more files so I need a ttyy s zero which or S two which is 4 and two then three and four this is just because of the virtual machine which I will be using with qmu and they need these device files here oh I want to have them in my def folder okay so let's um yeah move them okay so now in the def folder I have everything I need and now let's create uh compressed root file system so find everything in here print zero then I will use cpio and then I will use Gip to compress it and the result should be stored in routes.
cp. GC uh let me pause the video and check if I made a mistake here okay it should be let's see if this is working now yeah this looks good so now I have my root file system and now we can fire up qmu so qmu system arm the first thing we have to specify is the virtual machine we want to use if you want to see all which are supported I can use help here so these are are various virtual machines we have some a little bit more famous in here so we have we can emulate Rasberry pies here we can emulate the STM 32 F Discovery board but we some arm versatile boards which we have here but I will use this ver Target here which is an arm virtual machine okay so let's use word here with a mine or a lowercase m i can specify the amount of memory I want to give this machine here I'm passing 256 megabyte for example then with minus kernel I can pass in the kernel which should be booting and this can be found in Linux Arch arm boot set image with init Rd I can tell it which um yeah root file system which or which Ram disk it should use which is this one here and with append I can pass in some kernel options or I can append the kernel command line and we will need root isde slm and I will Al and I will also specify here no graphic because otherwise it would open up a second window in which I would see a graphic but I want to have the prints all here on my on in my terminal so I will use no graphic here so let's start this we can see the Linux kernel is putting up our inner process was started now here we have a shell but we have some messages here so let me quit from Q by typing control a x and let's take a look at these Arrow messages here so it seems I don't need ttys free I need tt3 so so I have to fix the um device files in my root file system yeah so let's remove all the I think I need sud sudo for this all the TTY files in here okay and now let's create new ones and this time I need two for two I need three and I need four okay so let me try to um yeah let's pack the root F system again okay and now let's try out qmu a second time and hopefully this time everything should work okay this is looking good so press enter to activate console and here we are in a console so if I type un name minus a we can see the corner version which I've used so 6. 1.
5 58 arm file 7 l so this is indeed a Linux virtual machine running arm cool so yeah it's working so this is how you can use qmu to emulate an arm by or a Linux kernel and a root file system built for arm in future videos I will show you a little bit more about qmu and my goal is to emulate a PCI card um with qmu and write a Linux driver for it so I guess that's it for today I hope you've enjoyed the video and learned something in case you want to support my work you can buy my coffee and buy my coffee.