Skip to content

Instantly share code, notes, and snippets.

@raminfp
Created November 19, 2018 17:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raminfp/6fc4cb67e9f9f0306045ef14fd2e6b67 to your computer and use it in GitHub Desktop.
Save raminfp/6fc4cb67e9f9f0306045ef14fd2e6b67 to your computer and use it in GitHub Desktop.
How to build your kernel "vmlinuz-<version>-generic" without compile kernel source with BUILDROOT/QEMU?

Let's Start (Weekend Notes) ...

Buildroot (BR) (https://buildroot.org/):

$ git clone git://git.buildroot.net/buildroot
$ cd buildroot

Buildroot uses the same interface as the kernel for configuration (ncurses based, make sure you have ncurses-devel sudo apt-get install libncurses-dev and bison sudo apt-get install bison installed)

$ make menuconfig

Start out by setting the appropriate architecture (assuming x86_64)
Target options -> Target Architecture -> x86_64

And then set the file system
Filesystem images -> cpio the root filesystem

Compile Buildroot:

$ make

Now we should set kernel image path : -kernel /boot/vmlinuz-4.14.12-041412-generic and buildroot rootfs : -initrd output/images/rootfs.cpio

## kernel.sh
qemu-system-x86_64 \
	-initrd output/images/rootfs.cpio \
	-kernel /boot/vmlinuz-4.14.12-041412-generic \ 
  	-append "console=ttyS0 root=/dev/sda debug earlyprintk=serial slub_debug=QUZ" -nographic

Execute bash scritp with sudo command:

$ sudo sh kernel.sh

Output :

[    0.000000] Linux version 4.14.12-041412-generic (kernel@kathleen) (gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3)) #201801051649 SMP Fri Jan 5 16:50:54 UTC 2018
[    0.000000] Command line: console=ttyS0 root=/dev/sda debug earlyprintk=serial slub_debug=QUZ
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
[    0.000000]   Centaur CentaurHauls
[    0.000000] x86/fpu: x87 FPU will use FXSAVE
[    0.000000] e820: BIOS-provided physical RAM map:
[    0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
[    0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000000f0000-0x00000000000fffff] reserved
[    0.000000] BIOS-e820: [mem 0x0000000000100000-0x0000000007fdffff] usable
[    0.000000] BIOS-e820: [mem 0x0000000007fe0000-0x0000000007ffffff] reserved
[    0.000000] BIOS-e820: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved
[    0.000000] bootconsole [earlyser0] enabled
[    0.000000] NX (Execute Disable) protection: active
[    0.000000] random: fast init done
[    0.000000] SMBIOS 2.8 present.
[    0.000000] DMI: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
[    0.000000] tsc: Fast TSC calibration failed
[    0.000000] tsc: Unable to calibrate against PIT
[    0.000000] tsc: No reference (HPET/PMTIMER) available
[    0.000000] e820: update [mem 0x00000000-0x00000fff] usable ==> reserved
[    0.000000] e820: remove [mem 0x000a0000-0x000fffff] usable
[    0.000000] e820: last_pfn = 0x7fe0 max_arch_pfn = 0x400000000
[    0.000000] MTRR default type: write-back
[    0.000000] MTRR fixed ranges enabled:
[    0.000000]   00000-9FFFF write-back
[    0.000000]   A0000-BFFFF uncachable
[    0.000000]   C0000-FFFFF write-protect

....

Starting logging: OK
Initializing random number generator... done.
Starting network: [    4.043488] clocksource: Switched to clocksource tsc
OK

Welcome to Buildroot
buildroot login: root

# ls /
bin      init     linuxrc  opt      run      tmp
dev      lib      media    proc     sbin     usr
etc      lib32    mnt      root     sys      var
# 
# uname -a
Linux buildroot 4.14.12-041412-generic #201801051649 SMP Fri Jan 5 16:50:54 UTC 2018 x86_64 GNU/Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment