A bootloader creation tool that formats USB devices and installs bootloader and kernel binaries to create bootable USB drives.
- 🔍 Automatic USB device detection
- 💾 Interactive device selection with detailed information
- 🛡️ Safety confirmations before destructive operations
- 📝 Clear progress indicators and colored output
- ✅ Installation verification
- 🔧 Support for custom kernel and bootloader binaries
- Linux operating system
- Root/sudo privileges (required for disk operations)
- USB drive (will be formatted - all data will be lost!)
fdisk,mkfs.vfat,lsblk,dd(standard Linux utilities)
makeThis creates example bootloader.bin and kernel.bin files.
sudo ./create_bootable_usb.shOr with custom binary files:
sudo ./create_bootable_usb.sh /path/to/kernel.bin /path/to/bootloader.binThe script will:
- Validate your binary files
- Scan for available USB devices
- Display detected devices with size and model information
- Ask you to select a device
- Request confirmation before formatting
- Create a bootable USB with your bootloader and kernel
sudo ./create_bootable_usb.sh [kernel_binary] [bootloader_binary]Arguments:
kernel_binary- Path to kernel binary file (default:kernel.bin)bootloader_binary- Path to bootloader binary file (default:bootloader.bin)
Example:
# Use default binaries (kernel.bin and bootloader.bin in current directory)
sudo ./create_bootable_usb.sh
# Use custom binaries
sudo ./create_bootable_usb.sh ./my_kernel.bin ./my_bootloader.bin- Validation: Checks that kernel and bootloader binary files exist
- Detection: Scans for removable USB devices using
/sys/blockandlsblk - Selection: Presents available devices with size, model, and vendor information
- Confirmation: Requires explicit "YES" confirmation before proceeding
- Unmounting: Unmounts all partitions on the target device
- Partitioning: Creates a new MBR partition table with a single bootable partition
- Formatting: Formats the partition as FAT32 with label "NAOBOOT"
- Installation:
- Writes bootloader to the MBR (first 446 bytes)
- Copies kernel binary to the USB partition
- Copies bootloader binary to the USB partition for reference
- Verification: Checks that files were written correctly
- Completion: Syncs all data and displays success message
NaoBootloader/
├── create_bootable_usb.sh # Main USB creation script
├── bootloader.asm # Example bootloader assembly source
├── kernel.asm # Example kernel assembly source
├── Makefile # Build script for example binaries
├── bootloader.bin # Compiled bootloader binary (generated)
├── kernel.bin # Compiled kernel binary (generated)
└── README.md # This file
The example files provide a starting point. To create your own:
- Write your bootloader in assembly (or C with appropriate compilation)
- Ensure bootloader fits in 446 bytes for MBR
- Compile to raw binary format
- Create your kernel binary
- Use the script to install them on a USB device
# Compile bootloader
nasm -f bin -o bootloader.bin bootloader.asm
# Compile kernel
nasm -f bin -o kernel.bin kernel.asm
# Create bootable USB
sudo ./create_bootable_usb.sh kernel.bin bootloader.bin- Requires root privileges (prevents accidental execution)
- Shows detailed device information before selection
- Requires typing "YES" (not just "y") to confirm
- Displays current partitions before formatting
- Unmounts device safely before operations
- Verifies installation after completion
- Ensure USB drive is properly inserted
- Check if device appears in
lsblkoutput - Try unplugging and re-inserting the USB drive
- Script must be run with
sudoor as root - Check device permissions with
ls -l /dev/sd*
- Device may not have synced properly
- Try ejecting and re-inserting the USB
- Check USB drive is not defective
- Ensure bootloader binary is valid x86 boot code
- Verify bootloader ends with 0xAA55 signature (for MBR)
- Check that bootloader is less than 446 bytes
make cleanThe script requires actual hardware and root access. For testing changes:
- Review the script logic
- Test with a virtual machine and virtual USB
- Or use a dedicated test USB drive with no important data
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit issues or pull requests.
- Double-check your device selection
- Backup any important data before using this tool
- Verify you're not selecting your system drive
- Test on non-critical devices first
The authors are not responsible for data loss or hardware damage resulting from the use of this tool.