目的
在真机上用USB引导运行JOS
原料准备
JOS(MIT 操作系统教学Demo 基于VX6开发的精简版本)
MobaXterm(远程连接)
VMware
QEMU
GRUB2
Ubuntu(工具:dd 、readelf、 objdump、 file 、hexdump、 fdisk、 losetup、 mount )
过程简介
1 修改JOS源代码的链接文件: vi /root/lab/kern/kernel.ld 替换_start入口为entry(GRUB下寻址)
/* Simple linker script for the JOS kernel. See the GNU ld 'info' manual ("info ld") to learn the syntax. */
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")OUTPUT_ARCH(i386)
/*ENTRY(_start)*/ENTRY(entry)*/
ENTRY(entry)
2 编译JOS
root@ubuntu:~/lab# make (make grub/make qemu/make qemu-gdb)
3 创建一个空镜像, 还可测试硬盘写入速度
dd if=/dev/zero of=jos.img bs=1M count=20
4 格式化设备,支持FAT/EXT等格式
mkfs.vfat jos.img
5 将镜像文件挂载成模拟设备
losetup
/dev/loop0 jos.img
mount /dev/loop0 /mnt/usb
6 安装grub文件
grub-install --root-directory=/mnt/usb/boot --no-floppy /dev/loop
7 配置grub.cfg
menuentry 'MIT-JOS'{
echo 'Loading ISO...'
multiboot /boot/kernel-7.0
}
8 启动QEMU虚拟机
qemu-system-x86_64-hda jos.img
9 运行正常后可将JOS.img 文件通过dd命令写入USB设备,在真机上运行
格式化USB、挂载USB、dd写入
dd if=jos.img of=/dev/sdb
需要注意虚拟机连接USB的图标

网友评论