在qemu上运行linux

1,安装工具
sudo apt-get install gcc-arm-linux-gnueabi
sudo apt-get install qemu

2,下载Linux内核
从kernel.org下载压缩包
tar -xf linux-3.16.45.tar.xz

3,编译内核
make mrproper #可选,保证原始干净环境

生成vexpress开发板子的config文件:
make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig

编译:make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm

生成的内核镱像位于arch/arm/boot/zImage, qemu启动时须要使用该镜像。

4,測试qemu和内核是否能执行成功
cp arch/arm/boot/zImage myImage
qemu-system-arm -M vexpress-a9 -m 512M -kernel myImage -nographic -append "console=ttyAMA0"

-M vexpress-a9 模拟vexpress-a9单板,你能够使用-M ?參数来获取该qemu版本号支持的全部单板
-m 512M 单板执行物理内存512M
-kernel /home/ivan/kernel_git/linux/arch/arm/boot/zImage 告诉qemu单板执行内核镜像路径
-nographic 不使用图形化界面,仅仅使用串口
-append "console=ttyAMA0" 内核启动參数。这里告诉内核vexpress单板执行。串口设备是哪个tty。

事实上在上面的測试中,你会发现内核报panic,由于内核找不到根文件系统,无法启init进程。

5,下载、编译和安装busybox
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make install CROSS_COMPILE=arm-linux-gnueabi-
安装完毕后。会在busybox文件夹下生成_install文件夹。该文件夹下的程序就是单板执行所须要的命令。

