如何运行最新的内核源码,把过程记录下。
1.下载源码
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
2.编译
arch/x86/configs/有i386_defconfig和x86_64_defconfig,这里以x86_64_defconfig为例,
make x86_64_defconfig
make -j4
运行内核qemu-system-x86_64 -kernel arch/x86/boot/bzImage
内核已经运行起来了,只不过没有文件系统,死机了。
3.制造fs
从https://busybox.net/downloads/下载busybox,如busybox-1.31.1.tar.bz2
解压,运行make menuconfig,选择
Settings --->
[*] Build static binary (no shared libs)
并保存.config
编译make -j4,并安装make install
cd _install/
sudo chmod 777 run.sh
sudo ./run.sh
run.sh内容如下
mkdir -p proc sys etc dev mnt tmp
mkdir -p etc/init.d/
touch etc/fstab
echo "proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0" > etc/fstab
touch etc/init.d/rcS
echo "/bin/mount -a
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
mdev -s" > etc/init.d/rcS
chmod 755 etc/init.d/rcS
touch etc/inittab
echo "::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::askfirst:-/bin/sh
::cttlaltdel:/bin/umount -a -r" > etc/inittab
chmod 755 etc/inittab
mknod dev/console c 5 1
mknod dev/null c 1 3
mknod dev/tty1 c 4 1
dd if=/dev/zero of=./rootfs.ext4 bs=1M count=32
mkfs.ext4 rootfs.ext4
mkdir -p fs
mount -o loop rootfs.ext4 ./fs
cp linuxrc bin sbin etc dev mnt usr proc sys tmp ./fs -rf
umount ./fs
gzip --best -c rootfs.ext4 > rootfs.img.gz
然后再次运行qemu-system-x86_64 -kernel bzImage -initrd rootfs.img.gz -append "root=/dev/ram init=/linuxrc"