10 min read
ゼロからのOS自作入門 Day1

Ubuntu 22.04

mz@os:~$ git clone https://github.com/uchan-nos/mikanos-build.git osbook
Cloning into 'osbook'...
remote: Enumerating objects: 184, done.
remote: Counting objects: 100% (90/90), done.
remote: Compressing objects: 100% (41/41), done.
remote: Total 184 (delta 61), reused 49 (delta 49), pack-reused 94 (from 1)
Receiving objects: 100% (184/184), 1.11 MiB | 1.33 MiB/s, done.
Resolving deltas: 100% (99/99), done.
mz@os:~$ sudo apt install ansible
[sudo] password for mz: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  ieee-data python3-argcomplete python3-dnspython python3-jmespath
  python3-kerberos python3-libcloud python3-netaddr python3-ntlm-auth
  python3-pycryptodome python3-requests-kerberos python3-requests-ntlm
  python3-requests-toolbelt python3-selinux python3-simplejson python3-winrm
  python3-xmltodict
Suggested packages:
  cowsay sshpass python3-sniffio python3-trio ipython3 python-netaddr-docs
The following NEW packages will be installed:
  ansible ieee-data python3-argcomplete python3-dnspython python3-jmespath
  python3-kerberos python3-libcloud python3-netaddr python3-ntlm-auth
  python3-pycryptodome python3-requests-kerberos python3-requests-ntlm
  python3-requests-toolbelt python3-selinux python3-simplejson python3-winrm
  python3-xmltodict
