听听音乐 發表於 2022-5-10 21:14:00

汇编语言

<p>汇编语言一发入魂 – 杨河老李 (kviccn.github.io)</p>
<p>Writing a Bootloader Part 1 | Alex Parker's Website (3zanders.co.uk) &nbsp;Part 2</p>
<p>part 3&nbsp;在Ubuntu的编译:sudo apt install build-essential -y</p>
<blockquote>
<p>asm: <strong>nasm -f elf32 a.asm -o boot1.bin</strong></p>
<p>comipile:<strong> g++ -m32 -ffreestanding -fno-exceptions -fno-rtti -fno-pic -Wall -Wextra -Werror -nostdlib -std=c++11 -o <span style="text-decoration: underline">kmain.o</span> -c kmain.cpp</strong></p>
<p>ld:<strong> ld -m elf_i386 -T linker.ld -o kernel.bin <span style="text-decoration: underline">boot1.bin</span> &nbsp;kmain.o</strong></p>
<p>check:</p>
<p><strong>hexdump kernel.bin</strong></p>
<p>run:</p>
<p><strong>qemu-system-x86_64 -fda kernel.bin</strong></p>
</blockquote>
<p>&nbsp;</p>
<blockquote>
<p>When you press the power button the computer loads the BIOS from some flash memory stored on the motherboard. The BIOS initializes and self tests the hardware then loads the first 512 bytes into memory from the media device (i.e. the cdrom or floppy disk). If the last two bytes equal&nbsp;<code>0xAA55</code>&nbsp;then the BIOS will jump to location&nbsp;<code>0x7C00</code>&nbsp;effectively transferring control to the bootloader.</p>
<p>At this point the CPU is running in 16 bit mode, meaning only the 16 bit registers are available. Also since the BIOS only loads the first 512 bytes this means our bootloader code has to stay below that limit, otherwise we’ll hit uninitialised memory!</p>
<p>只加载512k内容。其他内存区域是未初始化状态。</p>
</blockquote>
<h2 class="ContentItem-time" tabindex="0" role="button">BIOS启动:</h2>
<div class="ContentItem-time" tabindex="0" role="button">
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-6" class="markdown-section" data-markdown-raw="
### Boot Process Overview" data-section-index="6">
<h3>Boot Process Overview</h3>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-8" class="markdown-section" data-markdown-raw="
1. **BIOS Initialization**:" data-section-index="8">
<ul>
<li value="1"><span class="markdown-bold-text">BIOS Initialization</span>:</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-9" class="markdown-section" data-markdown-raw="
   - When a computer is powered on, the Basic Input/Output System (BIOS) performs a Power-On Self Test (POST) to check the hardware components and ensure everything is functioning correctly." data-section-index="9">
<ul>
<li>When a computer is powered on, the Basic Input/Output System (BIOS) performs a Power-On Self Test (POST) to check the hardware components and ensure everything is functioning correctly.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-11" class="markdown-section" data-markdown-raw="
2. **Loading the Boot Sector**:" data-section-index="11">
<ul>
<li value="2"><span class="markdown-bold-text">Loading the&nbsp;Boot&nbsp;Sector</span>:</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-12" class="markdown-section" data-markdown-raw="
   - After POST, the BIOS looks for a bootable device (like a hard drive, CD-ROM, or floppy disk) based on the boot order configured in the BIOS settings." data-section-index="12">
<ul>
<li>After POST, the&nbsp;BIOS looks for a bootable device&nbsp;(like&nbsp;a hard&nbsp;drive, CD-ROM, or&nbsp;floppy disk) based&nbsp;on the boot order configured&nbsp;in&nbsp;the BIOS settings.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-13" class="markdown-section" data-markdown-raw="
   - The BIOS reads the first sector (512 bytes) from the bootable device. This sector is known as the Master Boot Record (MBR) on hard drives or the boot sector on other media." data-section-index="13">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<p>The BIOS reads the first sector (512 bytes) from the bootable device. This sector is known as the Master Boot Record (MBR) on hard drives or the boot sector on other media.</p>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-15" class="markdown-section" data-markdown-raw="
