better sections for linux blog post
This commit is contained in:
parent
20ade0c6d6
commit
14b9f9fc4b
@ -8,55 +8,61 @@ author: Mahdi
|
|||||||
published: false
|
published: false
|
||||||
---
|
---
|
||||||
|
|
||||||
November 6th:
|
I use a MacBook Pro (mid-2014) with macOS, so I need to have a virtual machine for running a linux system with my kernel. I will also be doing the coding on this linux virtual machine as building the kernel is easier in a linux system than macOS.
|
||||||
Create a virtual machine for Archlinux on my macOS using QEMU:
|
|
||||||
- [Download the Archlinux iso image](https://archlinux.org/download/)
|
# Setting up the Virtual Machine (Archlinux)
|
||||||
- Create a qemu disk:
|
|
||||||
|
I create a virtual machine with Archlinux on my macOS using QEMU:
|
||||||
|
|
||||||
|
1. [Download the Archlinux iso image](https://archlinux.org/download/)
|
||||||
|
2. Create a qemu disk:
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
qemu-img create disk.img 15G
|
qemu-img create disk.img 15G
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Start the machine and [install Archlinux](https://wiki.archlinux.org/title/Installation_guide)
|
3. Start the machine and [install Archlinux](https://wiki.archlinux.org/title/Installation_guide)
|
||||||
{% highlight bash %}
|
{% 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
|
qemu-system-x86_64 -cdrom archlinux-2021.11.01-x86_64.iso -boot order=d -drive format=raw,file=disk.img -m 8G
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Start the machine after installing (note I forward 2222 to 22 so I can SSH/SCP to the virtual machine. I also set 4 CPUs so I can use threads for faster builds in the VM)
|
4. Start the machine after installing (note I forward 2222 to 22 so I can SSH/SCP to the virtual machine. I also set 4 CPUs so I can use threads for faster builds in the VM)
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
qemu-system-x86_64 -boot -drive format=raw,file=disk.img -m 8G -smp cpus=4 -net user,hostfwd=tcp::2222-:22 -net nic
|
qemu-system-x86_64 -boot -drive format=raw,file=disk.img -m 8G -smp cpus=4 -net user,hostfwd=tcp::2222-:22 -net nic
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Install dependencies:
|
5. Install dependencies for building the kernel:
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
pacman -S gcc git make
|
pacman -S gcc git make
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Clone linux:
|
6. Clone linux:
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
|
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Install necessary dependencies
|
7. necessary dependencies
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
pacman -S flex base-devel xmlto kmod inetutils bc libelf git cpio perl tar xz
|
pacman -S flex base-devel xmlto kmod inetutils bc libelf git cpio perl tar xz
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Copy configuration of archlinux (optional: also [use modprobed-db to remove unnecessary modules](https://wiki.archlinux.org/title/Kernel/Traditional_compilation#Default_Arch_configuration))
|
8. Copy configuration of archlinux (optional: also [use modprobed-db to remove unnecessary modules](https://wiki.archlinux.org/title/Kernel/Traditional_compilation#Default_Arch_configuration))
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
zcat /proc/config.gz > .config
|
zcat /proc/config.gz > .config
|
||||||
{% endhighlight %}
|
{% 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.
|
9. 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 %}
|
{% highlight bash %}
|
||||||
make -j8
|
make -j8
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Install the newly built Kernel. I create this as a script file and run it after every build from the root of repository.
|
10. 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 %}
|
{% highlight bash %}
|
||||||
make -j8 modules_install
|
make -j8 modules_install
|
||||||
RELEASE=$(cat include/config/kernel.release)
|
RELEASE=$(cat include/config/kernel.release)
|
||||||
cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linux${RELEASE}
|
cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linux${RELEASE}
|
||||||
mkinitcpio -k $RELEASE -g /boot/initramfs-linux${RELEASE}.img
|
mkinitcpio -k $RELEASE -g /boot/initramfs-linux${RELEASE}.img
|
||||||
mkinitcpio -k $RELEASE -s autodetect -g /boot/initramfs-linux-fallback${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
|
grub-mkconfig -o /boot/grub/grub.cfg
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
- Reboot and choose the new kernel (might be under "Advanced" in the bootloader)
|
- Reboot and choose the new kernel (might be under "Advanced" in the bootloader)
|
||||||
- Setup your environment for development. Mine consists of setting up tmux so I can have multiple terminals and neovim.
|
|
||||||
|
# Development Environment
|
||||||
|
|
||||||
|
Setup your environment for development. Mine consists of setting up tmux so I can have multiple terminals and neovim.
|
||||||
|
|
||||||
|
In the guest machine:
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
pacman -S neovim openssh tmux
|
pacman -S neovim openssh tmux
|
||||||
echo '[[ -z "$TMUX" ]] && exec tmux' >> /etc/profile
|
echo '[[ -z "$TMUX" ]] && exec tmux' >> /etc/profile
|
||||||
@ -69,7 +75,7 @@ scp -P 2222 ~/.tmux.conf root@localhost:/root
|
|||||||
scp -r -P 2222 ~/.config/nvim root@localhost:/root/.config/
|
scp -r -P 2222 ~/.config/nvim root@localhost:/root/.config/
|
||||||
{% endhighlight %}
|
{% endhighlight %}
|
||||||
|
|
||||||
# Debugging Logs
|
# Debugging
|
||||||
There is a `pr_debug` function used over the code, in order to enable those logs in `dmesg` for a specific module, you can do this:
|
There is a `pr_debug` function used over the code, in order to enable those logs in `dmesg` for a specific module, you can do this:
|
||||||
|
|
||||||
{% highlight bash %}
|
{% highlight bash %}
|
||||||
|
Loading…
Reference in New Issue
Block a user