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?

More than 3 years have passed since last update.

VMWare (vmdk)を使ってMikanOSのUEFIブートをする方法

Posted at

「ゼロからのOS自作入門」の第1章にあるhello.efiをqemuではなくVMWareのディスクで起動する方法です。もっと簡単な方法ある気がしますが。

全体のステップ

  1. ループバックデバイス準備
  2. GPTでパーティションの作成
  3. パーティションのフォーマット
  4. efiファイルのコピー
  5. ループバックデバイスをvmdkに変換
  6. VMWareにディスクを追加して起動

vmdkファイルの作成はLinux(VM)上で行い、それをMac上の別のテスト用VMに追加して起動するというシナリオです。
Linux上のコマンドがない場合は頑張って探してインストールして下さい。

ループバックデバイス準備

100MBのファイルを用意して、ループバックデバイスの作成

$ dd if=/dev/zero of=disk.img bs=100M count=1      # 100MBのファイル作成
$ sudo losetup -fP disk.img                        # ループバックデバイスの作成
$ sudo losetup -a                                  # デバイス名表示
/dev/loop0: [2051]:657184 (/develop/MikanOS/disk.img)

GPTでパーティションの作成

EFIはGPTしか対応しないっぽいのでMBRではなくGPTでパーティションを作成。fdisk利用。

$ sudo fdisk /dev/loop0

Welcome to fdisk (util-linux 2.37).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x00cf080e.

Command (m for help): g      <------GPTパーティションテーブルの作成
Created a new GPT disklabel (GUID: 7CD727F0-6839-4648-AEF1-81227F22DAAE).

Command (m for help): n          <------ディスク全体を使ってパーティション作成
Partition number (1-128, default 1):
First sector (2048-204766, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-204766, default 204766):

Created a new partition 1 of type 'Linux filesystem' and of size 99 MiB.

Command (m for help): t      <------パーティションタイプを"EFI System"に変更
Selected partition 1
Partition type or alias (type L to list all): 1
Changed type of partition 'Linux filesystem' to 'EFI System'

Command (m for help): w          <------変更を書き込んで終了
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

パーティションタイプはvfat32がいいのかと思ったけど、タイプのリストに見つけられなかった。GPTでは指定できない?EFI Systemも基本同じっぽいのでとりあえずそれを指定。

パーティションのフォーマット

今作ったパーティションをvfat32でフォーマット

sudo mkfs.vfat -F 32 /dev/loop0p1

efiファイルのコピー

フォーマットしたパーティションを適当なディレクトリにマウントしてhello.efiをコピー。「ゼロからのOS自作入門」第1章 エミュレータでのやり方、の部分とほぼ同じです。

$ sudo mount -t vfat /dev/loop0p1 /mnt
$ sudo mkdir -p /mnt/EFI/BOOT
$ sudo cp hello.efi /mnt/EFI/BOOT/BOOTX64.EFI
$ sudo umount /mnt

/mnthello.efiは適当に読み替えてください。

ループバックデバイスをvmdkに変換

$ sudo losetup -d /dev/loop0                    # ループバックデバイスを削除して
$ qemu-img convert -O vmdk disk.img disk.vmdk   # vmdkに変換

VMWareにディスクを追加して起動

出来上がったdisk.vmdkをMacにコピー。そのファイルを使って新規でVM作成

Other 64-bitを選択して

image.png

Firmware TypeでUEFIを選択

image.png

先程コピーしてきたvmdkファイルを指定して

image.png

VMを作成後、起動して"Hello, world!"がでれば成功

image.png

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?