创建自定义启动加载器可引导ISO映像 [英] Creating a bootable ISO image with custom bootloader

查看:677
本文介绍了创建自定义启动加载器可引导ISO映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换一个引导程序我在汇编语言写了一个的 ISO 的图像文件。以下是从 MikeOS 引导程序。这里是我的bootloader code:

I am trying to convert a bootloader I wrote in Assembly Language to an ISO image file. The following is the code from MikeOS bootloader. Here is my bootloader code:

   BITS 16
start:
    mov ax, 07C0h     ; Set up 4K stack space after this bootloader
    add ax, 288       ; (4096 + 512) / 16 bytes per paragraph
    mov ss, ax
    mov sp, 4096

    mov ax, 07C0h     ; Set data segment to where we're loaded
    mov ds, ax

    mov si, text_string   ; Put string position into SI
    call print_string ; Call our string-printing routine

    jmp $         ; Jump here - infinite loop!
    text_string db 'This is my cool new OS!', 0

    print_string:         ; Routine: output string in SI to screen
    mov ah, 0Eh       ; int 10h 'print char' function

.repeat:
    lodsb         ; Get character from string
    cmp al, 0
    je .done      ; If char is zero, end of string
    int 10h           ; Otherwise, print it
    jmp .repeat
.done:
    ret

    times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
    dw 0xAA55     ; The standard PC boot signature

我键入以下命令:

I typed the following command:

nasm -f bin -o boot.bin boot.asm 

此命令工作正常,它给出了一个名为.bin输出。接着我输入下面的命令:

This command works fine and it gives a .bin output. Next I typed the following command:

dd if=boot.bin of=floppy.img count=1 bs=512 

这也工作得很好,给了我的.IMG输出文件。当我键入​​此命令:

This also worked fine and gave me the .img output file. When I type this command:

dd if=boot.bin of=floppy.img skip seek=1 count=1339

我收到以下错误: DD:无法识别操作数'跳过'。在我的 DD 的文件中读取跳跃属性必须分配有一个编号。什么号码,我应该用跳跃属性类型的任何想法(例跳过= 1)。

I get the following error: dd: unrecognized operand ‘skip’. I read in the DD documentation that the skip attribute must have a number assigned to it. Any ideas what number should I type with skip attribute (Ex. skip=1).

接下来我键入以下命令:

Next I type the following command:

mkdosfs -C floppy.img 1440 

我收到以下错误: mkdosfs:无法创建floppy.img 。如何解决我遇到的问题?难道还有其他的,我可以我的引导程序转换.bin文件到的 ISO 的图像更简单的方法?

I get the following error: mkdosfs: unable to create floppy.img. How do I fix the problems I am encountering? Is there another easier way I could convert my bootloader .bin file to an ISO image?

推荐答案

看来你找到了你的榜样以创建可启动的 ISO 的形象从这个的 StackOverflow的答案。不幸的是,你挑一个公认的答案是不正确在许多方面。 pretend你从来没有见过这个问题的答案。

It appears you found your example for creating a bootable ISO image from this StackOverflow Answer. Unfortunately you picked an accepted answer that is incorrect in many ways. Pretend you never saw that answer.

在大多数Linux发行版无论是节目叫 genisoimage 的mkisofs 存在。这些天,他们实际上是相同的程序。你必须取其可以在下面的实施例被取代。我的例子将承担的 ISO 的创建工具叫做 genisoimage

On most Linux distros either a program called genisoimage or mkisofs exists. These days they are actually the same program. Whichever you have can be substituted in the examples below. My examples will assume the ISO creation utility is called genisoimage.

在你的问题,你有一个名为某些引导程序code boot.asm 。你正确地组装这被引导扇区二进制图像:

In your question you have some bootloader code in a file called boot.asm. You correctly assemble this to a boot sector binary image with:

nasm -f bin -o boot.bin boot.asm

