Linux 3.10 busybox InitramfsBuildQemuDebug
My environment is a CentOS 7 64-bit system run by VM Ware virtual machine
1: InstallationQemu
First install SDL, responsible for QEMU running only after the VNC server running on ':: 1:5900 ', and does not appear Qemu Run the window, for specific reference:
http://www.crifan.com/qemu_test_arm_vnc_server_running_on_127_0_0_1_5900_no_other_output/
Yum install sdl.i686 sdl.x86_64 sdl-devel.i686 sdl-devel.x86_64
Download source code qemu-2.1.0.tar.bz2, unzip the compilation, install
./configure--prefix=/usr/local/--target-list=x86_64-softmmu
Make && make install
Create a soft link
Ln-n/usr/local//bin/qemu-system-x86_64/bin/qemu
2:DownloadBUSYBOX-1.20.0.TAR.BZ2, unzip, go to source code directory, run
Make Menuconfig
Choose
Busybox Settings--->
Build Options--->
[*] Build BusyBox as a static binary (no shared libs)
Compiling the installation
Make && make install
Error occurred during compilation
CC LOGINUTILS/PASSWD.O
LOGINUTILS/PASSWD.C: in the function 'passwd_main' :
Loginutils/passwd.c:104:16: error: 'rlimit_fsize' storage size is unknown
struct Rlimit rlimit_fsize;
^
Loginutils/passwd.c:188:2: Warning: Implicitly declaring function 'setrlimit' [-wimplicit-function-declaration ]
Setrlimit (Rlimit_fsize, &rlimit_fsize);
^
Loginutils/passwd.c:188:12: error: 'rlimit_fsize' not declared ( First Use within this function )
Setrlimit (Rlimit_fsize, &rlimit_fsize);
^
Loginutils/passwd.c:188:12: Note: Each undeclared identifier is reported only once within the function in which it appears
Loginutils/passwd.c:104:16: Warning: Unused variable 'rlimit_fsize' [-wunused-variable]
Vim Include/libbb.h
Add in # include <sys/mman.h> back
#include <sys/resource.h>
Specific reference http://lists.busybox.net/pipermail/busybox/2012-May/077766.html
Compile a simple program to test
Vim ~/init.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
while (1) {
printf ("Hello world!\n");
Sleep (199999999);
}
return 0;
}
Gcc-static ~/init.c-o/opt/busybox-1.20.0/_install/init
Cd/opt/busybox-1.20.0/_install
Mknod-m dev/console C 5 1
Go to create directory and file
CD _install
Mkdir-p Dev proc sys etc mnt
Touch etc/mdev.conf
Mknod-m dev/null C 1 3
Theinit script does not run correctly when you create a console device file and do not create this file . Initialization Code reference function for console:init/main.c:kernel_init_freeable
Mknod-m dev/console C 5 1
To create the init file:
VIM Init
The contents are as follows:
#!/bin/sh
Echo
echo "###########################################################"
echo "# # Author: [email protected] # # #"
echo "# # DATE:2014/09/15 16:57:21 CST # #"
echo "###########################################################"
Echo
Path= "/bin:/sbin:/usr/bin:/usr/sbin"
if [!-F "/bin/busybox"];then
echo "Cat not find BusyBox in/bin dir, exit"
Exit 1
Fi
busybox= "/bin/busybox"
echo "Build root filesystem ..."
$BUSYBOX--install-s
if [!-d/proc];then
echo "/proc dir not exist, create it ..."
$BUSYBOX Mkdir/proc
Fi
echo "Mount Proc FS ..."
$BUSYBOX mount-t proc Proc/proc
if [!-d/dev];then
echo "/dev dir not exist, create it ..."
$BUSYBOX Mkdir/dev
Fi
echo "Mount Tmpfs In/dev ..."
$BUSYBOX mount-t Tmpfs Dev/dev
$BUSYBOX mkdir-p/dev/pts
echo "Mount Devpts ..."
$BUSYBOX mount-t devpts devpts/dev/pts
if [!-d/sys];then
echo "/sys dir not exist, create it ..."
$BUSYBOX Mkdir/sys
Fi
echo "Mount Sys FS ..."
$BUSYBOX mount-t Sysfs Sys/sys
echo "/sbin/mdev" >/proc/sys/kernel/hotplug
echo "Populate the dev dir ..."
$BUSYBOX mdev-s
echo "drop to Shell ..."
$BUSYBOX SH
Exit 0
Permissions to execute on Init
chmod u+x Init
3:DownloadLINUX-3.10.TAR.XZ, unzip the source code, enter the source directory, run
Make Menuconfig
Configure compilation options, select
General Setup--->
[*] Initramfs source file (s)
option, enter the directory of the prepared file system and I'm here.
/opt/busybox-1.20.0/_install
Compile
Make Bzimage
To run a virtual machine:
Qemu-kernel./arch/x86/boot/bzimage-append "No_timer_check"
Commissioning of the GDP under another terminal :
GDB Vmlinux
Target Remote 127.0.0.1:1234
b Start_kernel
4: Do not add No_timer_check on my machine will output
... trying to set up timer as Virtual wire IRQ ...
Back stuck
Ways to solve this problem:
In the source code search trying to set the timer as Virtual wire IRQ, locate the function output statement in the function Check_timer.
Running virtual machines
Qemu-kernel./arch/x86/boot/bzimage-append "Root=/dev/hda init=/bin/sh no_timer_check"-s-s
Running in the kernel source code directory
GDB Vmlinux
Enter the command after entering the gdb command line
Target Remote 127.0.0.1:1234
b Check_timer
C
After the breakpoint is executed from the output trying to the set up timer as a Virtual wire IRQ, the Timer_irq_works function is found to be stuck. There are statements in Timer_irq_works:
if (No_timer_check)
return 1;
Find the No_timer_check and find the No_timer_check option in documentation/x86/x86_64/boot-options.txt.
5:gdbDebug Appearsgdb ' g ' packet reply is too longfixed,
after downloading gdb-7.8.tar.xz
Extract
Xt-d GDB-7.8.TAR.XZ
Tar XF gdb-7.8.tar.xz
Edit Source code:
Vim gdb/remote.c
Find the process_g_packet function
Note Adjust the following two lines
if (Buf_len > 2 * rsa->sizeof_g_packet)
Error (_ ("Remote ' G ' packet reply is too long:%s"), RS->BUF);
Add the following code later:
if (Buf_len > 2 * rsa->sizeof_g_packet) {
Rsa->sizeof_g_packet = Buf_len;
for (i = 0; i < Gdbarch_num_regs (gdbarch); i++) {
if (Rsa->regs->pnum = =-1)
Continue
if (Rsa->regs->offset >= rsa->sizeof_g_packet)
Rsa->regs->in_g_packet = 0;
Else
Rsa->regs->in_g_packet = 1;
}
}
Configuration compilation
./configure--prefix=/usr/local/gdb
Make && make install
Setting environment variables
Export Path=/usr/local/gdb/bin: $PATH
6:Other questions
execute directly under the Xshell
Qemu-kernel./arch/x86/boot/bzimage-append "No_timer_check"
The keyboard input will appear garbled. This behavior does not occur in virtual machine environments.
Linux 3.10 busybox Initramfs building QEMU debugging