码迷,mamicode.com
首页 > 其他好文 > 详细

使用qemu模拟调试内核和debian根文件系统

时间:2015-12-02 16:17:12      阅读:851      评论:0      收藏:0      [点我收藏+]

标签:

 

开发环境:Ubuntu 14.04.3 LTS  64bit

sudo debootstrap jessie /mnt/jessie http://mirrors.163.com/debian

在/mnt/jessie目录下建立一个init文件,内容如下:

james@james-OptiPlex-380:~$ sudo vi /mnt/jessie/init 
#!/bin/sh
# devtmpfs does not get automounted for initramfs
echo "******** init **********"
/bin/mount -t devtmpfs devtmpfs /dev
exec 0</dev/console
exec 1>/dev/console
exec 2>/dev/console
exec /sbin/init $*

参考linux 内核文档 Documentation/filesystems/ramfs-rootfs-initramfs.txt,用下面脚本打包initramfs

james@james-OptiPlex-380:/mnt$ cat mkinitramfs.sh 

#!/bin/sh

# Copyright 2006 Rob Landley <rob@landley.net> and TimeSys Corporation.
# Licensed under GPL version 2

if [ $# -ne 2 ]
then
  echo "usage: mkinitramfs directory imagename.cpio.gz"
  exit 1
fi

if [ -d "$1" ]
then
  echo "creating $2 from $1"
  (cd "$1"; find . | cpio -o -H newc | gzip) > "$2"
else
  echo "First argument must be a directory"
  exit 1
fi

 

打包命令:

mkinitramfs.sh jessie rootfs.cpio.gz

 

使用以下命令启动内核和根文件系统:

qemu-system-x86_64  -kernel bzImage -initrd /mnt/rootfs.cpio.gz  /dev/zero -m 2G -nographic -append "console=ttyS0"

 

问题:启动时无法进入initramfs,原因是没根目录下的 init文件。

[   11.815891] rtc_cmos 00:00: setting system clock to 2015-12-02 07:21:59 UTC (1449040919)
[   11.818523] BIOS EDD facility v0.16 2004-Jun-25, 0 devices found
[   11.818900] EDD information not available.
[   11.819783] ALSA device list:
[   11.819991]   No soundcards found.
[   12.396667] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3
[   12.403434] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[   12.403941] Please append a correct "root=" boot option; here are the available partitions:
[   12.404870] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[   12.405584] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.13.0 #7
[   12.405945] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
[   12.406561]  0000000000008001 ffff880074d01dd0 ffffffff81b8de3a ffffffff8201c2c8
[   12.407087]  ffff880074d01e48 ffffffff81b89a24 223d746f00000010 ffff880074d01e58
[   12.407557]  ffff880074d01df8 000000000000004f ffff880074d01e68 0000000000000052
[   12.408077] Call Trace:
[   12.408502]  [<ffffffff81b8de3a>] dump_stack+0x45/0x56
[   12.408502]  [<ffffffff81b89a24>] panic+0xc2/0x1c1
[   12.408502]  [<ffffffff8234e338>] mount_block_root+0x1a8/0x250
[   12.408502]  [<ffffffff8234e61b>] mount_root+0xf1/0xfa
[   12.408502]  [<ffffffff8234f2a0>] ? initrd_load+0x2c9/0x2d8
[   12.408502]  [<ffffffff8234e78b>] prepare_namespace+0x167/0x19f
[   12.408502]  [<ffffffff8234e04a>] kernel_init_freeable+0x1c4/0x1d1
[   12.408502]  [<ffffffff8234d833>] ? do_early_param+0x88/0x88
[   12.408502]  [<ffffffff81b85b00>] ? rest_init+0x80/0x80
[   12.408502]  [<ffffffff81b85b0e>] kernel_init+0xe/0x120
[   12.408502]  [<ffffffff81b9f2ac>] ret_from_fork+0x7c/0xb0
[   12.408502]  [<ffffffff81b85b00>] ? rest_init+0x80/0x80
[   12.408502] general protection fault: fff2 [#1] SMP 
[   12.408502] Modules linked in:
[   12.408502] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.13.0 #7
[   12.408502] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
[   12.408502] task: ffff880074c58000 ti: ffff880074d00000 task.ti: ffff880074d00000
[   12.408502] RIP: 0010:[<ffffffff81b89aea>]  [<ffffffff81b89aea>] panic+0x188/0x1c1
[   12.408502] RSP: 0018:ffff880074d01de0  EFLAGS: 00000246
[   12.408502] RAX: 0000000000006a6a RBX: ffffffff8201c2c8 RCX: 00000000000000a0
[   12.408502] RDX: 000000000000006a RSI: 0000000000000000 RDI: ffffffff826c8a70
[   12.408502] RBP: ffff880074d01e48 R08: 0000000000000001 R09: 00000000000001e1
[   12.408502] R10: 736572203f205d3e R11: 3030623538623138 R12: 0000000000000000
[   12.408502] R13: 0000000000000000 R14: 0000000000000000 R15: ffff88007fa93000
[   12.408502] FS:  0000000000000000(0000) GS:ffff880077800000(0000) knlGS:0000000000000000
[   12.408502] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[   12.408502] CR2: 00007fbb08c44140 CR3: 000000000220c000 CR4: 00000000000006f0
[   12.408502] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[   12.408502] DR3: 0000000000000000 DR6: 0000000000000000 DR7: 0000000000000000
[   12.408502] Stack:
[   12.408502]  223d746f00000010 ffff880074d01e58 ffff880074d01df8 000000000000004f
[   12.408502]  ffff880074d01e68 0000000000000052 ffff880000095070 6120657361656c50
[   12.408502]  00000000000001ce ffff88007fa93000 0000000000008001 0000000000008001
[   12.408502] Call Trace:
[   12.408502]  [<ffffffff8234e338>] mount_block_root+0x1a8/0x250
[   12.408502]  [<ffffffff8234e61b>] mount_root+0xf1/0xfa
[   12.408502]  [<ffffffff8234f2a0>] ? initrd_load+0x2c9/0x2d8
[   12.408502]  [<ffffffff8234e78b>] prepare_namespace+0x167/0x19f
[   12.408502]  [<ffffffff8234e04a>] kernel_init_freeable+0x1c4/0x1d1
[   12.408502]  [<ffffffff8234d833>] ? do_early_param+0x88/0x88
[   12.408502]  [<ffffffff81b85b00>] ? rest_init+0x80/0x80
[   12.408502]  [<ffffffff81b85b0e>] kernel_init+0xe/0x120
[   12.408502]  [<ffffffff81b9f2ac>] ret_from_fork+0x7c/0xb0
[   12.408502]  [<ffffffff81b85b00>] ? rest_init+0x80/0x80
[   12.408502] Code: 00 00 49 ff cc 74 0c bf 58 89 41 00 e8 e0 90 83 ff eb ef 48 83 c3 64 eb b6 83 3d a1 80 93 00 00 74 05 e8 5a 3f 4e ff fb 45 31 e4 <4d> 39 ec 7c 18 41 83 f6 01 44 89 f7 ff 15 64 80 93 00 49 01 c4 
[   12.408502] RIP  [<ffffffff81b89aea>] panic+0x188/0x1c1
[   12.408502]  RSP <ffff880074d01de0>
[   12.408502] ---[ end trace 96badb4295b8f792 ]---

qemu提供了几个快捷键,ctrl+a h打开帮助

  • C-a h    print this help  
  • C-a x    exit emulator   退出
  • C-a s    save disk data back to file (if -snapshot)  
  • C-a t    toggle console timestamps  
  • C-a b    send break (magic sysrq)  
  • C-a c    switch between console and monitor   在linux控制台和qemu的控制终端切换
  • C-a C-a  sends C-a 
  • 使用qemu模拟调试内核和debian根文件系统

    标签:

    原文地址:http://www.cnblogs.com/cute/p/5013266.html

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!