3. **Boot Signature Check**:" data-section-index="15">3.&nbsp;<span class="markdown-bold-text">Boot Signature Check</span>:</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-16" class="markdown-section" data-markdown-raw="
   - The last two bytes of this 512-byte sector must contain the boot signature `0xAA55`. This signature indicates that the sector is a valid boot sector." data-section-index="16">
<ul>
<li>The last two&nbsp;bytes&nbsp;of this 512-byte&nbsp;sector&nbsp;must contain the boot signature&nbsp;<span class="markdown-inline-code">0xAA55</span>. This signature indicates that the sector is a valid boot sector.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-17" class="markdown-section" data-markdown-raw="
   - If the signature is present, the BIOS considers the sector bootable." data-section-index="17">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li>If the signature is&nbsp;present, the&nbsp;BIOS considers the sector&nbsp;bootable.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-19" class="markdown-section" data-markdown-raw="
4. **Loading into Memory**:" data-section-index="19">
<div class="markdown-section-toolbar">
<div>
<div class="markdown-section-toolbar-internal">
<div class="markdown-section-toolbar-item markdown-section-toolbar-copy dark">4. <span class="markdown-bold-text">Loading into Memory</span>:</div>
</div>
</div>
</div>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-20" class="markdown-section" data-markdown-raw="
   - The BIOS loads these 512 bytes into a specific location in memory, which is typically `0x7C00`." data-section-index="20">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li>The BIOS&nbsp;loads&nbsp;these 512 bytes into&nbsp;a specific&nbsp;location in&nbsp;memory, which&nbsp;is&nbsp;typically&nbsp;<span class="markdown-inline-code">0x7C00</span>.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-21" class="markdown-section" data-markdown-raw="
   - This location is chosen because it is a conventional memory address that is free and available during the boot process. It is within the first 1MB of memory, which is accessible in real mode (the mode the CPU is in when the system first starts)." data-section-index="21">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li>This location&nbsp;is&nbsp;chosen because it is&nbsp;a conventional memory&nbsp;address&nbsp;that is free&nbsp;and available&nbsp;during the&nbsp;boot process. It&nbsp;is&nbsp;within the first&nbsp;1MB of&nbsp;memory, which is accessible in&nbsp;real mode&nbsp;(the&nbsp;mode the&nbsp;CPU is&nbsp;in when&nbsp;the system&nbsp;first starts).</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-23" class="markdown-section" data-markdown-raw="
5. **Transferring Control**:" data-section-index="23">
<div class="markdown-section-toolbar">
<div>
<div class="markdown-section-toolbar-internal">
<div class="markdown-section-toolbar-item markdown-section-toolbar-copy dark">5. <span class="markdown-bold-text">Transferring Control</span>:</div>
</div>
</div>
</div>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-24" class="markdown-section" data-markdown-raw="
   - After loading the boot sector into memory at `0x7C00`, the BIOS jumps to this address to execute the code contained in the boot sector." data-section-index="24">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li>After loading&nbsp;the boot&nbsp;sector into&nbsp;memory&nbsp;at&nbsp;<span class="markdown-inline-code">0x7C00</span>, the BIOS jumps&nbsp;to&nbsp;this address to&nbsp;execute&nbsp;the code contained&nbsp;in the&nbsp;boot sector.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-25" class="markdown-section" data-markdown-raw="
   - This effectively transfers control from the BIOS to the bootloader, which is responsible for loading the operating system." data-section-index="25">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li>This&nbsp;effectively&nbsp;transfers&nbsp;control from the BIOS to the bootloader, which is responsible&nbsp;for loading the&nbsp;operating system.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-27" class="markdown-section" data-markdown-raw="
