首页 > 代码库 > 在qemu上运行linux
在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启动信息
derek@ubox:~/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 (derek@ubox) (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 / # / #
在qemu上运行linux