ubuntu18.04 qemu环境搭建【学习笔记】
原创
©著作权归作者所有:来自51CTO博客作者请给我倒杯茶的原创作品,请联系作者获取转载授权,否则将追究法律责任
一、准备工具
1.1 安装相关工具
1.2 下载kernel(linux-4.0)与busybox(1.24)源码
https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/
https://busybox.net/downloads/busybox-1.24.0.tar.bz2
二、编译最小文件系统
2.1 解压busybox
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make menuconfig 选中静态编译
|
Busybox Settings --->
|
[*] Build BusyBox as a static binary (no shared libs)
make install
cd _install
mkdir etc dev mnt
mkdir -p etc/init.d/
cd etc/init.d/
vim rcS
mkdir -p /proc
mkdir -p /tmp
mkdir -p /sys
mkdir -p /mnt
/bin/mount -a
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
chmod a+x rcS
cd ..
vim fstab
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
debugfs /sys/kernel/debug defaults defaults 0 0
vim inittab
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
cd ..
cd dev
sudo mknod console c 5 1
sudo mknod null c 1 3
拷贝交叉工具链的库到根文件系统
cp /opt/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/lib/*so* lib/ -d
cp /opt/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/arm-linux-gnueabi/libc/usr/lib/*so* usr/lib -d
生成ext3镜像文件并挂载
sudo dd if=/dev/zero of=a9rootfs.ext3 bs=1M count=32
mkfs.ext3 path/a9rootfs.ext3
mkdir tmpfs
sudo mount -t ext3 a9rootfs.ext3 tmpfs -o loop
sudo cp -r rootfs/*tmpfs
sudo umount tmpfs
启动参数要添加-sd选项
进入系统执行mount -t ext3 /dev/mmcblk0 /mnt/
2.2 linux编译配置
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
make vexpress_defconfig
make menuconfig
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
(_install) Initramfs source file(s)
() Default kernel command string
Kernel Features --->
Memory split (3G/1G user/kernel split) --->
(X) 3G/1G user/kernel split
make bzImage -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
make dtbs
启动qemu
qemu-system-arm -M vexpress-a9 -smp 4 -m 1024M -kernel arch/arm/boot/zImage -append "rdinit=/linuxrc console=ttyAMA0 loglevel=8"