qemu运行linux 4.9

本文详细介绍使用QEMU从源码构建ARM虚拟机的过程,包括克隆QEMU源码、配置与编译QEMU、构建内核及文件系统等关键步骤。

1、git clone最新的Qemu代码到本地:

ubuntu@ubuntu-X556UB:~/Qemu$ git clone git://git.qemu-project.org/qemu.git
正克隆到 'qemu'...
remote: Counting objects: 302770, done.
remote: Compressing objects: 100% (56838/56838), done.
remote: Total 302770 (delta 245135), reused 302770 (delta 245135)
接收对象中: 100% (302770/302770), 98.29 MiB | 74.00 KiB/s, 完成.
处理 delta 中: 100% (245135/245135), 完成.
检查连接... 完成。
正在检出文件: 100% (5068/5068), 完成.

2、配置Qemu
ubuntu@ubuntu-X556UB:~/Qemu/qemu$ ./configure --target-list=arm-softmmu --audio-drv-list=

ERROR: DTC (libfdt) version >= 1.4.0 not present. Your options:
         (1) Preferred: Install the DTC (libfdt) devel package
         (2) Fetch the DTC submodule, using:
             git submodule update --init dtc
ubuntu@ubuntu-X556UB:~/Qemu/qemu$ git submodule update --init dtc
子模组 'dtc' (git://git.qemu-project.org/dtc.git) 未对路径 'dtc' 注册
正克隆到 'dtc'...
remote: Counting objects: 3521, done.
remote: Compressing objects: 100% (2076/2076), done.
remote: Total 3521 (delta 2600), reused 1937 (delta 1409)
接收对象中: 100% (3521/3521), 800.99 KiB | 495.00 KiB/s, 完成.
处理 delta 中: 100% (2600/2600), 完成.
检查连接... 完成。
子模组路径 'dtc':检出 '65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf'

64位ARM配置

ubuntu@ubuntu-X556UB:~/Qemu/qemu$./configure --target-list=aarch64-softmmu --audio-drv-list=    

ubuntu@ubuntu-X556UB:~/Qemu/qemu$ ./configure --target-list=arm-softmmu --audio-drv-list=
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
binary directory  /usr/local/bin
library directory /usr/local/lib
module directory  /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory  /usr/local/etc
local state directory   /usr/local/var
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /home/ubuntu/Qemu/qemu
C compiler        cc
Host C compiler   cc
C++ compiler      c++
Objective-C compiler cc
ARFLAGS           rv
CFLAGS            -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g 
QEMU_CFLAGS       -I/usr/include/pixman-1 -I$(SRC_PATH)/dtc/libfdt -Werror -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv  -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong  -I/usr/include/libpng12
LDFLAGS           -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
make              make
install           install
python            python -B
smbd              /usr/sbin/smbd
module support    no
host CPU          x86_64
host big endian   no
target list       arm-softmmu
tcg debug enabled no
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
pixman            system
SDL support       no 
GTK support       yes (2.24.30)
GTK GL support    no
VTE support       no 
TLS priority      NORMAL
GNUTLS support    no
GNUTLS rnd        no
libgcrypt         no
libgcrypt kdf     no
nettle            no 
nettle kdf        no
libtasn1          no
curses support    no
virgl support     no
curl support      no
mingw32 support   no
Audio drivers     
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS support    yes
VNC support       yes
VNC SASL support  no
VNC JPEG support  yes
VNC PNG support   yes
xen support       no
brlapi support    no
bluez  support    no
Documentation     yes
PIE               yes
vde support       no
netmap support    no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
COLO support      yes
RDMA support      no
TCG interpreter   no
fdt support       yes
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
libcap-ng support no
vhost-net support yes
vhost-scsi support yes
vhost-vsock support yes
Trace backends    log
spice support     no 
rbd support       no
xfsctl support    no
smartcard support no
libusb            no
usb net redir     no
OpenGL support    no
OpenGL dmabufs    no
libiscsi support  no
libnfs support    no
build guest agent yes
QGA VSS support   no
QGA w32 disk info no
QGA MSI support   no
seccomp support   no
coroutine backend ucontext
coroutine pool    yes
debug stack usage no
GlusterFS support no
Archipelago support no
gcov              gcov
gcov enabled      no
TPM support       yes
libssh2 support   no
TPM passthrough   yes
QOM debugging     yes
lzo support       no
snappy support    no
bzip2 support     no
NUMA host support no
tcmalloc support  no
jemalloc support  no
avx2 optimization yes
replication support yes

3、make

ubuntu@ubuntu-X556UB:~/qemu$ make

4、make install

ubuntu@ubuntu-X556UB:~/qemu$ sudo make install

5、查看支持的芯片:
ubuntu@ubuntu-X556UB:~/qemu$ qemu-system-arm -M ?
Supported machines are:
akita                Sharp SL-C1000 (Akita) PDA (PXA270)
ast2500-evb          Aspeed AST2500 EVB (ARM1176)
borzoi               Sharp SL-C3100 (Borzoi) PDA (PXA270)
canon-a1100          Canon PowerShot A1100 IS
cheetah              Palm Tungsten|E aka. Cheetah PDA (OMAP310)
collie               Sharp SL-5500 (Collie) PDA (SA-1110)
connex               Gumstix Connex (PXA255)
cubieboard           cubietech cubieboard
highbank             Calxeda Highbank (ECX-1000)
imx25-pdk            ARM i.MX25 PDK board (ARM926)
integratorcp         ARM Integrator/CP (ARM926EJ-S)
kzm                  ARM KZM Emulation Baseboard (ARM1136)
lm3s6965evb          Stellaris LM3S6965EVB
lm3s811evb           Stellaris LM3S811EVB
mainstone            Mainstone II (PXA27x)
midway               Calxeda Midway (ECX-2000)
musicpal             Marvell 88w8618 / MusicPal (ARM926EJ-S)
n800                 Nokia N800 tablet aka. RX-34 (OMAP2420)
n810                 Nokia N810 tablet aka. RX-44 (OMAP2420)
netduino2            Netduino 2 Machine
none                 empty machine
nuri                 Samsung NURI board (Exynos4210)
palmetto-bmc         OpenPOWER Palmetto BMC (ARM926EJ-S)
raspi2               Raspberry Pi 2
realview-eb          ARM RealView Emulation Baseboard (ARM926EJ-S)
realview-eb-mpcore   ARM RealView Emulation Baseboard (ARM11MPCore)
realview-pb-a8       ARM RealView Platform Baseboard for Cortex-A8
realview-pbx-a9      ARM RealView Platform Baseboard Explore for Cortex-A9
romulus-bmc          OpenPOWER Romulus BMC (ARM1176)
sabrelite            Freescale i.MX6 Quad SABRE Lite Board (Cortex A9)
smdkc210             Samsung SMDKC210 board (Exynos4210)
spitz                Sharp SL-C3000 (Spitz) PDA (PXA270)
sx1                  Siemens SX1 (OMAP310) V2
sx1-v1               Siemens SX1 (OMAP310) V1
terrier              Sharp SL-C3200 (Terrier) PDA (PXA270)
tosa                 Sharp SL-6000 (Tosa) PDA (PXA255)
verdex               Gumstix Verdex (PXA270)
versatileab          ARM Versatile/AB (ARM926EJ-S)
versatilepb          ARM Versatile/PB (ARM926EJ-S)
vexpress-a15         ARM Versatile Express for Cortex-A15
vexpress-a9          ARM Versatile Express for Cortex-A9
virt-2.6             QEMU 2.6 ARM Virtual Machine
virt-2.7             QEMU 2.7 ARM Virtual Machine
virt-2.8             QEMU 2.8 ARM Virtual Machine
virt                 QEMU 2.9 ARM Virtual Machine (alias of virt-2.9)
virt-2.9             QEMU 2.9 ARM Virtual Machine
xilinx-zynq-a9       Xilinx Zynq Platform Baseboard for Cortex-A9
z2                   Zipit Z2 (PXA27x)

6、下载内核4.9版本内核linux-4.9.tar.gz并解压到linux-4.9文件夹

https://www.kernel.org/pub/linux/kernel/v4.x/


7、 配置内核并编译 

ubuntu@ubuntu-X556UB:~/Qemu/linux-4.9$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm vexpress_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  SHIPPED scripts/kconfig/zconf.tab.c
  SHIPPED scripts/kconfig/zconf.lex.c
  SHIPPED scripts/kconfig/zconf.hash.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
ubuntu@ubuntu-X556UB:~/Qemu/linux-4.9$ make CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm


8、下载busybox并编译安装

git clone https://github.com/mirror/busybox.git
make defconfig
make CROSS_COMPILE=arm-linux-gnueabi-
make CROSS_COMPILE=arm-linux-gnueabi- install


9、制作文件系统

sudo mkdir rootfs
sudo cp /home/ubuntu/Qemu/busybox/_install/* -r rootfs/
sudo mkdir rootfs/lib/
sudo cp -P /usr/arm-linux-gnueabi/lib/* rootfs/lib/
sudo mkdir rootfs/dev
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
dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
mkfs.ext3 a9rootfs.ext3


10、启动系统

qemu-system-arm -M vexpress-a9 -m 512M -kernel /home/ubuntu/Qemu/linux-4.9/arch/arm/boot/zImage -dtb /home/ubuntu/Qemu/linux-4.9/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -nographic -append "root=/dev/mmcblk0  console=ttyAMA0" -sd /home/ubuntu/Qemu/a9rootfs.ext3

<think>我们正在讨论的是使用QEMU编译Linux内核时的中间文件存放位置。请注意,编译内核和运行QEMU是两个不同的过程。用户的问题是关于编译内核时的中间文件(即编译过程中生成的临时文件)的存储路径,而不是运行QEMU时使用的文件。 编译Linux内核的过程通常是在主机上进行的,而不是在QEMU虚拟机内。编译内核时,中间文件(如.o目标文件)的存放位置由内核源码树中的配置决定。 在Linux内核编译中,中间文件的存放位置遵循以下规则: 1. 默认情况下,当我们执行`make`命令时,中间文件会生成在内核源码目录下的各个子目录中,与源代码文件处于同一目录。 2. 但是,更常见的做法是使用输出目录(output directory)来分离源码和编译生成的文件。这可以通过在编译时指定`O=<dir>`参数来实现,例如: ```bash make O=output/dir ``` 这样,所有的中间文件和最终生成的内核镜像都会存放在`output/dir`目录下,而不会污染源码树。 3. 如果没有指定`O`参数,那么中间文件就会直接生成在源码目录中。 因此,回答用户的问题: - 如果没有指定输出目录,中间文件就在内核源码的各个子目录中。 - 如果指定了输出目录(例如`make O=build`),那么中间文件就在指定的输出目录(如`build`)中。 注意:用户提到的引用中并没有直接说明中间文件的存放位置,但引用[1]和[3]提到了内核编译后的产物(如bzImage)的路径,以及文件系统镜像的生成。这些是最终生成的文件,而不是中间文件。 所以,我们可以这样回答: 在使用QEMU编译Linux内核时,中间文件的存储路径取决于编译时是否指定了输出目录: 1. 若未指定输出目录,则中间文件位于内核源代码的各个子目录中。 2. 若通过`make O=<输出目录>`指定了输出目录,则所有中间文件都位于该输出目录中。 例如,在引用[1]中,编译后的内核镜像路径为`/home/zsz/zsz/linux-4.9.229/arch/x86_64/boot/bzImage`,那么如果没有指定输出目录,则中间文件就分散在`linux-4.9.229`源码目录的各个子目录中。 为了保持源码目录的清洁,推荐使用输出目录。 根据要求,生成相关问题: 1. 如何指定Linux内核编译的输出目录? 2. 如何清理Linux内核编译产生的中间文件? 3. 如何只编译Linux内核的某个特定模块? 4. Linux内核编译过程中生成的中间文件有哪些类型? 5. 如何减少Linux内核编译占用的磁盘空间? 注意:用户提供的引用主要涉及QEMU运行内核,而不是编译内核,因此我们主要依靠内核编译的通用知识来回答。</think>在使用 QEMU 编译 Linux 内核时,中间文件的存储位置取决于编译配置方式,主要有两种情况: ### 1. 默认位置(未指定输出目录) 当直接在内核源码目录执行 `make` 命令时,所有中间文件(如目标文件、临时文件)会生成在**内核源码树的对应子目录中**: ```bash cd linux-5.15 make x86_64_defconfig make -j4 ``` - **中间文件路径**: 各架构的中间文件存放在对应目录下,例如: ``` linux-5.15/arch/x86/boot/compressed/ # 压缩内核相关中间文件 linux-5.15/drivers/usb/core/.built-in.o.cmd # 驱动编译中间文件 linux-5.15/kernel/.sched.o.cmd # 内核调度模块中间文件 ``` ### 2. 指定输出目录(推荐方式) 通过 `O=` 参数指定独立输出目录,所有中间文件会隔离到指定目录: ```bash mkdir build make O=build x86_64_defconfig make O=build -j4 ``` - **中间文件路径**: 全部集中在 `build` 目录下,结构保持与源码树一致: ``` build/arch/x86/boot/compressed/vmlinux.bin # 二进制中间文件 build/.config # 配置缓存 build/Module.symvers # 模块符号表 ``` ### 关键中间文件说明 | 文件类型 | 典型路径示例 | 作用说明 | |--------------------------|----------------------------------|------------------------------| | 目标文件 (.o) | `build/kernel/sched/core.o` | 未链接的编译单元 | | 依赖文件 (.cmd) | `build/kernel/.sched.o.cmd` | Makefile 依赖关系 | | 未压缩内核 | `build/vmlinux` | ELF 格式原始内核 | | 压缩内核 | `build/arch/x86/boot/compressed/vmlinux.bin` | 压缩后的内核二进制 | | 配置文件 | `build/.config` | 编译配置缓存 | | 模块符号表 | `build/Module.symvers` | 模块依赖关系 | > **最佳实践建议**: > 始终使用 `O=<dir>` 指定独立输出目录(如 `build/`),避免污染源码树。清理中间文件只需删除输出目录: > ```bash > rm -rf build/ > ``` 引用[1]和[3]中提到的 `bzImage` 和 `zImage` 是最终生成的内核镜像,位于输出目录的 `arch/<架构>/boot/` 路径下[^1][^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值