### Why `0x7C00`?" data-section-index="27">
<div class="markdown-section-toolbar">
<div>
<div class="markdown-section-toolbar-internal">
<div class="markdown-section-toolbar-item markdown-section-toolbar-copy dark">Why <span class="markdown-inline-code">0x7C00</span>?</div>
<div class="markdown-section-toolbar-item markdown-section-toolbar-copy dark">
<p><strong>FFFF=64k = 65535;&nbsp; </strong></p>
<p><strong>&nbsp;7c00= 31744</strong></p>
</div>
</div>
</div>
</div>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-29" class="markdown-section" data-markdown-raw="
- **Historical Reasons**: The choice of `0x7C00` is largely historical. It was chosen as a convenient location that is free and does not conflict with other system components during the boot process." data-section-index="29">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-bold-text">Historical&nbsp;Reasons</span>: The choice of&nbsp;<span class="markdown-inline-code">0x7C00</span>&nbsp;is largely&nbsp;historical. It was chosen&nbsp;as&nbsp;a convenient location that&nbsp;is&nbsp;free and does&nbsp;not conflict&nbsp;with&nbsp;other&nbsp;system components during the boot process.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-30" class="markdown-section" data-markdown-raw="
- **Real Mode Constraints**: In real mode, the CPU can only address the first 1MB of memory. `0x7C00` is within this range, making it accessible during the initial boot phase." data-section-index="30">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-bold-text">Real&nbsp;Mode&nbsp;Constraints</span>: In&nbsp;real mode, the CPU&nbsp;can&nbsp;only address the&nbsp;first&nbsp;1MB&nbsp;of memory.&nbsp;<span class="markdown-inline-code">0x7C00</span>&nbsp;is within&nbsp;this range, making it accessible&nbsp;during the&nbsp;initial boot&nbsp;phase.</li>
</ul>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-32" class="markdown-section" data-markdown-raw="
### Summary" data-section-index="32">
<div class="markdown-section-toolbar">
<div>
<div class="markdown-section-toolbar-internal">
<div class="markdown-section-toolbar-item markdown-section-toolbar-copy dark">Summary</div>
</div>
</div>
</div>
</section>
<section id="markdown-section-536d4b43-559a-451c-8437-f6e4fe2949a7-34" class="markdown-section" data-markdown-raw="
The process described is a fundamental part of how BIOS-based systems boot. The bootloader, once executed, can then load the operating system kernel into memory and switch the CPU to protected mode, allowing the full capabilities of the system to be utilized. This process is specific to BIOS; modern systems often use UEFI, which has a different boot process." data-section-index="34">The&nbsp;process described&nbsp;is a&nbsp;fundamental part&nbsp;of how&nbsp;BIOS-based systems boot. The&nbsp;bootloader, once&nbsp;executed, can then&nbsp;load&nbsp;the operating system kernel&nbsp;into memory and&nbsp;switch&nbsp;the CPU to&nbsp;protected mode, allowing&nbsp;the full&nbsp;capabilities of&nbsp;the system&nbsp;to be&nbsp;utilized. This process is specific&nbsp;to&nbsp;BIOS; modern systems often&nbsp;use UEFI, which&nbsp;has a&nbsp;different&nbsp;boot process.</section>
<section class="markdown-section" data-markdown-raw="
The process described is a fundamental part of how BIOS-based systems boot. The bootloader, once executed, can then load the operating system kernel into memory and switch the CPU to protected mode, allowing the full capabilities of the system to be utilized. This process is specific to BIOS; modern systems often use UEFI, which has a different boot process." data-section-index="34"></section>
<section class="markdown-section" data-markdown-raw="
The process described is a fundamental part of how BIOS-based systems boot. The bootloader, once executed, can then load the operating system kernel into memory and switch the CPU to protected mode, allowing the full capabilities of the system to be utilized. This process is specific to BIOS; modern systems often use UEFI, which has a different boot process." data-section-index="34">
<section id="markdown-section-b5c3b6e7-51fd-4075-8eda-7a948b494d89-8" class="markdown-section" data-markdown-raw="
### 16-bit Real Mode" data-section-index="8">
<h3>16-bit Real Mode</h3>
<p>1. <span class="markdown-bold-text">16-bit Mode</span>: When the CPU starts, it operates in real mode, which is a 16-bit mode. This means that the CPU can use 16-bit registers and can address up to 1MB of memory (though typically only the first 640KB is usable for conventional memory).</p>
</section>
<section id="markdown-section-b5c3b6e7-51fd-4075-8eda-7a948b494d89-13" class="markdown-section" data-markdown-raw="
2. **Addressing in Real Mode**:" data-section-index="13">
<ul>
<li value="2"><span class="markdown-bold-text">Addressing in Real&nbsp;Mode</span>:</li>
</ul>
</section>
<section id="markdown-section-b5c3b6e7-51fd-4075-8eda-7a948b494d89-14" class="markdown-section" data-markdown-raw="
   - In real mode, memory is addressed using a combination of segment and offset registers. The effective address is calculated as `segment * 16 + offset`." data-section-index="14">
<ul>
<li>In real&nbsp;mode, memory is addressed&nbsp;using&nbsp;a combination of&nbsp;segment&nbsp;and&nbsp;offset&nbsp;registers. The effective address&nbsp;is calculated&nbsp;as&nbsp;<span class="markdown-inline-code">segment&nbsp;*&nbsp;16 +&nbsp;offset</span>.</li>
</ul>
</section>
<section id="markdown-section-b5c3b6e7-51fd-4075-8eda-7a948b494d89-15" class="markdown-section" data-markdown-raw="
   - This addressing scheme allows access to the first 1MB of memory, but each segment can only be 64KB in size." data-section-index="15">
<ul>
<li>This addressing scheme allows access to the first 1MB of memory, but each segment can only be 64KB in size.</li>
<li>&nbsp;</li>
</ul>
<h1>创建一个启动盘 Bootable USB Drive</h1>
<p>1, 编译这段代码</p>
<details>
<summary>hello.s</summary>
<pre class="language-cpp highlighter-hljs"><code>
.code16

movw $0x07c0, %ax
movw %ax, %ds

movw $0xb800, %ax
movw %ax, %es

xorw %si, %si
movw message_length, %cx

l1:
movb message(%si), %bl
movb %bl, %es:(%si)
incw %si
loop l1

jmp .

message:
.byte 'H', 0xa, 'e', 0xa, 'l', 0xa, 'l', 0xa, 'o', 0xa, ' ', 0xa, 'W', 0xa, 'o', 0xa, 'r', 0xa, 'l', 0xa, 'd', 0xa
message_length:
.word . - message

.org 510
.word 0xAA55</code></pre>
</details>
<blockquote>
<p>&nbsp;as --32 boot.s -o boot.o</p>
<p>objcopy -O binary -j .text boot.o boot.bin</p>
<p>exdump boot0.bin 查看</p>
<p><strong><span style="color: rgba(224, 62, 45, 1)">一定注意,将没用的区域清零</span></strong>。否则总是引导不成功。由于这个boot.bin只有512。那么后面需要接00 00...</p>
<p><span style="color: rgba(224, 62, 45, 1)"><strong>dd if=/dev/zero of=disk.img bs=1024 count=100</strong></span> 生产一个清空的磁盘印象。块大小是1024,产生100个,就是102400字节大小。</p>
</blockquote>
<p>&nbsp;</p>
<section id="markdown-section-c1bc3c84-a864-4e94-b49a-4584ff2c9cbc-12" class="markdown-section" data-markdown-raw="
   - Identify the device name of your USB drive using the `lsblk` or `fdisk -l` command. It will be something like `/dev/sdX` (where `X` is a letter representing the drive)." data-section-index="12">
