Skip to content

Instantly share code, notes, and snippets.

@aabdelfattah
Last active January 18, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aabdelfattah/854a37c6bd519b5c28fe37fab2b99f25 to your computer and use it in GitHub Desktop.
Save aabdelfattah/854a37c6bd519b5c28fe37fab2b99f25 to your computer and use it in GitHub Desktop.
Setting up an environment for Rust Linux kernel development
#
# Instructions for the video https://www.youtube.com/watch?v=tPs1uRqOnlk excluding setting up the env ( e.g. installing Rust and llvm)
#
#
# Kernel
#
$ git clone --depth=1 https://github.com/Rust-for-Linux/linux.git
$ cd linux/
$ make allnoconfig qemu-busybox-min.config
$ make allnoconfig qemu-busybox-min.config rust.config
$ make LLVM=1 rustavailable # should say Rust is available if you have all dependencies
$ make LLVM=1 -j4
#
# Busybox
#
$ cd busybox
$ git clone --depth=1 https://github.com/mirror/busybox.git
$ make defconfig
$ make menuconfig # then from settings select use static libraries
# make -j4
$ cd ./_install/
$ find . | cpio -H newc -o | gzip > ../ramdisk.img
#
# running qemu
#
$ cd linux/
$ qemu-system-x86_64 -nographic -kernel vmlinux # should panic
$ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img # should start
#
# adding proc filesystem to enable ps
#
$ cd busybox/_install/
$ vim etc/init.d/rcS
# then add this content inside
# mkdir -p /proc
# mount -t proc none /proc
$ find . | cpio -H newc -o | gzip > ../ramdisk.img
$ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img # ps should work
#
# enabling a rust sample kernel module
#
$ make LLVM=1 menuconfig
# then select the samples from kernel hacking --> samples --> rust samples
#
# enable networking
#
$ cd busybox/_install/
$ vim etc/init.d/rcS
# then add this content inside to enable loopback interface
# ifconfig lo up
# udhcpc -i eth0
$ mkdir -p usr/share/udhcpc
$ cp ../examples/udhcp/simple.script usr/share/udhcpc/default.script
$ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img -nic user,model=rtl8139
$ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img -nic user,model=rtl8139,hostfwd=tcp::5556-:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment