From 71b92750cd361f8945f2533ca2b7e302ea181149 Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Thu, 24 Dec 2015 17:08:03 +0000 Subject: Added running Linux kernel on QEMU with minimal initramfs --- md/writeup/qemu_usage.md | 49 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'md') diff --git a/md/writeup/qemu_usage.md b/md/writeup/qemu_usage.md index 38fc3e0..7e1baf6 100644 --- a/md/writeup/qemu_usage.md +++ b/md/writeup/qemu_usage.md @@ -16,11 +16,21 @@ qemu-system-i386 -cdrom _iso_image_ -boot order=d _qemu_image_ ### Setting up memory -> -m 512 +``` +-m 512 +``` ### Setting up network card +``` -net nic +``` + +### Setting up tun device + +``` +brctl addbr tun0 +``` ### Lunching image @@ -30,8 +40,39 @@ If everything installed then image could be runed just with qemu-system-i386 _options_ _disk_image_ ``` - +## Lunching self compiled kernel + +Let compile kernel and prepare initramfs to lunch it. Create file init.c +```c +#include +#include + +int main(int argc, char *argv[]) +{ + printf("Hello world!\n"); + sleep(999999999); +} +``` + +compile + +```bash +gcc init.c -o init -static +``` + +and create image to lunch + +```bash +echo init | cpio -o -H newc | gzip > test.cpio.gz +``` + +And now we have luncuble stuff to test if kernel loads fine + +```bash +qemu-system-x86_64 -m 512 -kernel ./bzImage -initrd test.cpio.gz +``` +If everything whent fine we will see "Hello world" ## Compile qemu @@ -72,4 +113,6 @@ make 1. [https://wiki.archlinux.org/index.php/QEMU](https://wiki.archlinux.org/index.php/QEMU) 2. [http://www.cnx-software.com/2012/03/08/how-to-build-qemu-system-arm-in-linux/](http://www.cnx-software.com/2012/03/08/how-to-build-qemu-system-arm-in-linux/) -3. [https://wiki.linaro.org/PeterMaydell/KVM/HowTo/BuildQEMU](https://wiki.linaro.org/PeterMaydell/KVM/HowTo/BuildQEMU) \ No newline at end of file +3. [https://wiki.linaro.org/PeterMaydell/KVM/HowTo/BuildQEMU](https://wiki.linaro.org/PeterMaydell/KVM/HowTo/BuildQEMU) +4. [http://www.cs.rochester.edu/~sandhya/csc256/assignments/qemu_linux.html](http://www.cs.rochester.edu/~sandhya/csc256/assignments/qemu_linux.html) +5. [https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt](https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt) \ No newline at end of file -- cgit v1.2.3