### Install Dependencies Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Command to install QEMU system emulator for x86 architecture. ```sh $ sudo apt update && sudo apt install qemu-system-x86 ``` -------------------------------- ### Custom Kernel Stack Size Configuration Source: https://github.com/rust-osdev/bootloader/blob/main/README.md Configure the kernel stack size when using the entry_point macro. This example sets a custom stack size of 100 KiB. ```rust const CONFIG: bootloader_api::BootloaderConfig = { let mut config = bootloader_api::BootloaderConfig::new_default(); config.kernel_stack_size = 100 * 1024; // 100 KiB config }; bootloader_api::entry_point!(kernel_main, config = &CONFIG); ``` -------------------------------- ### Artifact Dependency Setup Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Adds the kernel crate as a build-dependency using artifact dependencies in Cargo.toml. Requires enabling the unstable artifact-dependencies feature. ```toml # in Cargo.toml [build-dependencies] kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" } ``` ```toml # .cargo/config.toml [unstable] bindeps = true ``` -------------------------------- ### Retrieve kernel executable path in build.rs Source: https://github.com/rust-osdev/bootloader/blob/main/README.md In your build script, use environment variables to get the path to the compiled kernel executable when using artifact dependencies. ```rust std::env::var_os("CARGO_BIN_FILE_MY_KERNEL_my-kernel") ``` -------------------------------- ### Test Bootable ISO with QEMU Source: https://github.com/rust-osdev/bootloader/blob/main/docs/chainloading.md Test your generated bootable ISO image using QEMU. This command boots the ISO as a hard disk image and loads your OS binary from a second virtual disk. ```bash qemu-system-x86_64 -hda grub.iso -hdb target/x86_64-my_os/debug/bootimage-my_os.bin ``` -------------------------------- ### Run Bootloader in QEMU Source: https://github.com/rust-osdev/bootloader/blob/main/bios/boot_sector/README.md Launches the bootloader using QEMU, specifying a raw disk image. This command is used for testing and debugging the boot process. ```bash qemu-system-x86_64 -drive format=raw,file=../../target/disk_image.img ``` -------------------------------- ### Create Bootable ISO with GRUB Source: https://github.com/rust-osdev/bootloader/blob/main/docs/chainloading.md Use grub-mkrescue to create a bootable ISO image from your OS's ISO directory. Ensure the 'iso' directory contains your GRUB configuration and OS binary. ```bash grub-mkrescue -o grub.iso iso ``` -------------------------------- ### Initialize a new Cargo binary project Source: https://github.com/rust-osdev/bootloader/blob/main/README.md Use this command to create a new binary crate for your OS project. ```sh cargo init --bin ``` -------------------------------- ### Build Project Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Command to build the project using Cargo. ```sh $ cargo build ``` -------------------------------- ### Build UEFI Bootloader Source: https://github.com/rust-osdev/bootloader/blob/main/uefi/README.md Command to build the UEFI bootloader for x86_64. It specifies the target, release profile, and enables unstable features for building standard library components. ```bash cargo b --target x86_64-unknown-uefi --release -Zbuild-std=core -Zbuild-std-features=compiler-builtins-mem ``` -------------------------------- ### Run Project (UEFI) Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Command to run the built project in UEFI mode using Cargo. ```sh $ cargo run uefi ``` -------------------------------- ### Run Project (BIOS) Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Command to run the built project in BIOS mode using Cargo. ```sh $ cargo run bios ``` -------------------------------- ### Build Bootsector Source: https://github.com/rust-osdev/bootloader/blob/main/bios/boot_sector/README.md Builds the first-stage bootsector using Cargo with specific targets and standard library configurations. This command is essential for creating the bootable executable. ```bash cargo build --profile=stage-1 -Zbuild-std=core --target ../../i386-code16-boot-sector.json -Zbuild-std-features=compiler-builtins-mem ``` -------------------------------- ### Build Script for Bootable Image Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Indicates the use of a cargo build script to create a bootable disk image. ```rust # build.rs // (content not provided in source, only referenced) ``` -------------------------------- ### Specify nightly toolchain and targets Source: https://github.com/rust-osdev/bootloader/blob/main/README.md Ensure you are using the nightly Rust toolchain and specify the necessary build targets for your OS development. ```toml # rust-toolchain.toml [toolchain] channel = "nightly" targets = ["x86_64-unknown-none", "x86_64-unknown-uefi"] ``` -------------------------------- ### Convert ELF to Raw Binary Source: https://github.com/rust-osdev/bootloader/blob/main/bios/boot_sector/README.md Converts the built ELF executable into a raw binary format suitable for a disk image. This step is crucial for creating a bootable sector. ```bash objcopy -I elf32-i386 -O binary ../../target/i386-code16-boot-sector/stage-1/bootloader-x86_64-bios-boot-sector ../../target/disk_image.img ``` -------------------------------- ### Add kernel as a workspace member Source: https://github.com/rust-osdev/bootloader/blob/main/README.md Create a new binary crate for your kernel within the project and add it to the workspace. ```sh cargo new kernel --bin ``` -------------------------------- ### GRUB Configuration for Chainloading Source: https://github.com/rust-osdev/bootloader/blob/main/docs/chainloading.md Configure GRUB2 to chainload your OS by specifying the boot binary location. This entry assumes your OS binary is on the first partition of the second hard disk (hd1). ```grub menuentry "myOS" { chainloader (hd1)+1 } ``` -------------------------------- ### Toolchain Configuration Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Specifies the nightly channel and necessary components/targets for the Rust toolchain in rust-toolchain.toml. ```toml # rust-toolchain.toml [toolchain] channel = "nightly" components = ["llvm-tools"] targets = ["x86_64-unknown-none", "x86_64-unknown-uefi"] ``` -------------------------------- ### Workspace Configuration Source: https://github.com/rust-osdev/bootloader/blob/main/examples/basic/basic-os.md Defines the kernel crate as a member of the workspace in Cargo.toml. ```toml # in Cargo.toml [workspace] members = ["kernel"] ``` -------------------------------- ### Define a Cargo workspace Source: https://github.com/rust-osdev/bootloader/blob/main/README.md Configure your Cargo.toml to manage multiple crates within a single project. Add your kernel crate to the members list. ```toml # in Cargo.toml [workspace] resolver = "3" members = [] ``` -------------------------------- ### Inspect ELF File Contents Source: https://github.com/rust-osdev/bootloader/blob/main/bios/boot_sector/README.md Dumps the contents of the ELF file in a detailed format, useful for analyzing the binary and identifying areas for size reduction. The `-M i8086,intel` option specifies the processor mode for disassembly. ```bash objdump -xsdS -M i8086,intel ../../target/i386-code16-boot-sector/stage-1/bootloader-x86_64-bios-boot-sector ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.