Bo2SS

Bo2SS

1. Taste the freshness: From one Hello to another Hello

Environment: Ubuntu 18.04 Virtual Machine on Windows

Practice#

🎯 Goal: Make your system output "Hello OS"

Download Source Code#

  1. You can execute the following command in the terminal at any location in the system to download the source code to the virtual machine
git clone https://gitee.com/lmos/cosmos.git

Generate bin File#

  1. In the specific location of the repository: /lesson02/HelloOS, compile the source code to generate HelloOS.bin
  • First, you need to install the tools gcc, make, nasm; by default, only nasm is installed, install the other tools if they are missing
sudo apt update
sudo apt install nasm
  • Then, execute the compilation, which will generate HelloOS.bin according to the rules in the Makefile by default
make

Move bin File#

  1. Move HelloOS.bin to the /boot/ directory
mv HelloOS.bin /boot/

Modify grub Boot Configuration⭐#

  1. Modify the /boot/grub/grub.cfg file
  • Open it with vim using sudo privileges
sudo vim /boot/grub/grub.cfg
  • Insert the following code at the end, paying attention to modify two places: set root, multiboot2
menuentry 'HelloOS' {
     insmod part_msdos            # GRUB loads partition module to recognize partitions
     insmod ext2                  # GRUB loads ext filesystem module to recognize ext filesystem
     set root='hd0,msdos4'        # Note the partition where the boot directory is mounted
     multiboot2 /boot/HelloOS.bin # GRUB loads HelloOS.bin using multiboot2 protocol
     boot                         # GRUB boots HelloOS.bin
}
  • Refer to this step for modifications, then open another terminal and observe the result of df /boot/, focusing on two places: filesystem, mount point
image-20210515092657939
  • Filesystem⭐
    • If it is /dev/sda1, then modify set root='hd0,msdos1'
    • If it is not sda [other system environments], further modifications may be needed [refer to course comments]
  • Mount Point⭐
    • If it is /boot, modify multiboot2 /HelloOS.bin
    • If it is /, no modification is needed

PS: Use :w! to save, and :q to exit editing

image-20210515092718504

Restart the Machine#

  1. Restart the machine, and press the shift key repeatedly [it could also be another key, like the esc key] before the system loads to enter the grub boot interface
image-20210515092730798
  • Select your system and press the enter key
image-20210515092740876
  • If there is an error here, it mainly involves factors such as system type (physical machine, other virtual machine systems), system partition type (UEFI), partition table type (GPT), etc. You can refer to the following reference content👇

Reference Content#

If running in other environments, refer to the comments in the course and related blogs

Scan to join:

image-20210523213829681

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.