<ul>
<li>Identify&nbsp;the device&nbsp;name of&nbsp;your USB drive&nbsp;using the<strong>&nbsp;<span class="markdown-inline-code">lsblk</span></strong>&nbsp;or&nbsp;<strong><span class="markdown-inline-code" style="color: rgba(224, 62, 45, 1)">fdisk&nbsp;-l</span>&nbsp;</strong>command. It&nbsp;will be something&nbsp;like<strong>&nbsp;<span class="markdown-inline-code">/dev/sdX</span></strong>&nbsp;(where&nbsp;<span class="markdown-inline-code">X</span>&nbsp;is&nbsp;a letter representing&nbsp;the drive).</li>
</ul>
</section>
<section id="markdown-section-c1bc3c84-a864-4e94-b49a-4584ff2c9cbc-14" class="markdown-section" data-markdown-raw="
2. **Backup Data**:" data-section-index="14">
<div class="markdown-section-toolbar">
<div>
<div class="markdown-section-toolbar-internal"><strong><span class="markdown-inline-code" style="color: rgba(224, 62, 45, 1)">fdisk&nbsp;-l</span></strong></div>
</div>
</div>
</section>
<section id="markdown-section-c1bc3c84-a864-4e94-b49a-4584ff2c9cbc-18" class="markdown-section" data-markdown-raw="
   - Use the `dd` command to write your `boot.bin` file to the USB drive. This will overwrite the beginning of the drive with your bootloader code.

   ```bash
   sudo dd if=boot.bin of=/dev/sdX bs=512 count=1
   ```
" data-section-index="18">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<blockquote>
<ul>
<li>Use&nbsp;the&nbsp;<span class="markdown-inline-code">dd</span>&nbsp;command&nbsp;to write your&nbsp;<span class="markdown-inline-code">boot.bin</span>&nbsp;file&nbsp;to the USB&nbsp;drive. This will overwrite&nbsp;the&nbsp;beginning of the&nbsp;drive with your&nbsp;bootloader code.
<div id="markdown-code-block-editor-vs.editor.ICodeEditor:85" class="markdown-code-outer-container markdown-block-code">
<div class="markdown-code-block-header">
<div>
<div>
<div>
<div>
<div class="show-file-icons">&nbsp;</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div data-keybinding-context="109" data-mode-id="shellscript">
<div class="monaco-editor no-user-selectshowUnused showDeprecated vs-dark" role="code" data-uri="aichat-code-block-anysphere://slrwdqaijw">
<div class="overflow-guard" data-mprt="3">
<div class="monaco-scrollable-element editor-scrollable vs-dark" role="presentation" data-mprt="6">
<div class="lines-content monaco-editor-background">
<div class="view-rulers" role="presentation" aria-hidden="true">&nbsp;</div>
<div class="view-lines monaco-mouse-cursor-text" role="presentation" aria-hidden="true" data-mprt="8">
<div class="view-line"><span class="mtk1">&nbsp;</span><span style="color: rgba(224, 62, 45, 1)"><strong><span class="mtk9">sudo</span><span class="mtk1">&nbsp;</span><span class="mtk12">dd</span><span class="mtk1">&nbsp;</span><span class="mtk12">if=boot.bin</span><span class="mtk1">&nbsp;</span><span class="mtk12">of=/dev/sdX</span><span class="mtk1">&nbsp;</span><span class="mtk12">bs=</span><span class="mtk15">512</span><span class="mtk1">&nbsp;</span><span class="mtk12">count=</span><span class="mtk15">1&nbsp; (这句会导致 /dev/sdX建立,如果没有U盘时。所以用之前先确认一下U盘的盘符在吗。或者有方法可以让这条语句执行不成功,如果 /dev/sdb 不存在的话。)</span></strong></span></div>
<div class="view-line">&nbsp;</div>
<div class="view-line"><span style="color: rgba(224, 62, 45, 1)"><strong><span class="mtk15">在boot.bin是512大小就可以了。</span></strong></span></div>
<div class="view-line"><span style="color: rgba(52, 73, 94, 1)"><strong><span class="mtk15">如果超过512,需要写剩下的,比如总大小是744:744-512=232</span></strong></span></div>
<div class="view-line">
<div><span style="color: rgba(22, 145, 121, 1)"><strong>sudo dd if=kernel.bin of=/dev/sdb bs=232 seek=1 skip=1 count=1</strong></span></div>
<div>
<div>
<div>&nbsp;</div>
</div>
</div>
<div>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-12" class="markdown-section" data-markdown-raw="
   - **Explanation**:" data-section-index="12">
