diff options
-rw-r--r-- | README.md | 44 | ||||
-rw-r--r-- | flake.lock | 40 | ||||
-rw-r--r-- | flake.nix | 16 | ||||
-rw-r--r-- | linux.nix | 23 |
4 files changed, 123 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..d077e8c --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# My Linux Kernel Development Workflow + + +## 'Install' the required dependencies +``` +$ nix develop +``` + +or if youre not using flakes... + +``` +$ nix-shell linux.nix +``` + +## Build the kernel +``` +$ make x86_64_defconfig +$ make defconfig kvm_guest.config +$ scripts/config --set-val DEBUG_INFO y --set-val DEBUG y --set-val GDB_SCRIPTS y --set-val DEBUG_DRIVER y + +$ make +``` + +## Create root filesystem +``` +$ qemu-img create qemu-image.img 1g +$ mkfs.ext2 qemu-image.img +$ mkdir mnt +# mount -o loop qemu-image.img mnt +# debootstrap --arch amd64 jessie mnt +# chroot mnt /bin/sh +## passdw (set password) +## exit +``` + +## Run the VM with the built kernel +``` +$ qemu-system-x86_64 -kernel arch/x86/boot/bzImage -drive file=qemu-image.img,index=0,media=disk,format=raw -append "root=/dev/sda nokaslr console=ttyS0 earlyprintk=serial" -enable-kvm -nographic +``` + +## Debugging +1. Add `-s -S` to the qemu parameters +2. `gdb -ex "add-auto-load-safe-path $(pwd)" -ex "file vmlinux" -ex 'target remote 127.0.0.1:1234' -ex 'hbreak start_kernel'` +3. Debug! diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ebcbb42 --- /dev/null +++ b/flake.lock @@ -0,0 +1,40 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1664871473, + "narHash": "sha256-1LzbW6G6Uz8akWiOdlIi435GAm1ct5jF5tovw/9to0o=", + "path": "/nix/store/6r60yphln7nca0mz33l4s8x8svk0r88b-source", + "rev": "b7a6fde153d9470afdb6aa1da51c4117f03b84ed", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9331325 --- /dev/null +++ b/flake.nix @@ -0,0 +1,16 @@ +{ + description = "My Linux development workflow's flake!"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + + flake-utils.lib.eachDefaultSystem + (system: + let pkgs = nixpkgs.legacyPackages.${system}; in + { + devShells.default = import ./linux.nix { inherit pkgs; }; + } + ); + +} diff --git a/linux.nix b/linux.nix new file mode 100644 index 0000000..4199da7 --- /dev/null +++ b/linux.nix @@ -0,0 +1,23 @@ +{ pkgs ? import <nixpkgs> {} }: + +pkgs.stdenv.mkDerivation { + name = "linux-kernel-build"; + nativeBuildInputs = with pkgs; [ + getopt + flex + bison + gcc + gnumake + bc + pkg-config + binutils + ]; + buildInputs = with pkgs; [ + elfutils + ncurses + openssl + zlib + gdb + ]; +} + |