6,形成根文件夹结构
1. 创建rootfs文件夹(根文件夹),根文件系统内的文件全部放到这里
sudo mkdir rootfs
2. 拷贝busybox命令到根文件夹下
sudo cp busybox-1.20.2/_install/* -r rootfs/
3. 从工具链中拷贝执行库到lib文件夹下
sudo mkdir rootfs/lib
sudo mkdir rootfs/dev
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
4. 创建4个tty端终设备
sudo mknod rootfs/dev/tty1 c 4 1
sudo mknod rootfs/dev/tty2 c 4 2
sudo mknod rootfs/dev/tty3 c 4 3
sudo mknod rootfs/dev/tty4 c 4 4

7,制作根文件系统镜像
1. 生成32M大小的镜像
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
2. 格式化成ext3文件系统
mkfs.ext3 a9rootfs.ext3
3. 将文件复制到镜像中
sudo mkdir tmpfs
sudo mount -t ext3 a9rootfs.ext3 tmpfs/ -o loop
sudo cp -r rootfs/* tmpfs/
sudo umount tmpfs

8,系统启动执行
qemu-system-arm -M vexpress-a9 -m 512M -kernel myImage -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3

9,linux启动信息

[email protected]:~/share$ qemu-system-arm -M vexpress-a9 -m 512M -kernel myImage -nographic -append "root=/dev/mmcblk0 console=ttyAMA0" -sd a9rootfs.ext3
WARNING: Image format was not specified for ‘a9rootfs.ext3‘ and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the ‘raw‘ format explicitly to remove the restrictions.
pulseaudio: set_sink_input_volume() failed
pulseaudio: Reason: Invalid argument
pulseaudio: set_sink_input_mute() failed
pulseaudio: Reason: Invalid argument
Booting Linux on physical CPU 0x0
Initializing cgroup subsys cpuset
Linux version 3.16.45 ([email protected]) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #1 SMP Sun Jul 16 21:32:51 CST 2017
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c53c7d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine: ARM-Versatile Express
Memory policy: Data cache writeback
CPU: All CPU(s) started in SVC mode.
sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 178956969942ns
PERCPU: Embedded 7 pages/cpu @9fbed000 s6976 r8192 d13504 u32768
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 130048
Kernel command line: root=/dev/mmcblk0 console=ttyAMA0
PID hash table entries: 2048 (order: 1, 8192 bytes)
Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
Memory: 513184K/524288K available (4650K kernel code, 191K rwdata, 1292K rodata, 246K init, 149K bss, 11104K reserved)
Virtual kernel memory layout:
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)
    fixmap  : 0xffc00000 - 0xffe00000   (2048 kB)
    vmalloc : 0xa0800000 - 0xff000000   (1512 MB)
    lowmem  : 0x80000000 - 0xa0000000   ( 512 MB)
    modules : 0x7f000000 - 0x80000000   (  16 MB)
      .text : 0x80008000 - 0x805d5ba4   (5943 kB)
      .init : 0x805d6000 - 0x80613b40   ( 247 kB)
      .data : 0x80614000 - 0x80643ea0   ( 192 kB)
       .bss : 0x80643ea8 - 0x80669528   ( 150 kB)
SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
        RCU restricting CPUs from NR_CPUS=8 to nr_cpu_ids=1.
RCU: Adjusting geometry for rcu_fanout_leaf=16, nr_cpu_ids=1
NR_IRQS:16 nr_irqs:16 16
GIC CPU mask not found - kernel will fail to boot.
GIC CPU mask not found - kernel will fail to boot.
smp_twd: clock not found -2
L2C: DT/platform modifies aux control register: 0x02020000 -> 0x02420000
L2C-310 enabling early BRESP for Cortex-A9
L2C-310 full line of zeros enabled for Cortex-A9
L2C-310 dynamic clock gating disabled, standby mode disabled
L2C-310 cache controller enabled, 8 ways, 128 kB
L2C-310: CACHE_ID 0x410000c8, AUX_CTRL 0x46420001
Console: colour dummy device 80x30
Calibrating local timer... 97.02MHz.
Calibrating delay loop... 852.78 BogoMIPS (lpj=4263936)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
CPU: Testing write buffer coherency: ok
missing device node for CPU 0
CPU0: thread -1, cpu 0, socket 0, mpidr 80000000
Setting up static identity map for 0x604712a8 - 0x60471300
Brought up 1 CPUs
SMP: Total of 1 processors activated (852.78 BogoMIPS).
CPU: All CPU(s) started in SVC mode.
devtmpfs: initialized
VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 0
futex hash table entries: 256 (order: 2, 16384 bytes)
regulator-dummy: no parameters
NET: Registered protocol family 16
DMA: preallocated 256 KiB pool for atomic coherent allocations
cpuidle: using governor ladder
cpuidle: using governor menu
hw-breakpoint: debug architecture 0x4 unsupported.
Serial: AMBA PL011 UART driver
mb:uart0: ttyAMA0 at MMIO 0x10009000 (irq = 37, base_baud = 0) is a PL011 rev1
console [ttyAMA0] enabled
mb:uart1: ttyAMA1 at MMIO 0x1000a000 (irq = 38, base_baud = 0) is a PL011 rev1
mb:uart2: ttyAMA2 at MMIO 0x1000b000 (irq = 39, base_baud = 0) is a PL011 rev1
mb:uart3: ttyAMA3 at MMIO 0x1000c000 (irq = 40, base_baud = 0) is a PL011 rev1
fixed-dummy: no parameters
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Advanced Linux Sound Architecture Driver Initialized.
Switched to clocksource v2m-timer1
NET: Registered protocol family 2
TCP established hash table entries: 4096 (order: 2, 16384 bytes)
TCP bind hash table entries: 4096 (order: 3, 32768 bytes)
TCP: Hash tables configured (established 4096 bind 4096)
TCP: reno registered
UDP hash table entries: 256 (order: 1, 8192 bytes)
UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
CPU PMU: probing PMU on CPU 0
hw perfevents: enabled with ARMv7 Cortex-A9 PMU driver, 1 counters available
squashfs: version 4.0 (2009/01/31) Phillip Lougher
jffs2: version 2.2. (NAND) ? 2001-2006 Red Hat, Inc.
9p: Installing v9fs 9p2000 file system support
msgmni has been set to 1002
io scheduler noop registered (default)
clcd-pl11x ct:clcd: PL111 rev2 at 0x10020000
clcd-pl11x ct:clcd: CT-CA9X4 hardware, XVGA display
Console: switching to colour frame buffer device 128x48
physmap platform flash device: 04000000 at 40000000
physmap-flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
physmap platform flash device: 04000000 at 44000000
physmap-flash: Found 2 x16 devices at 0x0 in 32-bit bank. Manufacturer ID 0x000000 Chip ID 0x000000
Intel/Sharp Extended Query Table at 0x0031
Using buffer write method
Concatenating MTD devices:
(0): "physmap-flash"
(1): "physmap-flash"
into device "physmap-flash"
libphy: smsc911x-mdio: probed
smsc911x smsc911x eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=smsc911x-fffffff:01, irq=-1)
smsc911x smsc911x eth0: MAC Address: 52:54:00:12:34:56
isp1760 isp1760: NXP ISP1760 USB Host Controller
isp1760 isp1760: new USB bus registered, assigned bus number 1
isp1760 isp1760: Scratch test failed.
isp1760 isp1760: can‘t setup: -19
isp1760 isp1760: USB bus 1 deregistered
isp1760: Failed to register the HCD device
usbcore: registered new interface driver usb-storage
mousedev: PS/2 mouse device common for all mice
rtc-pl031 mb:rtc: rtc core: registered pl031 as rtc0
mmci-pl18x mb:mmci: mmc0: PL181 manf 41 rev0 at 0x10005000 irq 41,42 (pio)
ledtrig-cpu: registered to indicate activity on CPUs
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new SD card at address 4567
input: AT Raw Set 2 keyboard as /devices/mb:kmi0/serio0/input/input0
mmcblk0: mmc0:4567 QEMU! 32.0 MiB
 mmcblk0: unknown partition table
aaci-pl041 mb:aaci: ARM AC‘97 Interface PL041 rev0 at 0x10004000, irq 43
aaci-pl041 mb:aaci: FIFO 512 entries
oprofile: using arm/armv7-ca9
TCP: cubic registered
NET: Registered protocol family 17
9pnet: Installing 9P2000 support
rtc-pl031 mb:rtc: setting system clock to 2017-07-16 13:59:34 UTC (1500213574)
ALSA device list:
  #0: ARM AC‘97 Interface PL041 rev0 at 0x10004000, irq 43
input: ImExPS/2 Generic Explorer Mouse as /devices/mb:kmi1/serio1/input/input2
kjournald starting.  Commit interval 5 seconds
EXT3-fs (mmcblk0): mounted filesystem with writeback data mode
VFS: Mounted root (ext3 filesystem) readonly on device 179:0.
Freeing unused kernel memory: 244K (805d6000 - 80613000)
random: nonblocking pool is initialized
can‘t run ‘/etc/init.d/rcS‘: No such file or directory

Please press Enter to activate this console.
/ # uname -a
Linux (none) 3.16.45 #1 SMP Sun Jul 16 21:32:51 CST 2017 armv7l GNU/Linux
/ #
/ # 
时间: 2024-10-10 04:05:53

在qemu上运行linux的相关文章

如何实现在Windows上运行Linux程序,附示例代码

如何实现在Windows上运行Linux程序,附示例代码 微软在去年发布了Bash On Windows, 这项技术允许在Windows上运行Linux程序, 我相信已经有很多文章解释过Bash On Windows的原理,而今天的这篇文章将会讲解如何自己实现一个简单的原生Linux程序运行器, 这个运行器在用户层实现, 原理和Bash On Windows不完全一样,比较接近Linux上的Wine. 示例程序完整的代码在github上, 地址是 https://github.com/30324

转:在Web上运行Linux—js/linux模拟器

一个叫Fabrice Bellard 的程序员写了一段Javascript在Web浏览器中启动Linux(原网页,我把这个网页iframe在了下面),目前,你只能使用Firefox 4和Chrome 11 运行这个Linux.这不是什么假的模仿Linux的东西,这是实实在在的运行一个Linux.这一举动还引起了很多很牛人的关注,包括Javascript的创建者Brendan Eich . ======================================================

windows10上运行Linux Bash Shell

前言 对于熟悉Linux运维的工程师,如果能在Windows上运行Bash shell的话,会比用可恶的dos命令舒服得多.Windows确实提供了这样的功能. 1.打开开发者模式 "设置"->"更新和安全"->"开发者选项"->"开发人员模式" 2.安装"适用于Linux的Windows子系统" 按提示重启电脑 3.安装 运行-cmd-输入bash 提示访问https://aka.ms/

ubuntu上运行linux项目

①首先把项目传到linux中 ②进入项目文件夹中,安装Django库 pip3 install django ③安装操作mysql的库mysqlclient pip3 install mysqlclient ④数据迁移 python3 manage.py makemigration python3 manage.py migrate ④执行项目 python3 manage.py runserver 0.0.0.0:8000 ⑤访问项目 http://服务器ip:端口号 原文地址:https:/

从U盘运行Linux操作系统的三种方法

摘要: 从U盘运行Linux操作系统的三种方法 usb_linux_0 你或许听说过在U盘上运行live Linux操作系统,但你知不知道可以永久的保存运行时的数据,或者直接将Linux安装到U盘?本文将介绍把Linux装进口袋(U盘)的三种方法,挑一种你最喜欢的方法吧! 将ISO映像烧录到U盘 usb_linux_1 把一个Linux发行版的Live ISO映像烧录到U盘中已 经变的极其容易了. 从U盘运行Linux操作系统的三种方法 usb_linux_0 你或许听说过在U盘上运行live

LCOW —— 单一Docker引擎下可同时运行Linux和Windows容器啦!

https://blog.csdn.net/m2l0zgssvc7r69efdtj/article/details/79251059 就在上周,Docker官方的master分支上新增了LCOW(Linux Containers on Windows)[1]功能.启用这项功能,即可在单一的Docker引擎下,同时运行Linux和Windows容器.下面赶紧跟小编一起,看看Windows 10将会发生哪些变化? 可以用Docker命令docker ps,列出所有正在运行的Linux或Windows

x86_64的debian(wheezy)下使用qemu和busybox运行linux

1.编译kernel 进入源码根目录 make defconfig //这一步生成了默认的内核配置,请参考make help生成的信息. make //这一步生成了bzImage 2.制作根文件系统 dd if=/dev/zero of=rootfs.img bs=1M count=10 //生成了rootfs.img,大小10M mkfs.ext4 rootfs.img //在rootfs.img上制作ext4文件系统 mkdir rootfs sudo mount -t ext4 -o lo

编译可在Android上运行的qemu user mode

前言 本文在Ubuntu 64位系统上对qemu项目进行交叉编译,并且只编译与qemu user mode有关的代码. 下文中的”NDK”若无特殊说明均指”Android NDK”. 下文中”$NDK”表示的是NDK的根目录. 步骤 1. 下载并安装Android NDK 下载并安装Android NDK的过程在这里不做介绍. 2. 下载qemu 3. 设置NDK工具的环境变量 为交叉编译设置Android NDK环境变量:NDK.SYSROOT 4. 编译依赖库 glib 编译可在Androi

如何在linux主机上运行/调试 arm/mips架构的binary

如何在linux主机上运行/调试 arm/mips架构的binary 原文链接[email protected]0.0.0.55 本文中用于展示的binary分别来自Jarvis OJ上pwn的add,typo两道题 写这篇教程的主要目的是因为最近想搞其他系统架构的pwn,因此第一步就是搭建环境了,网上搜索了一波,发现很多教程都是需要树莓派,芯片等硬件,然后自己编译gdb,后来实践的过程中发现可以很简单地使用qemu实现运行和调试异架构binary,因此在这里分享一下我的方法. 主机信息: 以一