运行一个简单的Linux系统

该篇博客参考自孟宁老师发布的Linux内核分析https://www.shiyanlou.com/teacher/19301

因为我在自己的虚拟机上运行这个实验的时候出了一些问题,所以写这个不是博客的博客,供大家参考。原文请参考孟宁老师的博客,我这个只是我自己在跑的时候出现的一些问题,和一需要的改动,希望能够帮助一些使用ubuntu 虚拟搭建这个环境的娃。

1.创建自己的linux内核目标,并把linux 内核代码clone下来(参看自孟宁老师的实验指导)

mkdir LinuxKernel

cd ~/LinuxKernel/ 
wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.18.6.tar.xz
xz -d linux-3.18.6.tar.xz
tar -xvf linux-3.18.6.tar
cd linux-3.18.6
make i386_defconfig
make # 一般要编译很长时间,少则20分钟多则数小时

2. 制作根文件系统(参看自孟宁老师的实验指导)

git clone https://github.com/mengning/menu.git   
cd menu
gcc -o init linktable.c menu.c test.c -m32 -static –lpthread (这个命令看着是不能用了)
//gcc -Wall -pthread -o init linktable.c menu.c test.c -m32 -static (请使用这个来编译文件)

3. 修改部分

直接在修改menu目录下的Makefile:

把qemu命令替换成qemu-system-i386。

接着在memu目录下运行“make rootfs”,这个命令可以直接编译,同时运行kernel。

现在给看下目录结构:

root@ubuntu:~/linuxkernel/kernel# tree -L 1
.
├── init
├── linux-3.18.6
├── linux-3.18.6.tar
├── menu
├── rootfs
└── rootfs.img

3 directories, 3 files
linux-3.18.6 和menu在同个目录下。

运行后的效果图:

暂时算原创吧~.~

猜你喜欢

转载自blog.csdn.net/llanlianggui/article/details/86374608