LoginSignup
7
2

More than 3 years have passed since last update.

ゼロからのOS自作入門をMacで勉強する方法 (Docker使用)

Last updated at Posted at 2021-03-29

ゼロからのOS自作入門をMacで読み進めたい

本書ではLinux(Ubuntu)を開発環境に選んでおり、
WindowsのWSLを使った方法を紹介しているが、Macでの方法は記載されていなかった。

私の環境

  • macOS Big Sur(ver. 11.2.2)
  • Docker Engine v20.10.2

Docker上で環境を作っていく

Docker上のUbuntuでビルドしたOSをQEMUで起動させることにした。

今回作ったDockerfile

$ cat works/os/Dockerfile
FROM ubuntu:18.04

MAINTAINER meruneru

ENV IMAGE_NAME=MikanOS

RUN apt-get update
RUN apt-get install -y  vim \
                        build-essential \
                        python3 \
                        git \
                        okteta \
                        tmux \
                        dosfstools

# https://github.com/uchan-nos/mikanos-build
RUN cd $HOME; \
    git clone https://github.com/uchan-nos/mikanos-build.git osbook; \
    apt install -y ansible; \
    cd $HOME/osbook/devenv; \
    ansible-playbook -K -i ansible_inventory ansible_provision.yml

CMD ["/bin/bash"]

Dockerfileからイメージを作成する

$ docker build -t os works/os

Docker内のGUIアプリをMacOS側に出力するために・・・

XQuartz(X11サーバ)を別途インストールし、XQuatzの環境設定のセキュリティタブで、
"ネットワーク・クライアントからの接続を許可"にチェックを入れておく。
image.png

Dockerイメージを起動する

以下のコマンドでOSを起動させることができる。
起動後に書籍に載っているコマンドがインストールされていれば、環境構築完了:sunny:

コマンドが長いので、私は下記ファイルをシェルスクリプトにして起動してる。

docker run -it --rm \
           --privileged \
           -e DISPLAY=$(hostname):0 \
           -v ~/.Xauthority:/root/.Xauthority \
           -v $HOME/works/os:/root/os/ \
           os

7
2
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
7
2