<ul>
<li><span class="markdown-bold-text">Explanation</span>:</li>
</ul>
</section>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-13" class="markdown-section" data-markdown-raw="
   - `if=combined.bin`: Input file is `combined.bin`." data-section-index="13">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-inline-code">if=combined.bin</span>: <strong><span style="color: rgba(45, 194, 107, 1)">Input&nbsp;file</span>&nbsp;</strong>is&nbsp;<span class="markdown-inline-code">combined.bin</span>.</li>
</ul>
</section>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-14" class="markdown-section" data-markdown-raw="
   - `of=/dev/sdX`: Output file is the USB drive (replace `sdX` with your actual device)." data-section-index="14">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-inline-code">of=/dev/sdX</span>: <span style="color: rgba(45, 194, 107, 1)"><strong>Output&nbsp;file</strong></span>&nbsp;is&nbsp;the&nbsp;USB&nbsp;drive&nbsp;(replace&nbsp;<span class="markdown-inline-code">sdX</span>&nbsp;with&nbsp;your&nbsp;actual&nbsp;device).</li>
</ul>
</section>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-15" class="markdown-section" data-markdown-raw="
   - `bs=232`: Block size is set to 232 bytes, which is the size of the remaining data." data-section-index="15">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-inline-code">bs=232</span>: <strong><span style="color: rgba(45, 194, 107, 1)">Block&nbsp;size&nbsp;</span></strong>is&nbsp;set&nbsp;to&nbsp;232 bytes, which&nbsp;is&nbsp;the&nbsp;size&nbsp;of&nbsp;the&nbsp;remaining&nbsp;data.</li>
</ul>
</section>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-16" class="markdown-section" data-markdown-raw="
   - `skip=1`: Skip the first 512 bytes of `combined.bin` (the boot sector)." data-section-index="16">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-inline-code">skip=1</span>: Skip&nbsp;the&nbsp;first&nbsp;512 bytes&nbsp;of&nbsp;<span class="markdown-inline-code">combined.bin</span>&nbsp;(the&nbsp;boot&nbsp;sector).</li>
</ul>
</section>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-17" class="markdown-section" data-markdown-raw="
   - `seek=1`: Start writing at the second sector of the USB drive." data-section-index="17">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
<ul>
<li><span class="markdown-inline-code">seek=1</span>: Start&nbsp;writing&nbsp;at&nbsp;the&nbsp;second sector of&nbsp;the&nbsp;USB&nbsp;drive.</li>
<li>count=1 是认为写一个block。而block的大小是 232,因为 bs=232</li>
</ul>
<p>&nbsp;</p>
<p><span style="color: rgba(224, 62, 45, 1)">写完后别忘了 sync</span></p>
<div>&nbsp;sync</div>
<div>&nbsp; &nbsp;sudo eject /dev/sdX</div>
</section>
<section id="markdown-section-3a8233cb-ba30-4128-adc8-befde4cb55b6-19" class="markdown-section" data-markdown-raw="
### Important Note" data-section-index="19">
<div class="markdown-section-toolbar">
<div>&nbsp;</div>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
</blockquote>
</section>
<section id="markdown-section-c1bc3c84-a864-4e94-b49a-4584ff2c9cbc-23" class="markdown-section" data-markdown-raw="
   - If your bootloader or operating system requires a filesystem, you can create one on the USB drive. For example, to create a FAT32 filesystem:

   ```bash
   sudo mkfs.vfat /dev/sdX1
   ```
