A minimal 64-bit bootable Linux ISO that runs a custom C program as init. Built using a precompiled Linux kernel, GRUB bootloader, and custom initramfs without a full Linux distro. Designed to run standalone in QEMU or VirtualBox.
# 🐧 Custom Linux Bootable ISO
This project demonstrates how to build a **minimal 64-bit bootable Linux ISO** that runs a **custom C program as `init`**. It uses:
- A **precompiled Linux kernel (`bzImage`)**
- A **custom `init` program** written in C
- A minimal **initramfs**
- The **GRUB bootloader**
- Works in **QEMU** and **VirtualBox**
---
## 📁 Project Structure
. ├── init.c # Your main C program (runs as PID 1) ├── init # Statically compiled binary ├── rootfs/ # Root filesystem for initramfs │ ├── dev/ │ ├── proc/ │ ├── sys/ │ └── init ├── initrd.gz # Compressed initramfs ├── iso/ │ └── boot/ │ ├── grub/ │ │ └── grub.cfg │ ├── vmlinuz # Precompiled Linux kernel (bzImage) │ └── initrd.gz └── mylinux.iso # Final bootable ISO
---
## 🛠️ Requirements
- Linux host (Ubuntu recommended)
- `gcc`, `cpio`, `grub-pc-bin`, `xorriso`
- Precompiled Linux kernel (`bzImage`)
- `fakeroot` (for safe initramfs creation)
---
## 🧪 Step-by-Step Instructions
### 1. Write Your Init Program (`init.c`)
```c
#include <unistd.h>
#include <fcntl.h>
int main() {
int fd = open("/dev/console", O_WRONLY);
write(fd, "✅ Hello from custom init!\n", 27);
while (1); // Infinite loop to keep the kernel alive
return 0;
}
gcc -static -o init init.c
chmod +x initmkdir -p rootfs/{dev,proc,sys}
cp init rootfs/init
# Create device nodes
sudo mknod rootfs/dev/console c 5 1
sudo mknod rootfs/dev/null c 1 3
chmod 600 rootfs/dev/console
chmod 666 rootfs/dev/null
# Create initramfs
cd rootfs
find . | cpio -o --format=newc | gzip > ../initrd.gz
cd ..mkdir -p iso/boot/grub
nano iso/boot/grub/grub.cfgPaste this:
set timeout=0
set default=0
menuentry "Boot Custom Linux" {
linux /boot/vmlinuz console=tty0 video=vesafb:mtrr:3,ywrap,1024x768-32
initrd /boot/initrd.gz
}cp initrd.gz iso/boot/initrd.gz
cp bzImage iso/boot/vmlinuzgrub-mkrescue -o S2 HyperCalc.iso isoqemu-system-x86_64 -cdrom S2 HyperCalc.iso -boot d -m 512-
Create a new VM:
- Type: Linux
- Version: Other Linux (64-bit)
- RAM: 512 MB
- No hard disk needed
-
Mount
S2 HyperCalc.isoas optical drive. -
Boot and watch the console for your custom
initoutput.
Edit grub.cfg:
linux /boot/vmlinuz console=tty0 video=vesafb:mtrr:3,ywrap,480 - 80 25Optional for EFI VMs:
VBoxManage modifyvm "YourVMName" --firmware efi
VBoxManage setextradata "YourVMName" "VBoxInternal2/EfiGraphicsResolution" "1920x1080"- Linux kernel: https://kernel.org
- GRUB bootloader
- cpio for archive creation
fakerootfor safe permissions during build