0 upgraded, 17 newly installed, 0 to remove and 0 not upgraded.
Need to get 22.8 MB of archives.
After this operation, 243 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main arm64 python3-pycryptodome arm64 3.11.0+dfsg1-3ubuntu0.1 [1,034 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 python3-dnspython all 2.1.0-1ubuntu1 [123 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 ieee-data all 20210605.1 [1,887 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 python3-netaddr all 0.8.0-2 [309 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 ansible all 2.10.7+merged+base+2.10.8+dfsg-1 [17.5 MB]
Get:6 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-argcomplete all 1.8.1-1.5 [27.2 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 python3-jmespath all 0.10.0-1 [21.7 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-kerberos arm64 1.1.14-3.1build5 [22.6 kB]
Get:9 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 python3-simplejson arm64 3.17.6-1build1 [54.2 kB]
Get:10 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-libcloud all 3.2.0-2 [1,554 kB]
Get:11 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-ntlm-auth all 1.4.0-1 [20.4 kB]
Get:12 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-requests-kerberos all 0.12.0-2 [11.9 kB]
Get:13 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-requests-ntlm all 1.1.0-1.1 [6,160 B]
Get:14 http://ports.ubuntu.com/ubuntu-ports jammy/main arm64 python3-requests-toolbelt all 0.9.1-1 [38.0 kB]
Get:15 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-selinux arm64 3.3-1build2 [154 kB]
Get:16 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-xmltodict all 0.12.0-2 [12.6 kB]
Get:17 http://ports.ubuntu.com/ubuntu-ports jammy/universe arm64 python3-winrm all 0.3.0-2 [21.7 kB]
Fetched 22.8 MB in 7s (3,135 kB/s)                                             
Selecting previously unselected package python3-pycryptodome.
(Reading database ... 168717 files and directories currently installed.)
Preparing to unpack .../00-python3-pycryptodome_3.11.0+dfsg1-3ubuntu0.1_arm64.de
b ...
Unpacking python3-pycryptodome (3.11.0+dfsg1-3ubuntu0.1) ...
Selecting previously unselected package python3-dnspython.
Preparing to unpack .../01-python3-dnspython_2.1.0-1ubuntu1_all.deb ...
Unpacking python3-dnspython (2.1.0-1ubuntu1) ...
Selecting previously unselected package ieee-data.
Preparing to unpack .../02-ieee-data_20210605.1_all.deb ...
Unpacking ieee-data (20210605.1) ...
Selecting previously unselected package python3-netaddr.
Preparing to unpack .../03-python3-netaddr_0.8.0-2_all.deb ...
Unpacking python3-netaddr (0.8.0-2) ...
Selecting previously unselected package ansible.
Preparing to unpack .../04-ansible_2.10.7+merged+base+2.10.8+dfsg-1_all.deb ...
Unpacking ansible (2.10.7+merged+base+2.10.8+dfsg-1) ...
Selecting previously unselected package python3-argcomplete.
Preparing to unpack .../05-python3-argcomplete_1.8.1-1.5_all.deb ...
Unpacking python3-argcomplete (1.8.1-1.5) ...
Selecting previously unselected package python3-jmespath.
Preparing to unpack .../06-python3-jmespath_0.10.0-1_all.deb ...
Unpacking python3-jmespath (0.10.0-1) ...
Selecting previously unselected package python3-kerberos.
Preparing to unpack .../07-python3-kerberos_1.1.14-3.1build5_arm64.deb ...
Unpacking python3-kerberos (1.1.14-3.1build5) ...
Selecting previously unselected package python3-simplejson.
Preparing to unpack .../08-python3-simplejson_3.17.6-1build1_arm64.deb ...
Unpacking python3-simplejson (3.17.6-1build1) ...
Selecting previously unselected package python3-libcloud.
Preparing to unpack .../09-python3-libcloud_3.2.0-2_all.deb ...
Unpacking python3-libcloud (3.2.0-2) ...
Selecting previously unselected package python3-ntlm-auth.
Preparing to unpack .../10-python3-ntlm-auth_1.4.0-1_all.deb ...
Unpacking python3-ntlm-auth (1.4.0-1) ...
Selecting previously unselected package python3-requests-kerberos.
Preparing to unpack .../11-python3-requests-kerberos_0.12.0-2_all.deb ...
Unpacking python3-requests-kerberos (0.12.0-2) ...
Selecting previously unselected package python3-requests-ntlm.
Preparing to unpack .../12-python3-requests-ntlm_1.1.0-1.1_all.deb ...
Unpacking python3-requests-ntlm (1.1.0-1.1) ...
Selecting previously unselected package python3-requests-toolbelt.
Preparing to unpack .../13-python3-requests-toolbelt_0.9.1-1_all.deb ...
Unpacking python3-requests-toolbelt (0.9.1-1) ...
Selecting previously unselected package python3-selinux.
Preparing to unpack .../14-python3-selinux_3.3-1build2_arm64.deb ...
Unpacking python3-selinux (3.3-1build2) ...
Selecting previously unselected package python3-xmltodict.
Preparing to unpack .../15-python3-xmltodict_0.12.0-2_all.deb ...
Unpacking python3-xmltodict (0.12.0-2) ...
Selecting previously unselected package python3-winrm.
Preparing to unpack .../16-python3-winrm_0.3.0-2_all.deb ...
Unpacking python3-winrm (0.3.0-2) ...
Setting up python3-requests-toolbelt (0.9.1-1) ...
Setting up python3-ntlm-auth (1.4.0-1) ...
Setting up python3-pycryptodome (3.11.0+dfsg1-3ubuntu0.1) ...
Setting up python3-kerberos (1.1.14-3.1build5) ...
Setting up python3-simplejson (3.17.6-1build1) ...
Setting up python3-xmltodict (0.12.0-2) ...
Setting up python3-jmespath (0.10.0-1) ...
Setting up python3-requests-kerberos (0.12.0-2) ...
Setting up ieee-data (20210605.1) ...
Setting up python3-dnspython (2.1.0-1ubuntu1) ...
Setting up python3-selinux (3.3-1build2) ...
Setting up python3-argcomplete (1.8.1-1.5) ...
Setting up python3-requests-ntlm (1.1.0-1.1) ...
Setting up python3-libcloud (3.2.0-2) ...
Setting up python3-netaddr (0.8.0-2) ...
Setting up python3-winrm (0.3.0-2) ...
Setting up ansible (2.10.7+merged+base+2.10.8+dfsg-1) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...                                                           
Scanning linux images...                                                        

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
mz@os:~$ 
mz@os:~$ cd osbook/
day01/      devenv/     devenv_src/ .git/       
mz@os:~$ cd osbook/devenv
mz@os:~/osbook/devenv$ ansible-playbook -K -i ansible_inventory ansible_provision.yml
BECOME password: 

PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [ensure development tools are at the latest version] **********************
changed: [localhost]

TASK [check whether qemu-system-gui exists] ************************************
ok: [localhost]

TASK [install qemu gui package if exists] **************************************
changed: [localhost]

TASK [set llvm 14 as default] **************************************************
changed: [localhost] => (item=llvm-PerfectShuffle)
changed: [localhost] => (item=llvm-ar)
changed: [localhost] => (item=llvm-as)
changed: [localhost] => (item=llvm-bcanalyzer)
changed: [localhost] => (item=llvm-cat)
changed: [localhost] => (item=llvm-cfi-verify)
changed: [localhost] => (item=llvm-config)
changed: [localhost] => (item=llvm-cov)
changed: [localhost] => (item=llvm-c-test)
changed: [localhost] => (item=llvm-cvtres)
changed: [localhost] => (item=llvm-cxxdump)
changed: [localhost] => (item=llvm-cxxfilt)
changed: [localhost] => (item=llvm-diff)
changed: [localhost] => (item=llvm-dis)
changed: [localhost] => (item=llvm-dlltool)
changed: [localhost] => (item=llvm-dwarfdump)
changed: [localhost] => (item=llvm-dwp)
changed: [localhost] => (item=llvm-exegesis)
changed: [localhost] => (item=llvm-extract)
changed: [localhost] => (item=llvm-lib)
changed: [localhost] => (item=llvm-link)
changed: [localhost] => (item=llvm-lto)
changed: [localhost] => (item=llvm-lto2)
changed: [localhost] => (item=llvm-mc)
changed: [localhost] => (item=llvm-mca)
changed: [localhost] => (item=llvm-modextract)
changed: [localhost] => (item=llvm-mt)
changed: [localhost] => (item=llvm-nm)
changed: [localhost] => (item=llvm-objcopy)
changed: [localhost] => (item=llvm-objdump)
changed: [localhost] => (item=llvm-opt-report)
changed: [localhost] => (item=llvm-pdbutil)
changed: [localhost] => (item=llvm-profdata)
changed: [localhost] => (item=llvm-ranlib)
changed: [localhost] => (item=llvm-rc)
changed: [localhost] => (item=llvm-readelf)
changed: [localhost] => (item=llvm-readobj)
changed: [localhost] => (item=llvm-rtdyld)
changed: [localhost] => (item=llvm-size)
changed: [localhost] => (item=llvm-split)
changed: [localhost] => (item=llvm-stress)
changed: [localhost] => (item=llvm-strings)
changed: [localhost] => (item=llvm-strip)
changed: [localhost] => (item=llvm-symbolizer)
changed: [localhost] => (item=llvm-tblgen)
changed: [localhost] => (item=llvm-undname)
changed: [localhost] => (item=llvm-xray)
changed: [localhost] => (item=ld.lld)
changed: [localhost] => (item=lld-link)
changed: [localhost] => (item=clang)
changed: [localhost] => (item=clang++)
changed: [localhost] => (item=clang-cpp)

TASK [clone EDK II repository] *************************************************
changed: [localhost]

TASK [build EDK II base tools] *************************************************
changed: [localhost]

TASK [download standard libraries] *********************************************
changed: [localhost]

TASK [configure display variable if WSL1] **************************************
skipping: [localhost]

TASK [configure display variable if WSL2] **************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=8    changed=6    unreachable=0    failed=0    skipped=2    rescued=0    ignored=0   

mz@os:~/osbook/devenv$ iasl -v

Intel ACPI Component Architecture
ASL+ Optimizing Compiler/Disassembler version 20200925
Copyright (c) 2000 - 2020 Intel Corporation

mz@os:~/osbook/devenv$ cd
mz@os:~$ 
mz@os:~$ ls edk2/
ArmPkg            FatPkg               pip-requirements.txt
ArmPlatformPkg    FmpDevicePkg         PrmPkg
ArmVirtPkg        IntelFsp2Pkg         ReadMe.rst
BaseTools         IntelFsp2WrapperPkg  RedfishPkg
Conf              License-History.txt  SecurityPkg
CONTRIBUTING.md   License.txt          ShellPkg
CryptoPkg         Maintainers.txt      SignedCapsulePkg
DynamicTablesPkg  MdeModulePkg         SourceLevelDebugPkg
edksetup.bat      MdePkg               StandaloneMmPkg
edksetup.sh       NetworkPkg           UefiCpuPkg
EmbeddedPkg       OvmfPkg              UefiPayloadPkg
EmulatorPkg       PcAtChipsetPkg       UnitTestFrameworkPkg
mz@os:~$ qu
quirks-handler  quote           quote_readline  
mz@os:~$ qu
quirks-handler  quote           quote_readline  
mz@os:~$ ls
20241217.log  Documents  edk2   osbook    Public  Templates
Desktop       Downloads  Music  Pictures  snap    Videos
mz@os:~$ 
mz@os:~$ 
mz@os:~$ qemu-i
qemu-img  qemu-io   
mz@os:~$ qemu-img crete -f raw disk.img 200M
qemu-img: Command not found: crete
Try 'qemu-img --help' for more information
mz@os:~$ qemu-img create -f raw disk.img 200M
Formatting 'disk.img', fmt=raw size=209715200
mz@os:~$ ls
20241217.log  disk.img   Downloads  Music   Pictures  snap       Videos
Desktop       Documents  edk2       osbook  Public    Templates
mz@os:~$ mkfs.fat -n 'MIKAN OS' -s 2 -f 2 -R 32 -F 32 disk.img 
mkfs.fat 4.2 (2021-01-31)
mz@os:~$ mkdir -p mnt
mz@os:~$ sudo mount -o loop disk.img mnt
[sudo] password for mz: 
mz@os:~$ sudo cp 
20241217.log               .local/
.ansible/                  mnt/
.bash_history              Music/
.bash_logout               osbook/
.bashrc                    .parallels/
.cache/                    Pictures/
.config/                   .profile
Desktop/                   Public/
disk.img                   snap/
Documents/                 .ssh/
Downloads/                 .sudo_as_admin_successful
edk2/                      Templates/
.gnupg/                    Videos/
mz@os:~$ ls
20241217.log  disk.img   Downloads  mnt    osbook    Public  Templates
Desktop       Documents  edk2       Music  Pictures  snap    Videos
mz@os:~$ sudo cp osbook/
day01/      devenv/     devenv_src/ .git/       LICENSE     README.md
mz@os:~$ sudo cp osbook/day01/
asm/ bin/ c/   
mz@os:~$ sudo cp osbook/day01/
asm/ bin/ c/   
mz@os:~$ sudo cp osbook/day01/asm/
.gitignore  hello.asm   Makefile    
mz@os:~$ sudo cp osbook/day01/asm/
.gitignore  hello.asm   Makefile    
mz@os:~$ sudo cp osbook/day01/c/
.gitignore  hello.c     Makefile    
mz@os:~$ sudo cp osbook/day01/c/
.gitignore  hello.c     Makefile    
mz@os:~$ sudo cp osbook/day01/bin/hello.efi 
20241217.log               .local/
.ansible/                  mnt/
.bash_history              Music/
.bash_logout               osbook/
.bashrc                    .parallels/
.cache/                    Pictures/
.config/                   .profile
Desktop/                   Public/
disk.img                   snap/
Documents/                 .ssh/
Downloads/                 .sudo_as_admin_successful
edk2/                      Templates/
.gnupg/                    Videos/
mz@os:~$ sudo mkdir -p mnt/EFI/BOOT
mz@os:~$ 
mz@os:~$ 
mz@os:~$ sudo cp osbook/
day01/      devenv/     devenv_src/ .git/       LICENSE     README.md
mz@os:~$ sudo cp osbook/day01/
asm/ bin/ c/   
mz@os:~$ sudo cp osbook/day01/bin/hello.efi mnt/EFI/BOOT/BOOTX64.EFI
mz@os:~$ 
mz@os:~$ sudo unmount mnt
sudo: unmount: command not found
mz@os:~$ sudo umount mnt
mz@os:~$ 
mz@os:~$ qemu-
qemu-img               qemu-nbd               qemu-system-i386
qemu-io                qemu-pr-helper         qemu-system-x86_64
qemu-make-debian-root  qemu-storage-daemon    
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=\$HOME/osbook/devenv/OVMF_CODE.fd -drive if=pflash,file=$HO
$HOME      $HOSTNAME  $HOSTTYPE  
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=\$HOME/osbook/devenv/OVMF_CODE.fd -drive if=pflash,file=$HO
$HOME      $HOSTNAME  $HOSTTYPE  
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=\$HOME/osbook/devenv/OVMF_CODE.fd -drive if=pflash,file=\$HOME/osbook/devenv/OVMF_VARS.fd / -hda disk.img 
qemu-system-x86_64: -drive if=pflash,file=$HOME/osbook/devenv/OVMF_CODE.fd: Could not open '$HOME/osbook/devenv/OVMF_CODE.fd': No such file or directory
mz@os:~$ ls osbook/
day01/      devenv/     devenv_src/ .git/       LICENSE     README.md
mz@os:~$ ls osbook/devenv
devenv/     devenv_src/ 
mz@os:~$ ls osbook/devenv
devenv/     devenv_src/ 
mz@os:~$ ls osbook/devenv/
ansible_inventory      make_mikanos_image.sh  run_qemu.sh
ansible_provision.yml  mount_image.sh         vagrant-build-edk2.sh
build-edk2.sh          OVMF_CODE.fd           Vagrantfile
buildenv.sh            OVMF_VARS.fd           x86_64-elf/
.gitignore             run_image.sh           
make_image.sh          run_mikanos.sh         
mz@os:~$ ls osbook/devenv/
ansible_inventory      make_mikanos_image.sh  run_qemu.sh
ansible_provision.yml  mount_image.sh         vagrant-build-edk2.sh
build-edk2.sh          OVMF_CODE.fd           Vagrantfile
buildenv.sh            OVMF_VARS.fd           x86_64-elf/
.gitignore             run_image.sh           
make_image.sh          run_mikanos.sh         
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=\$HOME/osbook/devenv/devenv/OVMF_CODE.fd -drive if=pflash,file=\$HOME/osbook/devenv/devenv/OVMF_VARS.fd / -hda disk.img 
qemu-system-x86_64: -drive if=pflash,file=$HOME/osbook/devenv/devenv/OVMF_CODE.fd: Could not open '$HOME/osbook/devenv/devenv/OVMF_CODE.fd': No such file or directory
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=~/ -drive if=pflash,file=\$HOME/osbook/devenv/devenv/OVMF_VARS.fd / -hda disk.img 
20241217.log               .local/
.ansible/                  mnt/
.bash_history              Music/
.bash_logout               osbook/
.bashrc                    .parallels/
.cache/                    Pictures/
.config/                   .profile
Desktop/                   Public/
disk.img                   snap/
Documents/                 .ssh/
Downloads/                 .sudo_as_admin_successful
edk2/                      Templates/
.gnupg/                    Videos/
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=~/osbook/ -drive if=pflash,file=\$HOME/osbook/devenv/devenv/OVMF_VARS.fd / -hda disk.img 
day01/      devenv/     devenv_src/ .git/       LICENSE     README.md
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=~/osbook/devenv -drive if=pflash,file=\$HOME/osbook/devenv/devenv/OVMF_VARS.fd / -hda disk.img 
devenv/     devenv_src/ 
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=~/osbook/devenv/ -drive if=pflash,file=\$HOME/osbook/devenv/devenv/OVMF_VARS.fd / -hda disk.img 
ansible_inventory      make_mikanos_image.sh  run_qemu.sh
ansible_provision.yml  mount_image.sh         vagrant-build-edk2.sh
build-edk2.sh          OVMF_CODE.fd           Vagrantfile
buildenv.sh            OVMF_VARS.fd           x86_64-elf/
.gitignore             run_image.sh           
make_image.sh          run_mikanos.sh         
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=~/osbook/devenv/OVMF_CODE.fd -drive if=pflash,file=~/osbook/devenv/ -hda disk.img 
ansible_inventory      make_mikanos_image.sh  run_qemu.sh
ansible_provision.yml  mount_image.sh         vagrant-build-edk2.sh
build-edk2.sh          OVMF_CODE.fd           Vagrantfile
buildenv.sh            OVMF_VARS.fd           x86_64-elf/
.gitignore             run_image.sh           
make_image.sh          run_mikanos.sh         
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=~/osbook/devenv/OVMF_CODE.fd -drive if=pflash,file=~/osbook/devenv/OVMF_VARS.fd -hda disk.img 
qemu-system-x86_64: -drive if=pflash,file=~/osbook/devenv/OVMF_CODE.fd: Could not open '~/osbook/devenv/OVMF_CODE.fd': No such file or directory
mz@os:~$ pwd
/home/mz
mz@os:~$ qemu-system-x86_64 -drive if=pflash,file=/home/mz/osbook/devenv/OVMF_CODE.fd -drive if=pflash,file=/home/mz/osbook/devenv/OVMF_VARS.fd -hda disk.img
WARNING: Image format was not specified for '/home/mz/osbook/devenv/OVMF_CODE.fd' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
WARNING: Image format was not specified for '/home/mz/osbook/devenv/OVMF_VARS.fd' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
WARNING: Image format was not specified for 'disk.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

alt text