" data-section-index="23">
<ul>
<li>
<div id="markdown-code-block-editor-vs.editor.ICodeEditor:86" class="markdown-code-outer-container markdown-block-code">
<div>
<div data-keybinding-context="110" data-mode-id="shellscript">
<div class="monaco-editor no-user-selectshowUnused showDeprecated vs-dark" role="code" data-uri="aichat-code-block-anysphere://nfklxzaskx">
<div class="overflow-guard" data-mprt="3">
<div class="monaco-scrollable-element editor-scrollable vs-dark" role="presentation" data-mprt="6">
<div class="lines-content monaco-editor-background">
<div class="view-rulers" role="presentation" aria-hidden="true">然后分区fdisk,格式化 optional 注意格式化时要空出刚才的512字节的section区域。</div>
<div class="view-lines monaco-mouse-cursor-text" role="presentation" aria-hidden="true" data-mprt="8">
<div class="view-line"><span class="mtk1">&nbsp;&nbsp;&nbsp;</span><span class="mtk9">sudo</span><span class="mtk1">&nbsp;</span><span class="mtk12">mkfs.vfat</span><span class="mtk1">&nbsp;</span><span class="mtk12">/dev/sdX1</span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
</section>
<section id="markdown-section-c1bc3c84-a864-4e94-b49a-4584ff2c9cbc-27" class="markdown-section" data-markdown-raw="
   - If your bootloader needs additional files, mount the USB drive and copy them over.

   ```bash
   sudo mount /dev/sdX1 /mnt
   sudo cp additional_files /mnt
   sudo umount /mnt
   ```
" data-section-index="27">
<ul>
<li>
<div id="markdown-code-block-editor-vs.editor.ICodeEditor:87" class="markdown-code-outer-container markdown-block-code">
<div data-keybinding-context="111" data-mode-id="shellscript">
<div class="monaco-editor no-user-selectshowUnused showDeprecated vs-dark" role="code" data-uri="aichat-code-block-anysphere://gwhmoleaaj">
<div class="overflow-guard" data-mprt="3">
<div class="monaco-scrollable-element editor-scrollable vs-dark" role="presentation" data-mprt="6">
<div class="lines-content monaco-editor-background">
<div class="view-zones" role="presentation" aria-hidden="true">copy file</div>
<div class="view-lines monaco-mouse-cursor-text" role="presentation" aria-hidden="true" data-mprt="8">
<div class="view-line"><span class="mtk1">&nbsp;&nbsp;&nbsp;</span><span class="mtk9">sudo</span><span class="mtk1">&nbsp;</span><span class="mtk12">mount</span><span class="mtk1">&nbsp;</span><span class="mtk12">/dev/sdX1</span><span class="mtk1">&nbsp;</span><span class="mtk12">/mnt</span></div>
<div class="view-line"><span class="mtk1">&nbsp;&nbsp;&nbsp;</span><span class="mtk9">sudo</span><span class="mtk1">&nbsp;</span><span class="mtk12">cp</span><span class="mtk1">&nbsp;</span><span class="mtk12">additional_files</span><span class="mtk1">&nbsp;</span><span class="mtk12">/mnt</span></div>
<div class="view-line"><span class="mtk1">&nbsp;&nbsp;&nbsp;</span><span class="mtk9">sudo</span><span class="mtk1">&nbsp;</span><span class="mtk12">umount</span><span class="mtk1">&nbsp;</span><span class="mtk12">/mnt</span></div>
</div>
<div class="contentWidgets" data-mprt="1">&nbsp;</div>
<div class="cursors-layer cursor-line-style cursor-solid" role="presentation" aria-hidden="true">&nbsp;</div>
</div>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
</section>
</section>
</section>
</div><br><br>
来源:https://www.cnblogs.com/bigben0123/p/16255390.html
頁: [1]
查看完整版本: 汇编语言