Environment: Ubuntu 18.04 Virtual Machine on Windows
Practice#
🎯 Goal: Make your system output "Hello OS"
Download Source Code#
- 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#
- 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#
- Move HelloOS.bin to the /boot/ directory
mv HelloOS.bin /boot/
Modify grub Boot Configuration⭐#
- 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

- 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

Restart the Machine#
- 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

- Select your system and press the enter key

- 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
- Operating System Practice 45 Lectures 01: Running HelloOS——CSDN
- pedro/pos——Gitee
- Can be implemented in non-desktop environments (like WSL2)
- Summary of Core Issues in Peng Dong's "Operating System Practice" Group——Shimo
- ❗ You can basically find answers here!
- 02 | A Few Lines of Assembly and C: Implementing the Simplest Kernel——Geek Time
Course Link#
Scan to join: