写点什么

Qemu Linux

作者:贾献华
  • 2022 年 7 月 04 日
  • 本文字数:1310 字

    阅读完需:约 4 分钟

sudo apt install -y qemu qemu-system-x86
复制代码

Linux Kernel

The Linux Kernel Archives


wget -c https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.12.5.tar.xztar xvf linux-5.12.5.tar.xzcd linux-5.12.5/make x86_64_defconfig# zImagesudo apt install libelf-devmake bzImagemake modulesfind . -name bzImage# ./arch/x86/boot/bzImage# ./arch/x86_64/boot/bzImage
复制代码

First Boot

qemu-system-x86_64 \    -m 512M \  # 指定内存大小    -smp 4\  # 指定虚拟的 CPU 数量    -kernel ./arch/x86/boot/bzImage  # 指定内核文件路径
复制代码



[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0, 0) ]

rootfs

qemu-img create -f raw disk.raw 512Mmkfs -t ext4 ./disk.rawsudo mount -o loop ./disk.raw ./img# 安装内核模块sudo make modules_install INSTALL_MOD_PATH=./img  # 指定安装路径
复制代码


  • Log

  • INSTALL drivers/thermal/intel/x86_pkg_temp_thermal.koINSTALL fs/efivarfs/efivarfs.koINSTALL net/ipv4/netfilter/iptable_nat.koINSTALL net/ipv4/netfilter/nf_log_arp.koINSTALL net/ipv4/netfilter/nf_log_ipv4.koINSTALL net/ipv6/netfilter/nf_log_ipv6.koINSTALL net/netfilter/nf_log_common.koINSTALL net/netfilter/xt_LOG.koINSTALL net/netfilter/xt_MASQUERADE.koINSTALL net/netfilter/xt_addrtype.koINSTALL net/netfilter/xt_mark.koINSTALL net/netfilter/xt_nat.koDEPMOD 5.12.5


sudo ls ./img/lib/modules# 5.12.5
复制代码

Second boot

qemu-system-x86_64 \    -m 512M \    -smp 4\    -kernel ./arch/x86/boot/bzImage \    -drive format=raw,file=./disk.raw \  # 指定文件作为磁盘    -append "root=/dev/sda"  # 内核启动参数,指定根文件系统所在设备
复制代码



[ end Kernel panic - not syncing: No working init found. Try passing init= option to Kernel. See Linux Documentation/admin-guide/init.rst for guidance. ]

busybox

BusyBox


make defconfigmake menuconfig
复制代码


  • menuconfig

  • Settings --->--- Build Options[*] Build BusyBox as a static binary (no shared libs)


makesudo make CONFIG_PREFIX=../linux-5.12.5/img/ install
复制代码


cd ../linux-5.12.5/qemu-system-x86_64 \    -m 512M \    -smp 4\    -kernel ./arch/x86/boot/bzImage \    -drive format=raw,file=./disk.raw \    -append "init=/linuxrc root=/dev/sda"
复制代码



can't run '/etc/init.d/rcS': No such file or directorycan't open /dev/tty3: No such file or directorycan't open /dev/tty4: No such file or directory


sudo mkdir -p ./img/etc/init.d/sudo vi ./img/etc/inittabsudo vi ./img//etc/init.d/rcS
复制代码


./img/etc/inittab


::sysinit:/etc/init.d/rcS::askfirst:/bin/ash::ctrlaltdel:/sbin/reboot::shutdown:/sbin/swapoff -a::shutdown:/bin/umount -a -r::restart:/sbin/init
复制代码


./img/etc/init.d/rcS


#!/bin/sh
复制代码



/dev /sys /proc


sudo mkdir ./img/dev ./img/proc ./img/sys
复制代码


./img/etc/init.d/rcS


#!/bin/sh
mount -t proc proc /procmount -t sysfs sysfs /sys
复制代码


参考


用户头像

贾献华

关注

及时当勉励 岁月不待人 2018.06.04 加入

https://2022.iosdevlog.com

评论

发布
暂无评论
Qemu Linux_7月日更_贾献华_InfoQ写作社区