2.2 KiB
2.2 KiB
layout | title | date | permalink | categories | author | published |
---|---|---|---|---|---|---|
post | My first contribution to Linux Kernel: Step by step | 2021-11-06 00:00:00 | first-linux-contribution/ | programming | Mahdi | false |
November 6th: Create a virtual machine for Archlinux on my macOS using QEMU:
- Download the Archlinux iso image
- Create a qemu disk: {% highlight bash %} qemu-img create disk.img 15G {% endhighlight %}
- Start the machine and install Archlinux {% highlight bash %} qemu-system-x86_64 -cdrom archlinux-2021.11.01-x86_64.iso -boot order=d -drive format=raw,file=disk.img -m 8G -smp cpus=4 {% endhighlight %}
- Start the machine after installing {% highlight bash %} qemu-system-x86_64 -drive format=raw,file=disk.img -m 2G {% endhighlight %}
- Install dependencies: {% highlight bash %} pacman -S gcc git make {% endhighlight %}
- Clone linux: {% highlight bash %} git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git {% endhighlight %}
- Install necessary dependencies {% highlight bash %} pacman -S flex base-devel xmlto kmod inetutils bc libelf git cpio perl tar xz {% endhighlight %}
- Copy configuration of archlinux (optional: also use modprobed-db to remove unnecessary modules) {% highlight bash %} zcat /proc/config.gz > .config {% endhighlight %}
- Make! The
-j8
parameter specifies the number of threads to be used by the build. My CPU has 8 threads and so I use it all. {% highlight bash %} make -j8 {% endhighlight %} - Install the newly built Kernel. I create this as a script file and run it after every build from the root of repository. {% highlight bash %} make -j8 modules_install RELEASE=$(cat include/config/kernel.release) cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linux${RELEASE} mkinitcpio -k $RELEASE -g /boot/initramfs-linux${RELEASE}.img mkinitcpio -k $RELEASE -s autodetect -g /boot/initramfs-linux-fallback${RELEASE}.img {% endhighlight %}
- Run grub-mkconfig to add a menu option for this new kernel {% highlight bash %} grub-mkconfig -o /boot/grub/grub.cfg {% endhighlight %}
- Reboot and choose the new kernel (might be under "Advanced" in the bootloader)