这将创建 BOOT.BIN 这是你的引导扇区。下一步是在第一个扇区创建软盘映像和地点 BOOT.BIN 。你可以这样做与此:

This creates boot.bin which is your boot sector. The next step is to create a floppy disk image and place boot.bin in the first sector. You can do that with this:

dd if=/dev/zero of=floppy.img bs=1024 count=1440
dd if=boot.bin of=floppy.img seek=0 count=1 conv=notrunc

第一命令只是使一个零填充磁盘映像等于一个1.44MB软盘(1024 * 1440字节)的大小。第二个命令的地方 BOOT.BIN floppy.img 的第一个扇区不截断该文件的其余部分。 寻求= 0 表示,争取第一个扇区(512字节是块的默认大小的 DD 的)。 计数= 1 指定我们只希望1扇区(512字节)从 BOOT.BIN 复制。 =单次转​​换notrunc之外表示,写入输出文件,剩余磁盘映像保持不变(而不是截断)。在

The first command simply makes a zero filled disk image equal to the size of a 1.44MB floppy (1024*1440 bytes). The second command places boot.bin into the first sector of floppy.img without truncating the rest of the file. seek=0 says seek to first sector (512 bytes is default size of a block for DD). count=1 specifies we only want to copy 1 sector (512 bytes) from boot.bin. conv=notrunc says that after writing to the output file, that the remaining disk image is to remain intact (not truncated).

建立一个磁盘映像后如上图所示,你可以创建一个 ISO 的这些命令的图片:

After building a disk image as shown above, you can create an ISO image with these commands:

mkdir iso
cp floppy.img iso/
genisoimage -quiet -V 'MYOS' -input-charset iso8859-1 -o myos.iso -b floppy.img -hide floppy.img iso/

以上第一命令创建一个子目录名为 ISO 将包含文件被放置到最后CD-ROM映像。第二个命令没有做任何事情超过复制我们的 floppy.img ISO 目录,因为我们需要为启动。第三个命令确实繁重,并构建的 ISO 的形象。

The commands above first create a sub-directory called iso that will contain the files to be placed onto the final CD-ROM image. The second command doesn't do anything more than copy our floppy.img into iso directory because we need that for booting. The third command does the heavy lifting and builds the ISO image.


  • -V'MYOS设定卷标(它可以是任何你想要的)

  • - 输入,字符集ISO8859-1 台套正在使用的字符。不要改变它

  • -o myos.iso 说的 ISO 的图像将被输出到文件 myos.iso

  • -b floppy.img 说我们的 ISO 的将是启动和正在使用的引导映像文件 floppy.img

  • 不需要 -hide floppy.img ,但它隐藏了最后的ISO的目录列表引导映像。如果你安装这个的 ISO 的和做它的一个 LS 列出文件, floppy.img 将不会出现。

  • ISO / 在命令的最后是将用于构建的 ISO 的图像从该目录。它需要至少包含我们的启动软盘映像,但你可以把你想成 ISO / 目录中的任何其他文件。

  • -V 'MYOS' sets the volume label (It can be whatever you want)
  • -input-charset iso8859-1 sets the character set being used. Don't change it
  • -o myos.iso says the ISO image will be output to the file myos.iso
  • -b floppy.img says that our ISO will be bootable and the boot image being used is the file floppy.img
  • -hide floppy.img isn't needed but it hides the boot image from the final ISO's directory listing. If you were to mount this ISO and do an ls on it to list the files, floppy.img wouldn't appear.
  • iso/ on the end of the command is the directory that will be used to build the ISO image from. It needs to at least contain our bootable floppy image, but you can place any other files you wish into the iso/ directory.

ISO 的图像时产生 myos.iso 可引导。使用的一个例子的 QEMU 的推出这样一个形象:

The ISO image myos.iso that is generated can be booted. An example of using QEMU to launch such an image:

qemu-system-i386 -cdrom ./myos.iso

这篇关于创建自定义启动加载器可引导ISO映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