0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MBRでQEMUの起動

Posted at

【超入門】自作MBRでQEMUを動かしてみる(macOS編)

はじめに

QEMUと16進数1行コマンドだけで、自作ブートセクタ(MBR)を作ってPCを起動するミニ実験です。

「BIOSが自作バイナリを読んで、CPUがあなたの命令で動き出す」

——それを512バイトで実現します。


✅ 前提

  • OS:macOS(Intel / Apple Silicon どちらもOK)
  • QEMUがインストール済み(していない場合は↓)
brew install qemu

作業ディレクトリの準備

好きなディレクトリに作業ディレクトリを作成

mkdir ~/mbr-test
cd ~/mbr-test

自作MBR(ブートセクタ)バイナリを作る

# 1. 512バイトの空ファイル(全0)を作成
dd if=/dev/zero bs=512 count=1 of=img.bin status=none

# 2. 先頭に無限ループ命令 EB FE を書き込む
printf '\xeb\xfe' | dd of=img.bin bs=1 seek=0 conv=notrunc status=none

# 3. 最後の2バイトに「起動可能ディスク」サイン 55 AA を書き込む
printf '\x55\xaa' | dd of=img.bin bs=1 seek=510 conv=notrunc status=none

確認(念のため)

ls -lh img.bin
# → 512B になっていればOK!

xxd img.bin | tail
# → 最後が 55aa で終わっていればOK

QEMUで起動

qemu-system-x86_64 -drive file=img.bin,format=raw

成功の目印

  • 「Boot failed」などのエラーメッセージは出ない
  • 黒い画面に点滅カーソルだけが表示される

🧠 補足:このimg.binの中身は?

範囲 内容
0x0000 EB FE = jmp $(無限ループ)
0x0002〜 00 パディング(509バイト)
0x01FE〜 55 AA(MBRの合言葉)

この最小構成だけで「ブート可能なHDDイメージ」としてBIOSに認識され、QEMUで実行されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?